# correlation analysis tool

n=7

decimal(3)

font "arial",10,100

graphsize 500,500

dim x(n) : dim y(n)

tx=0 : ty=0

x = {2,3,3,4,4,6,5}

y = {1,2,4,5,4,8,7}

for m = 0 to n-1

tx=tx+x[m] : ty=ty+y[m]

next m

meanx=tx/n : meany=ty/n

sdx=0 : sdy=0: sdxy=0

for m = 0 to n-1

sdx=sdx +(x[m]-meanx)^2

sdy=sdy +(y[m]-meany)^2

sdxy=sdxy +(x[m]-meanx)*(y[m]-meany)

next m

sx=(sdx/n)^.5

sy=(sdy/n)^.5

covxy=sdxy/n

r= covxy/(sx*sy)

m= covxy/sx^2

c= meany-m*meanx

# Standard deviation covariance correlation coefficient and line of best fit

Print "Sx="+sx

Print "Sy="+sy

Print "Sxy="+covxy

print "r="+r

print "y="+m+"x+"+c

# graph parameters

minx=-10 : maxx=10 : miny=-10 : maxy=40

rangex=(maxx-minx)

rangey=(maxy-miny)

for i= 0 to 10

line 0,i*50,500,i*50

line i*50,0,i*50,500

text i*50,480,minx+rangex*i/10

text 0,500-i*50,miny+rangey*i/10

next i

color red

for i= 0 to n-1

circle (x[i]-minx)*(500/rangex),500-(y[i]-miny)*(500/rangey),5

next i

color blue

for i= 0 to 500

circle i,500*(1+(-c+miny)/rangey)-m*(rangex/rangey)*(i+500*minx/rangex) ,2

next i

rangex=(maxx-minx)

rangey=(maxy-miny)

for i= 0 to 10

line 0,i*50,500,i*50

line i*50,0,i*50,500

text i*50,480,minx+rangex*i/10

text 0,500-i*50,miny+rangey*i/10

next i

color red

for i= 0 to n-1

circle (x[i]-minx)*(500/rangex),500-(y[i]-miny)*(500/rangey),5

next i

color blue

for i= 0 to 500

circle i,500*(1+(-c+miny)/rangey)-m*(rangex/rangey)*(i+500*minx/rangex) ,2

next i

## No comments:

## Post a Comment