Wednesday, January 2, 2013

Correlation and regression


  
Find the correlation coefficient , regression coefficient of x  and estimated value of
Y with the help of dimension or array for the following data.
X       y
6       8
8       3
9       5
61      32
88      57
56      46
12      50
32      39
50      20 

Solution : here we see that the total number of observation is 10 so we put do I = 1,10
And put the values with respect to x and y.
Answer:
        dimension x(10)  ,Y(10)
          print*, 'enter value of dimension x'
          do i = 1,10
          read(*,*) x(i)
          end do
          write(*,*) 'Enter the value of the dimension y'
          do j= 1,10
          read(*,*) y(j)
          End do
          sumx=0
          sumy=0
          do i=1,10
            sumx=sumx+x(i)
            sumy=sumy+y(i)
          enddo
          avex=sumx/10.0
          avey=sumy/10.0
          sum1=0
          sum2=0
          spxy=0
          do i=1,10
            sum1=sum1+(x(i)-avex)**2
            sum2=sum2+(y(i)-avey)**2
            spxy=spxy+(x(i)-avex)*(y(i)-avey)
         end do
         correlation= spxy/sqrt(sum1*sum2)
         Byx=spxy/sum1
         A=avey-(Byx*avex)
         print*, 'the value of corr',correlation,'      ','Byx is=',Byx
         print*, 'the estimatec value of Y is =', a
         print*, 'average of x is', avex,'    ',' and average of y is',avey
         stop
         end

No comments:

Post a Comment