Correlation Formula

400092

New Member
Joined
Dec 30, 2010
Messages
11
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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I don't know what that language is, but the formula translates literally in Excel to

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

or simplifies to

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

or just

=CORREL(x, y)
 
Upvote 0

Similar threads

Forum statistics

Threads
1,224,396
Messages
6,178,396
Members
452,844
Latest member
Shebl

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top