Wednesday, January 2, 2013

Correlation


Find the correlation of following data
X     Y
10    20
20    30
30    40
40    50
Solution:
         Real x,y,sumx,sumy,ssqrx,ssqry, spxy, Num , Den, r
         Write(*,*) 'Enter the value of N'
         read(*,*) N
          sumx= 0.0
         sumy= 0.0
          ssqrx= 0.0
         ssqry= 0.0
         spxy= 0.0
         Do j = 1,N
         Write(*,*) 'Enter the value of x',j
         read(*,*) x
         Write(*,*) 'Enter the value of y',j
         REad(*,*) y
         sumx = sumx+ x
         sumy = sumy+ y
         Avex= sumx/N
         Avey= sumy/N
         ssqrx= ssqrx+ x**2
         ssqry= ssqry+ y**2
         spxy=spxy+(x*y)
         End do
         Num= spxy- ((sumx*sumy)/n)
         Den= sqrt((ssqrx-(Avex)**2)*(ssqry-(Avey)**2))
         r = Num/Den
         write(*,*) 'The correlation between x and y is =' , r , ssqrx
         End


hints: her we consider N= 4 because each of the variable has 4 observation.

No comments:

Post a Comment