A pocket diagnostic calculator program for computing Bayesian probabilities for nine diseases with sixteen symptoms

A pocket diagnostic calculator program for computing Bayesian probabilities for nine diseases with sixteen symptoms

COMPUTERS AND BIOMEDICALRESEARCH l&177-186 (1978) A Pocket Diagnostic Calculator Program for Computing Bayesian Probabilities for Nine Diseases w...

609KB Sizes 5 Downloads 80 Views

COMPUTERS

AND

BIOMEDICALRESEARCH

l&177-186

(1978)

A Pocket Diagnostic Calculator Program for Computing Bayesian Probabilities for Nine Diseases with Sixteen Symptoms* PART

A

HERBERT SHERMAN Hurvard

School

ofPublic

Health,

677 Huntington

Avenue,

Boston,

Massachusetts

02115

Received September 7. 1977 We have demonstrated the use of a tape-controlled hand calculator for the bedside calculation of Bayesian probabilities for the differential diagnosis of up to 9 ‘diseases and 16 symptoms. We have indicated the maneuvers required to store the requisite data as well as the effects of these maneuvers on the calculated results.

One mode of quantitative diagnosis is the use of Bayesian probabilities (1). Despite the large literature on this subject and the ready availability of programs usable in desktop calculators (2), this form of calculation is still not widely used because of the failure of present computational aids to permit bedside calculations. In this paper we show how a hand-held tape-programmed calculator (e.g., Texas Instruments SR-52 and Hewlett-Packard 67) can be used to compute Bayesian probabilities on a time scale consistent with the normal interview with the patient. We will also describe a sample application to compute Bayesian probabilities for the differentiation of up to nine diseases using up to 16 symptoms. Thus, our aims are fourfold: (1) description of a generalized procedure for such Bayesian computations, (2) discussion of the maneuvers, particularly those of data storage, employed to overcome the calculator limitations, (3) computation of the sensitivity of the calculated result to the approximations used in the program, and (4) presentation, in Part B, of a sample study. * This study was supported by the Robert Wood Johnson Foundation and the Commonwealth Fund through the Center for the Analysis of Health Practices, Harvard School of Public Health and by the National Center for Health Services Research under Grant HS-02063 to the Ambulatory Care Project. Beth Israel Hospital, Boston, Massachusetts. OOIO-4809/78/01 IZ-0177IEO2.00/0 177 Copyright 0 1978 by Academic Press. Inc. All rights of reproduction in any form reserved. Printed in Great Britain

178

HERBERT

SHERMAN

METHODS

The instrument for which the program will be described is the Texas Instruments (TI) SR-52l (with a lo-digit display in conventional notation or lo-digit mantissa plus 2-digit exponent in scientific notation) with an internal register storage of 12 decimal digits. The Hewlett-Packard (HP) Model 67 is at least equally suitab1e.l Both machines permit the generation and storage of programs on magnetic tapes which store up to 224 steps. Longer programs can be stored on an unlimited number of successive tapes providing the program does not require recursive references to prior tapes and providing that all of the intermediate data needed by the successive tapes can be stored in the accessible electronic storage registers. Four features of these calculators make our program possible: (1) Conditional and prior probabilities used in the computation can be stored on a magnetic tape and loaded into specified storage registers for use in succeeding tape-controlled programs. (2) “Indirect” references to storage registers allow program references to be directed by index registers under program control. (3) The calculator permits the use of subroutines. (4) Branching instructions, essential elements in most programs, are available. A. Bayesian Probability

Formula

The form of the Bayesian probability Warner (3): P(DJ

ii j-

calculation

[LZjP(Sjl Di)+ 1

P(IlIS)=7 5 P(Di) iz I

;i [a,iP(S,ilDi) ;= 1

used is that attributable

(I -aJ(l

-P(SjIDJ)l

--__ + (I -aj)(l

to

IAll -P(S,iD,))J

’ Since this work was completed, Texas Instruments has announced the SR-5Y which has up to ‘960 program steps and up to 100 storage registers. Although the SR-59 could make use of full con ditional probability rather than single-digit approximations, the SR-52 is available at about one-half of the price of the SR-59. 2 Some of the limitations of the Texas Instruments SR-52 calculator are not shared by the HewlettPackard 67. These limitations can be overcome by adding programming steps and therefore by increased program running time. For this program the major differences between the calculators are: (a) The availability of single stroke “integer” and “fraction” operations of the HP permit the independent capture of digits to the left and right of the decimal point but require as many as 15 program steps on the SR-52. (b) The wider range of single stroke branching instructions on the HP (s # .v, x = y, .Y c is. x > J, x < 0. x = 0), compared with those available in the SR-52 (X = 0, x > 0), saves program steps. The SR-52 calculator requires multistrokes to achieve the same branching set. (c) The SR-52 unit allows the index register to be decremented to 0 and to branch when 0 is reached whereas the HP unit allows the index register to be incremented or decremented to 0. (d) The SR-52 unit. judiciously used. allows use of up to 32 storage registers for intermediate results while the HP advertise only 26 such registers.

PART

A: POCKET

DIAGNOSTIC

CALCULATOR

179

where Sj = sign/symptom j;

0 C.i
Di = disease i; O< i
= = P(DJ = P(D,IS) =

0.5; Sj was not observed; 1.0; Sj is present; prior probability of disease, D, in the population of presenting patients; probability that disease, 0, occurs in patients with the complex of symptoms S; S = the presence or absence of the set of symptoms Si; P(SjIDJ = the conditional probability that symptom S,i occurs in patients with disease, Di. B. Number Storage

The required constants include up to 144 (i.e., 9 x 16) conditional symptom probabilities, 9 prior disease probabilities, 16 symptom states, and 2 numbers giving the actual number of diseases and symptoms used for any particular data tape. In addition to these 17 1 numbers required for the computation, transient data storage is needed to indicate the stage of computation, intermediate results, etc. Since there are only 20 advertised registers (one of which is needed as an index register), number storage is a severe limitation. All probabilities are stored as a string of digits. Up to 10 digits can be stored in each storage register without losing any digits through truncation during arithmetic manipulation. The IO-digit array P(S,iID,)P(S,iI

03. . ’ P(S,I D,)u,,

is stored as one block in each of the 16 symptoms, one designated for each symptom. The three remaining registers are used to store prior probabilities as a string, the i, index and the j, index. Each of the probabilities is retrieved by stripping the appropriate register of a single digit, using the digit in the computation, and then discarding the used digit; the discarded digit is supplanted with one significant digit of the computed Bayesian numerator at the end of the computation. Two approximations were used to fit the computations into the limited programming and data space available: (1) All prior and conditional probabilities are reduced to one significant figure. The maximum conditional or prior probability is limited to O.9.3 3 This latter constraint is not a serious limitation in practice. If, in fact, the prior probability of disease is 1.0. then there is no need for a Bayesian computation because the existence of the disease is certain. Similarly, if the conditional probability of Sj, given D, is 1.0, then the symptom is pathognomonic and no Bayesian calculation is necessary or useful.

180

HERBERT

SHERMAN

(2) The numerator of the Bayesian probability digits to the right of the decimal point.

is truncated to seven significant

C. General Features of Program and Tapes

In order to generalize the computation and to make it as independent as possible of specific combinations of differential diagnoses, the program is contained on three magnetic tapes, only one of which is disease specific. It assumes that the differential diagnosis considers up to nine alternatives (e.g., eight diseases and one “all others”) using 16 symptoms. The general flow diagram is shown in Fig. 1.

Tape 1 uses 18 1 program steps and contains: (1) The conditional probabilities for each of the symptoms, assuming the presence of each of the diseases. This requires knowledge of 9 x I6 conditional probabilities, wherej, = number of signs/symptoms used for the particular choice of differential diagnoses (Q16) and i, = number of differential diagnoses (< 9). (2) The prior probabilities for each of the i, diseases. (3) A program allowing the physician to enter the presence, absence, or failure to observe each of the symptoms,j,, for the particular patient under consideration. (4) A program which arranges these data into a storage format that permits the Bayesian probability computation on the next tape to be packed into 222 steps. In practice, the physician would enter the Data Tape I for the specific differential diagnosis disease set. After tape entry, the display gives the number of the specific symptom to be entered. The physician enters 0 indicating absence of the symptom, 5 indicating failure or inability to observe the symptom, or 94 indicating presence of the symptom. When the entry of all symptom indications is complete, the physician enters Tape II. Tape I can be modified to store local data on prior and conditional probabilities. Tape II uses 222 of the available 223 program steps in the program for calculating the numerator and denominator of the Bayesian probability for each of the i, 4Each converted

of these entries are effectively to 10 in the program.

divided

by 10 in the program.

The decimal

entry

digit

9 1s

PART A: POCKET DIAGNOSTIC

CALCULATOR

181

diseases, using the conditional probabilities, the prior probabilities, and the presence, absence, or lack of observation for each symptom supplied by Tape I. In order to compress the program into the available storage space, it is necessary to extract the components of the Bayesian calculation completed in Tape II and to process these into directly readable form by Tape III. In order to accommodate the Bayesian numerator in the limited storage, it is truncated to seven significant digits to the right of the decimal point. Tape III contains 2 13 program steps. It extracts the numerators and denominator of the Bayesian probabilities and computes the final probability for each disease. In order to check the effects of truncation, these probabilities can readily be summed; a significant deviation of this sum from 1.0 should be considered suspicious. A simplified version of the data flow for each tape is given in Appendix I. D. Storage Registers

Because all advertised registers were used to store the necessary information transferred from Tape I, there were no storage registers left for intermediate calculations. To circumvent this problem, the six registers needed by the program and the index register were taken from internal registers available within the calculator (4). These are not not normally advertised because their use can be compromised by storage space seized by the calculator to store intermediate results involving multiple parenthetic expressions. The program as written did not cause overwriting of these storage registers. E. Speedof Computation

In order to speed the computation, each conditional branch transfer is directed to an absolute program step instead of merely to a “labeled” point in the program. Although labeling of conditional branches simplifies program writing, it requires the calculator to search through all steps of the program until the appropriate label is discovered; this search takes an average of 0.2 sec. We also minimized the use of subroutines for the same reasons. RESULTS

A. Time

The time required is approximately proportional to the product of the number of diseases and the number of symptoms. For example, after the symptoms have been entered, a 9 disease x 16 symptom calculation (Tape II) takes 13 min, 21 sec. The presentation of the results for display (Tape III) takes an additional 2 min, 5 1 sec. B. Rounding Error

The sensitivity of the computed result to rounding errors was computed by standard techniques for Eq. [A 1I. (1) Sensitivity to rounding of conditional probabilities;

182

HERBERT

SHERMAN

Given the expression for P(Dil S) in Eq. ]A1 1,differentiation with respect to P(S,,I DJ gives the following sensitivity equation for each conditional probability: AP(D, I S)

@(Sj

I Di)( 1 - u,!)

L42J

P(Dt 1S) (1 - P(Di 1S)) = [u,jP(Sj I DJ + (1 - ai) (1 - p(S, / Di))] ’

The total error is AP(D, I S)

= -(I

-P(DilS))

AP(Sj I Di) (1 - - uj)

2

-.

]A31

P(Di I S)

The fractional error in P(Di IS), given by the left-hand side of the equation, is the sum of fractional errors in rounded conditional probabilities, each fractional error in rounded conditional probability weighted by two factors; i.e., for aj = 0, the first term does not exceed: AP(Si I DJ --. 1 - P(Sj I Di)

IA4i

This term can be large if P(S,I Di) approaches 1. With P(S,I Di) = 0.5, the weighting factor is 1 and decreases with further reduction of P(S,I Di). The other weighting factor, (1 - P(DiI S)), approaches 0 as P(D,l S) approaches 1. It is maximum when P(D,I S) = 0. (2) Sensitivity due to rounding of the prior probabilities: Differentiation of Eq. [Al 1 with respect to P(Di) gives the sensitivity of the P(D,I S): AP(Di I S) = P(DiI S)

I _

P(D,I S)

PCDJ

1po‘ MD,)

IA51

Thus, the fractional error due in P(D,l S) is proportional to the fractional error m P(Di). The proportionality constant may be negative and exceed one if P(D,IS) > P(D;).

This error can be significant if P(D,) = 0.05, for example, and P(D,l S) = 0.9. The error in assigning P(Di) = 0.1 in place of its true value of 0.05, will then be amplified by a factor of 17: 1, will lead to a reduction of the true value of P(D,I S) and to a failure in this first-order approximation. (3) Sensitivity to rounding of the numerator of the Bayesian probability: While the decision to round the numerator of the Bayesian probability to seven significant digits to the right of the decimal point seemed conservative, the error in this approximation becomes apparent when a large number of differential diagnoses is being considered. Fortunately, there is an easy internal check on the

PART A: POCKET DIAGNOSTIC

CALCULATOR

183

error. By summing the Bayesian probabilities for each of the differential diagnoses, the total should equal 1.0. If the sum is less than 1.0, rounding error is potentially significant. Provision is, therefore, made in the instructions for the program suggesting the user make this check. DISCUSSION

The principal limitation of the present tape-controlled calculators in implementing Bayesian probability computations is available storage. Ideally, conditional probabilities should be stored in individual registers with two or three significant digits. In our analysis, however, we had to store several such conditional probabilities in a single register and then “slice off’ as many digits as are required for the immediate computation. Because hand-held calculators are unlikely to be optimized for Bayesian probability computations, this technique will probably be of continuing utility as new generations of hand-held calculators are announced. The second most pressing limitation is the speed with which the computation is completed. To a limited extent, speed of completion will be aided as internal memory grows, permitting storage of more program steps and allowing use of only one magnetic tape containing all program steps. Speed would be further increased if there were enough registers to hold each of the conditional probabilities and each of symptom states (a$ Although it is unlikely that even in the next generation of such machines enough register memory will be available for both, it should be possible to store the individual symptom states in separate registers, thus avoiding the necessity for extracting each up It will also be possible to compute each (a, - 0.5) with its appropriate sign and then to store them for immediate recall. This will permit the computation of each term in the numerator in the form [a, - 0.51 x (2P(SjlDJ

- 1) + 0.5,

where the square-bracketed term is treated as a single number. This procedure will significantly shorten the number of program steps and the number of arithmetic operations. The final item that will speed the SR-52 computation will be the availability of an internally programmed truncation operation, a capability already available on the HP-67 and on the SR-59. The particular formulation of the Bayes’ computation used in this paper, offered by Warner, was proposed with the idea that the physician may weight the observation of a given sign/symptom on a certainty scale from 0 to 1.0, where 0 is definite absence and 1.0 is definite presence of the sign/symptom, and 0.5 indicates that the sign/symptom was not observed. (Remember that these are actually entered by decimal digits: 0 implying 0, 5 implying 0.5, and 9 implying 1.0.) The relative certainty of each entry is used in the calculations except for 0.9 which is converted to 1.0. The theoretical basis for this formulation has never been given to my knowledge,

184

HERBERT

SHERMAN

although it is intuitively plausible and has been repeated elsewhere (5). Our program as written5 permits use of this feature by entering this certainty, multiplied by 10. The ultimate limitation is, of course, the availability of sufficient experimental data to permit the Bayesian probability computation and the independence requirements of the signs and symptoms required in the computation. The lack of independence can be handled by more modern statistical techniques (e.g., logit analysis). The unavailability of data, except for a few groups of difFerential diagnoses, is a more grievous matter. Hopefully, with the demonstrated success of computerized diagnosis of abdominal pain (6), there may now be an incentive to collect such data for general use. The availability of such data and the newer and more powerful tapecontrolled calculators that will inevitably appear, suggest that a new era is now approaching in bedside diagnosis.

CONCLUSIONS

The essential elements of a program for computing Bayesian probabilities have been given. The program will deal with up to nine differential diagnoses characterized by up to 16 independent symptoms. The errors due to approximations of the various probabilities by single sign&ant digits are given by analytic expressions, and warnings are offered when the errors may be significant. APPENDIX SIMPLIFIED

I:

DATA FLOW DESCRIPTIONS

Tape I (Diseaseand Patient Specific Data)

(1) The number of symptoms for the differential diagnoses and the maximum number of differential diagnoses stored on this tape are entered into internal registers from the magnetic tape. (2) A set of prior probabilities (single digit for each disease) are taken off the magnetic tape and stored as a string in another internal register. This string can be changed from the keyboard by the physician to suit local conditions. (3) The conditional probabilities associated with each symptom state are stored as a string by removing the conditional probability from the magnetic tape, multiplying by powers of 10 as necessary and adding. (4) In the interactive mode the display presents to the physician the number of the symptom whose presence or absence (or relative certainty), a3 is next needed. This symptom certainty is entered by the physician as an integer from 0 to 9. This integer is placed at the leading digit of the string of conditional probabilities by simply multiplying the string by 10 and then adding aj ’ Copies of the program

are available

from the author.

PART

A:

POCKET

DIAGNOSTIC

CALCULATOR

185

(5) After all symptom states are entered, the physician is presented with a display of the entries that have been made so that these can be checked for accuracy. Tape II

(1) The calculator retains all of 20 internal storage registers intact while Tape II is being read into the machine. These registers contain from Tape I: the number of symptoms j,, the number of differential diagnoses i,, one register for each symptom containing the symptom state followed by the one-digit conditional probabilities for that symptom for each of the differential diagnoses. (2) The computation of the Bayesian probability is done in a looped fashion. The outer loop involves the computations for ith differential diagnosis. (3) The inner loop involves a computation for each of the symptoms that enter into the product making up the numerator. The core computation is done in the form: 2 x aj x P(S,IDJ

+ 1 -a,-

P(SjlDi)

rather than that given in Eq. [All. This form involves fewer program steps than the original Warner form. In order to do the computation, one must strip off aj and P(S,I Di) and store them temporarily. After the above computation is complete, P(Sj IDJ is discarded and a,i is returned to its original leading position of the string and one proceeds to the next value of j. (4) When all of the terms of the numerator are computed and multiplied term by term, P(Di) is extracted and multiplies the final product to give the numerator of P(D,I S); the numerator is added to a register to give the denominator. The numerator is truncated to seven digits to the right of the decimal point. Each digit is stripped off and stored in the conditional probability register to replace the P(Sjl Di) that has been discarded. This step is necessary because there are not enough program steps to complete the Bayesian computation on a single tape; the numerators must therefore be stored for use by Tape III in registers that are not erased during tape read-in. (5) As each P(D,IS) computation is completed, the outer loop is indexed to the next i. Tape III

(1) Since the number of differential diagnoses, i,, is less than 10, then each of the registers is stripped of the leading (10 - i,) digits in order to bring the significant digits of the numerator to the leading position in each of their seven registers. (2) The numerator for each P(D,I S) is collected digit by digit from each of the seven registers and assembled into one register. (3) The process is repeated i times.

186

HERBERT SHERMAN

(4) When all numerators have been assembled, each is divided by the denominator and by 10’ to give the Bayesian probability and stored in a register. (5) The physician can recall each register in turn and sum the probabilities in the process to insure that the closure error is small. The computed probabilities can be recalled as often as necessary. REFERENCES 1. LUSTED, L. B. “Introduction to Medical Decision Making.” Charles C Thomas, Springfield, Ill., 1968. 2. HORROCKS,J.C. A computer-aided diagnostic system using a small desk-top computer-calculator. Methods Inform. Med. 13,83 (1974). 3. WARNER, H. R. AND STALJFFER,W. M. Some techniques for computer-assisted diagnosis of heart disease. Proceedings on Automated Data Processing in Hospitals, Elsinor, Denmark, April-May 1966. (A more accessible source is (I), p. 32.) 4. Advanced programming techniques (appendix). In “Programming Workbook.” Texas Instruments, Inc., Dallas, Texas, 1966. 5. BARNOON, S., AND WOLFE, H. “Measuring the Effectiveness of Medical Decisions,” Appendix 1. Charles C Thomas, Springfield, Ill., 1972. 6. Editorial. Computers for Surgeons. Lancer 11,124i (1977).