' *** CORRELAT.LST *** 2nd GFA-Manual, page 6-7 > PROCEDURE correlation(i1,i2,VAR proc1(),proc2(),cor#,sign!,a#,b#) ' ' *** Calculate correlation cor# between two word-arrays ' *** Compares elements i1-i2 in both arrays ' *** Not more than 1000 elements can be compared! ' *** If correlation is significant (95 %): sign!=TRUE ' *** Parameters of regression-line are a# and b#: y = a#x + b# ' LOCAL n,i,sum.xy%,sum.x%,sum.y%,sum.x2%,sum.y2%,p#,q# LOCAL cor.a,cor.r#,m\$,k CLR sum.xy%,sum.x%,sum.y%,sum.x2%,sum.y2%,sign! ' n=SUCC(SUB(i2,i1)) ! number of elements IF n<=1000 ' FOR i=i1 TO i2 ADD sum.xy%,MUL(proc1(i),proc2(i)) ADD sum.x%,proc1(i) ADD sum.y%,proc2(i) ADD sum.x2%,MUL(proc1(i),proc1(i)) ADD sum.y2%,MUL(proc2(i),proc2(i)) NEXT i p#=sum.xy%-MUL(sum.x%,sum.y%)/n q#=SQR((sum.x2%-MUL(sum.x%,sum.x%)/n)*(sum.y2%-MUL(sum.y%,sum.y%)/n)) cor#=p#/q# ' RESTORE cor.r.values REPEAT READ cor.a,cor.r# UNTIL n<=cor.a IF ABS(cor#)>=cor.r# sign!=TRUE ENDIF ' q#=sum.x2%-MUL(sum.x%,sum.x%)/n a#=p#/q# b#=sum.y%/n-a#*(sum.x%/n) ' ELSE ' OUT 2,7 m\$=" *** Error ***|Procedure Correlation |can't digest more |" m\$=m\$+"than 1000 elements" ALERT 3,m\$,1,"Sorry",k CLR cor#,a#,b# ' ENDIF ' cor.r.values: DATA 3,.988,4,.9,5,.805,6,.729,7,.669,8,.622,9,.582,10,.55,11,.524,12,.497 DATA 13,.476,14,.458,15,.441,16,.426,17,.421,18,.4,19,.389,20,.378,21,.369 DATA 22,.36,24,.344,26,.33,28,.317,30,.306,35,.275,40,.264,50,.235,60,.214 DATA 70,.195,80,.185,90,.173,100,.165,250,.104,500,.074,1000,.052 RETURN ' ********* '