Statistical Functions for Archive

See all articles from CATS v7 n9
Publication: CATS Newsletter
Pub Details: CATS v7 n9 (Volume 7, Issue 9)
Date: January 1990
Pages: 9

Archive, like Superbasic, is an extendable language through user defined procedures. While Archive does not have any built-in statistical functions, these can easily be added. The following procedures let you calculate the mean, standard deviation and coefficient of variation for any numerical field in your data base. Additionaly, you can plot a graph of the data in the field to your screen. The functions are called by entering stat;field where field is the number of the field you wish statistics for. Note that data fields in archive are numbered beginning with 0, not 1. To plot a graph of the data, first generate the statistics as above. Then enter splot;field (where field is again the field number you wish to examine). A graph of the data, properly scaled will be displayed.

proc dec2
let mean=val(dec(avg,2,10))
let sd2=val(dec(2*sd,2,10))
endproc

proc splot;
fld mode 0,8
dec2
print at 5,0;mean+sd2
print at 6,0;"+2sd"
print at 10,0;mean:
print at 11,0;"Mean
print at 15,0;mean-sd2:
print at 16,0;"-2sd"
let screen-unit=10/(4*sd)
let hpos=10
all
print at 5,hpos;"-"
print at 10,hpos;"-"
print at 15,hpos;"-"
print at (10-((fieldv(a)-mean)*
screen-unit)),hpos;"x"
let hpos=hpos+2
endall
print at 22,0;"data points sd
avg cv"
print tab 5;n; tab 20;sd2/2; tab
30;mean; tab
40;val(dec(SD/N,3,10))
print at 0,0;""
endproc

proc stat;field
let a=field
cls
print "calculating statistics" stat1
stat2
print : print
print n;" DATA POINTS"
print "Average Value : ";(dec
(avg,3,10))
print "S.D. : ";(dec(sd,3,10))
print "C.V. : ";(dec(sd/n,3,10))
endproc

proc stat1
last : let n=recnum()+1
let sum=0

all
let sum=sum+fieldv(a)
endall
let avg=sum/n
endproc

proc stat2
let sd=0: let ss=0
all
let sq=(avg-fieldv(a))*(avg-fieldv(a))
let ss=ss+sq
print fieldv(a);" ";
endall
let sd=sqr(ss/(n-1))
endproc

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.