Correlation Formula

400092

New Member
Hi, I have the below code and want to confirm if the correlation formula matches the code..

newnum = num do 10 i=1,num
if(val1(i) .le. -999.000 .or. val2(i) .le. -999.000 ) then
newnum = newnum - 1
goto 10
endif
sumx = sumx + val1(i)
sumy = sumy + val2(i)
sumxy = sumxy + val1(i)*val2(i)
sumx2 = sumx2 + val1(i)**2
sumy2 = sumy2 + val2(i)**2
10 continue
if(newnum .le. 0) then
type *,' '
type *,'gbicorcoef - newnum = ',newnum
type *,' '
rcode = 2
return
endif
corcoef = newnum*sumxy - sumx*sumy
if((newnum*sumx2-sumx**2)*(<wbr>newnum*sumy2-sumy**2) .le. 0) then
type *,'gbicorcoef - trying sqrt on ',
+ (newnum*sumx2-sumx**2)*(<wbr>newnum*sumy2-sumy**2)
corcoef = -999.999
goto 9999
endif
corcoef =
+ corcoef/sqrt((newnum*sumx2-<wbr>sumx**2)*(newnum*sumy2-sumy**<wbr>2))

Correlation formula: [ NΣXY - (ΣX)(ΣY) / Sqrt([NΣX<sup>2</sup> - (ΣX)<sup>2</sup>][NΣY<sup>2</sup> - (ΣY)<sup>2</sup>])]

-- removed inline image ---

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I don't know what that language is, but the formula translates literally in Excel to

=(ROWS(x)*SUMPRODUCT(x,y) - SUM(x)*SUM) / SQRT( (ROWS(x)*SUMPRODUCT(x,x) - SUM(x)^2)*(ROWS(x)*SUMPRODUCT(y,y) - SUM^2))

or simplifies to

=SUMPRODUCT(x - AVERAGE(x), y - AVERAGE) / SQRT((SUMPRODUCT((x - AVERAGE(x))^2) * SUMPRODUCT((y - AVERAGE)^2)))

or just

=CORREL(x, y)

Replies
5
Views
454

1,207,423
Messages
6,078,443
Members
446,338
Latest member
AliB

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back