| 
 PureBytes Links 
Trading Reference Links 
 | 
I have been following the discussion on Pearson's Correlation function.
Here is a post regarding that which I posted in February of 1999.
Also included is some additional information I posted, which was in
response to the questions I  received regarding my posting of the
Pearson's R function.
-----------------------------
Response:
I used the formula found in "Multivariate Statistical Analysis: A
Conceptual Introduction" by Sam Kash Kachigan. The formula can be found
on page 130. For any of you who have Advanced Get, they have a Pearson's
R value which is displayed on their regression lines.  I used this value
to verify my function.  I was able to match my results with theirs.
Gary Funck also posted a Reference found on the web
(http://econ8.hku.hk/stat/hyperstat/A34739.html), which at first glance
looks correct (I have not gone through it thoroughly).
For statistical reference I would recommend the following two books.
These should be in everyone's library:
        Multivariate Statistical Analysis : A Conceptual Introduction
        by Sam Kash Kachigan
        Paperback - 303 pages 2nd edition (June 1991)
        Radius Press
        ISBN: 0942154916
        PDQ Statistics
        by Geoffrey R. Norman, David L. Streiner
        Paperback - 208 pages 2 Ed edition (September 1998)
        Blackwell Science Inc
        ISBN: 1550090763
--------------------------------------------------------------------------------------------------
{*********************************************************
Userfunction:           Pearsons_R
Usage:                  Pearsons_R( Price, Length )
Author:                 Andrew
Last Date Modified:     18 February 1999
This function calculates and returns the Pearson's R Value.
This Code was Adapted from Code received on 15 February 1999
from the Code List.
Original Notes with the code were:
 Pcorrelation
 Calculates Pearson's Correlation Coefficient r.
 Created 12/17/96
*********************************************************}
INPUTS:  Price(NumericSeries),
         Length(Numeric);
VARS:   V1m(0),
        V2m(0),
        n(0),
        S1(0),
        S2(0),
        Count(0),
        SumGhost(0),
        AvgGhost(0),
        Count2(0),
        SumSqr(0),
        Count3(0),
        StdDevGhost(0),
        SumSqr2(0),
        Count4(0),
        StdDevPrice(0);
ARRAY:  Ghost[999](0);
Ghost[0] = 1;
FOR Count = 1 TO ( Length - 1 )
BEGIN
 Ghost[Count] = Ghost[Count-1] + 1;
END;
V1m = Average(Price, Length);
SumGhost = 0;
FOR Count2 = 0 TO ( Length - 1 )
BEGIN
 SumGhost = SumGhost + Ghost[Count2];
END;
AvgGhost = ( SumGhost / Length );
V2m = AvgGhost;
S1 = 0;
FOR n = 0  TO ( Length - 1 )
BEGIN
 S1 = ( S1 + (Price[n] - V1m) * (Ghost[n] - V2m) );
END;
IF ( Length <> 0 ) THEN
BEGIN
 SumSqr = 0;
 FOR Count3 = 0 TO (Length - 1 )
 BEGIN
  SumSqr = SumSqr + (Ghost[count3]-V2m) * (Ghost[count3]-V2m);
 END;
 StdDevGhost = SquareRoot(SumSqr / ( Length - 1 ) );
END ELSE
 StdDevGhost = 0;
IF ( Length <> 0 ) THEN
BEGIN
 SumSqr2 = 0;
 FOR Count4 = 0 TO (Length - 1 )
 BEGIN
  SumSqr2 = SumSqr2 + (Price[count4]-V1m) * (Price[count4]-V1m);
 END;
 StdDevPrice = SquareRoot(SumSqr2 / ( Length - 1 ) );
END ELSE
 StdDevPrice = 0;
S2 = ( ( Length -1 ) * StdDevPrice * StdDevGhost);
IF ( S2 = 0 ) THEN
BEGIN
 Pearsons_R = 0;
END ELSE
BEGIN
 Pearsons_R  = ( S1 / S2 ) * ( -1 );
END;
 |