[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rank Correlation Function for Arrays



PureBytes Links

Trading Reference Links


Did anyone try to code the more complicated formula for the case where
there are ties?

ysk

On Sat, 2 Mar 2002 10:41:11 -0500
"Alex Dannenberg" <alex@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

> ...Also, just look in Numerical Recipes to see that the rank correln is
> equal to "value1" only when there are no ties (i.e. Ties=1).  Otherwise, you
> need to compute the correln among the ranks explicitly or use a much more
> complicated expression that requires storing all the informn about ties...
> (see  http://lib-www.lanl.gov/numerical/bookcpdf/c14-6.pdf)
> 
> Hope this helps.
> 
> -Alex
> 
> -----Original Message-----
> From: Alex Dannenberg [mailto:alex@xxxxxxxxxxxxxxxxxxxxxxx]
> Sent: Saturday, March 02, 2002 10:24 AM
> To: Michael E Songer; Omega-list (E-mail)
> Subject: RE: Rank Correlation Function for Arrays
> 
> 
> ...Just to make the thing a bit more efficient, you can replace
> 
> 
> 	If Ties=1 then myRank=HiCount;
> 	If Ties>1 then begin
> 		Tot=0;
> 		For z=1 to Ties-1 begin
> 			Num=HiCount+1;
> 			Tot=Tot+Num;
> 			HiCount=Num;
> 		End;
> 		myRank=Tot/(Ties-1);
> 	End;
> 
> 
> with
> 
> 	myRank=HiCount+(Ties-1)/2
> 
> -Alex
> 
> 
> -----Original Message-----
> From: Michael E Songer [mailto:songer@xxxxxxxxxxxxx]
> Sent: Friday, March 01, 2002 2:16 PM
> To: Omega-list (E-mail)
> Subject: Rank Correlation Function for Arrays
> 
> 
> List,
> Several people expressed an interest in a rank correlation function to be
> used with arrays. Here is the function: msCorrel_Rank_a.  I have also
> included a sample indicator.
> Mike
> 
> 
> {SAMPLE INDICATOR}
> {*************************************************************************}
> Arrays: IndArray[50](0), DepArray[50](0);
> VARS: x(0);
> 
> 
> for x=0 to 50 begin
> 	IndArray[x]=c[x] of data2;
> 	DepArray[x]=c[x] of data1;
> End;
> 
> value1=msCorrel_Rank_a(DepArray, IndArray);
> 
> plot1(value1,"rankCor");
> plot2(0,"zero");
> 
> {**************************************************************************}
> 
> 
> 
> 
> {FUNCTION}
> {*************************************************************************
> 
> Fill [0] element in array being evaluated.
> Limit 100 elements. Change to larger value if you like.
> 
> Michael E. Songer
> songer@xxxxxxxxxxxxx
> *************************************************************************}
> 
> 
> INPUTS: DepArray[Dsize](NumericArrayRef), IndArray[Isize](NumericArrayRef);
> VARS: x(0),y(0),z(0),HiCount(0),Ties(0),myRank(0),Tot(0),Num(0);
> VARS:Sum(0),Diff(0),Diff2(0),N(0);
> ARRAYS: DepRankArray[100](0),IndRankArray[100](0);
> 
> 
> {Fill DepRankArray}
> For x = 0 to Dsize Begin
> 	HiCount=1;
> 	Ties=0;
> 	For y= 0 to Dsize begin
> 		If DepArray[x]>DepArray[y] then HiCount=HiCount+1;
> 		If DepArray[x]=DepArray[y] then Ties=Ties+1;
> 	End;
> 	If Ties=1 then myRank=HiCount;
> 	If Ties>1 then begin
> 		Tot=0;
> 		For z=1 to Ties-1 begin
> 			Num=HiCount+1;
> 			Tot=Tot+Num;
> 			HiCount=Num;
> 		End;
> 		myRank=Tot/(Ties-1);
> 	End;
> 	DepRankArray[x]=myRank;
> End;
> 
> {Fill IndRankArray}
> For x = 0 to Isize Begin
> 	HiCount=1;
> 	Ties=0;
> 	For y= 0 to Isize begin
> 		If IndArray[x]>IndArray[y] then HiCount=HiCount+1;
> 		If IndArray[x]=IndArray[y] then Ties=Ties+1;
> 	End;
> 	If Ties=1 then myRank=HiCount;
> 	If Ties>1 then begin
> 		Tot=0;
> 		For z=1 to Ties-1 begin
> 			Num=HiCount+1;
> 			Tot=Tot+Num;
> 			HiCount=Num;
> 		End;
> 		myRank=Tot/(Ties-1);
> 	End;
> 	IndRankArray[x]=myRank;
> End;
> 
> {CALCULATE RANK CORRELATION}
> Sum=0;
> For x=0 to Dsize begin
> 	Diff=IndRankArray[x]-DepRankArray[x];
> 	Diff2=square(Diff);
> 	Sum=Sum+Diff2;
> End;
> N=Dsize+1;
> 
> value1= 1 - ( ( 6*Sum ) / ( N*(square(N)-1) ) );
> 
> msCorrel_Rank_a=value1;
> 
> {*******************************************************************}
>