Microcomputer Applications and Technology ^ ^

Microcomputer
and Technology
Applications
^^
Program To Calculate Means and
Standard Deviations
We have recently developed a short but useful program
to calculate means and standard deviations in sample sizes
of up to 1924 numbers between zero and 65024. The data
can be entered without knowing how many entries there
are since the program will count and save the entries and
then calculate the mean, variance, and standard deviation. It can also perform the calculations in numbers of
up to four decimal places as long as there are no more
t h a n five characters (excluding the decimal point) and the
numbers are all the same order of magnitude.
To complete the data entry, enter the number 65025,
which has been designated as terminator and initiates the
mean routine.
Although the program is written for the Commodore
64, it can be easily adapted to other computers. Care must
be taken to select a location into which to poke and peek
the values (lines 110, 260, 270, 310, and 410) that will not
interfere with the BASIC operating system. For the Commodore, that location is 49152.
The program may be obtained on disk by mailing $5.00
for postage and handling to Magali Huertas, MT(ASCP),
712 Livezey L a n e , P h i l a d e l p h i a , PA 19128.—Magali
Huertas, MT(ASCP), and Geronimo Lluberas-Acosta, MD,
Philadelphia.
READY
10 REM:PROGRAM TO CALCULATE MEAN AND
STANDARD DEVIATION
20 REM:BYMAGALI HUERTAS, M.T. AND GERONIMO
LLUBERAS-ACOSTA, M.D.
30 POKE53280,0:POKE53281,0:POKE646,1
35 PRINT""
40 PRINT" wait while memory loci are cleared"
100 for i=0to3848
110 poke 49152 + i,0:next
120 print" start program 1"
123 print" instructions 2"
125 print""
128 prinf'PRESS 1 OR 2 AND RETURN";:
INPUTV:IFV<10RV>2THEN128
130 IFV = 2THENGOSUB600
140 PRINT" choose data format"
142 prinf'whole numbers
0"
144 prinf'one decimal place
1"
146 prinftwo decimal places
2"
148 prinf'three decimal places 3"
150 prinf'four decimal places
4"
155 print" "
160 prinf'ENTER YOUR CHOICE (0 TO 4)";:INPUTFM
165
170
172
175
180
200
210
215
220
230
240
260
270
280
290
300
310
320
330
340
370
380
390
400
410
420
430
435
440
445
450
460
465
470
475
480
485
490
495
500
505
510
515
550
IFFM<0ORFM>4THEN160
PRINT" hardcopy of the analysis?"
print""
print" PRESS T FOR YES OR 'N' FOR
NO";:INPUTPR$
IFPR$o"N"THEN175
E = 1924
FOR I = OTOE
Q=l+1
PRINT"ENTRY#"; Q; " = "; :INPUTX
IFX = 65025THENN = l:GOTO290
X = X*10fFM
P = INT(X/255):POKE49152 + (2*I),P
R = X - (P*255):POKE49153 + (2*I),R
NEXT
T=0
FORI = 0TO(N-1)
S = ((PEEK(49152 + (2*l)))*255 + PEEK
(49153 + (2*l)))/10fFM
T = T + S:NEXT
AV = T/N:AV = (INT(AV* 1000))/1000
IFPR$ = "Y"THENOPEN4, 4, 7
PRINT""
PRINT"#"; TAB(5); "X"; TAB(14); " X - M " ;
TAB(26);"(X-M)t2"
K = 0:L = 0:J = 0
FORI = 0TO(N-1)
S = ((PEEK(49152 + (2I)))*255 + PEEK
(49153 + (2*I)))/10|FM
L = ABS(AV - S):L = (INT(L*1000))/1000
K = L|2:Q = I + 1
PRINTQ; TAB(4); S; TAB(12); L; TAB(24); K
IFPR$ = "Y"THENPRINT#4,Q;TAB(4); S;
TAb(8);L;TAB(10);K
J = J + K:NEXT
F = J/(N-1)
SD = F|(1/2)
SD = (INT(SD*1000))/1000
PRINT"N = ";
PRINT"MEAN = "; AV
PRINT"VARIANCE = ";F
PRINT'STANDARD DEVIATION = "TAB(12); SD
IFPR$ = "N"THENGOTO550
PRINT#4,"N= "; N
PRINT#4,"MEAN= "; AV
PRINT#4,"VARIANCE= "; F
PRINT#4, "STANDARD DEVIATION = "; TAB(6); SD
CLOSE 4
END
LABORATORY MEDICINE • VOL. 17, NO. 7, JULY 1986 419
600
610
620
630
640
650
655
660
665
670
675
680
690
700
710
720
PRINT'this program is designed to calculate"
prinf'mean, variance and standard deviation"
prinf'of a group of up to 1924 numbers be-"
print'lween 0 and 65024 of no more than five"
prinf'characters (excluding decimal point)"
prinfeach."
prinf'press return to continue.":input
prinf'after completing the entry the number"
print"
print"65025"
print"
prinf'should be entered, this will indicate"
prinf'to the computer that the sequence is"
prinfcomplete."
prinf'press return to continue.":input
return
Correlations
This program studies the relationship of two sets of results. It can be used to correlate two methods or two tests.
The program is written for the Commodore 64 or Vic-20
in BASIC and can be easily translated into other basic
forms.
The program will accept up to 200 inputs (100 for each
of the two values) and will stop and do all the required
calculations by merely typing "stop" or "end" as a reference value after the last "real" value. It can be previewed
on the screen, and a hard copy option is available to those
with a printer.
The printout or screen view will show a comparison of
all values, t h e slope, y intercept "y," and correlation "r."
All t h a t is needed is graph paper (to plot the study).—Ron
Sorochin, BS, MT(ASCP), Jones Memorial Hospital,
Wellsville, NY.
101
102
103
105
110
115
116
PRINT:INPUT" TEST EVALUATED";TE$
DIMR$(100),T$(100);N = 0
DIMR(100),T(100)
PRINT:PRINT:INPUT" REFERENCE METHOD";RM$
:PRINT.INPUT" TEST METHOD";TM$
FORQ=1TO100
PRINT:PRINT"
PLEASE ENTER REFERENCE
VALUE ":
120 PRINT"
THEN TEST VALUE":INPUTR$(Q),T$(Q)
124 IFR$(Q) = "STOP"ORR$(Q) = "END"THENGOTO130
125 :N = N + 1: NEXT
130 FORW = 1TON
131 R(W) = VAL(R$(W)):T(W) = VAL(T$(W))
135 Z = R(W)
136 X = X + Z
137 NEXT
140
145
146
147
150
152
154
155
156
157
160
165
166
167
170
180
200
210
220
230
240
245
246
247
248
249
250
252
257
258
259
260
261
262
263
300
310
FORW=1TON
U=T(W)
Y = Y+U
NEXT
PRINT" REFERENCE TOTAL " X
PRINTPRINT" TEST TOTAL
"Y
FORW=1TON
ZZ = R(W)*R(W)
XX = XX + ZZ
NEXT
FORW=1TON
UU = T(W)*T(W)
YY = YY + UU
NEXT
PRINTPRINTTOTAL X f 2 ="XX
PRINTPRINTTOTAL Y j 2 = "YY
FORW=1TON
KK = R(W)*T(W)
LL = LL + KK
NEXT
PRINTPRINTTOTAL X*Y = "LL
INPUT" NEED HARDCOPY Y/N";HC$
IFHC$ = "Y"THENGOTO250
INPUT'SCREEN VIEWING (S) OR END (E)";IY$
IFIY$ = "E"THENEND
IFHC$ = "N"GOT0252
OPEN1,4:CMD1
PRINTPRINT'CORRELATION STUDY FOR - "TE$
PRINT" REFERENCE - "RM$" TEST - "TM$
PRINT"
PRINT" REFERENCE
TEST"
PRINT"
FORQ=1TON
"T(Q)
PRINT"
"R(Q)"
NEXT
M = (LL-((X*Y)/N))/(XX-((X | 2)/N))
"INT(M*100+.5)/
PRINTPRINT"
SLOPE =
100
400 B = Y/N-(M*(X/N))
Y INTERCEPT =
410 PRINTPRINT"
"INT(B*100 + .5)/100
600 R = ((N*LL)-(X*Y))/(SQR(((N*XX)-(X*X))*((N*YY)(Y-Y))))
R (COEFF) = "INT(R*100 + .5)/
620 PRINTPRINT"
100
622 PRINTPRINT"
ACCEPTABLE
NOT ACCEPTABLE
623 PRINT"
TECH
DATE
RV'D
DATE
624 PRINT"
625 IFHC$()"Y"GOT0245
1000 IFHC$ = "Y"THEN PRINT#1,4:CLOSE1
Items Wanted
Please help us strengthen the newsworthiness and ex- crocomputing. The section has not been conceived as a place
for long pieces, even though longer submissions are welchange of information offered in MICROCOMPUTER
come and treated as candidates for publication as regular
APPLICATIONS AND TECHNOLOGY. The sphere of microcomarticles in Laboratory Medicine. Please send your items along
puting continues to expand and we want to provide brief
to Laboratory Medicine, attn Microcomputer Applications and
updates from every front: short reviews of programs and
Technology, 2100 W Harrison St, Chicago, IL 60612-3798 —
equipment, notes on any of the myriad of publications now
The Editors.
focused exclusively on this field, and commentary on the
pleasures and frustrations involved in the experience of mi420 LABORATORY MEDICINE • VOL. 17, NO. 7, JULY 1986