bljacobs
01-23-2014, 08:22 AM
Ran into a problem when calculate the Spearman Rank Correlation using the function spear when all of the values in one of the particular series were set to zero. The evaluation of fac at this point in the code was being set to zero.
fac = (1.0 - sf/en3n) * (1.0-sg/en3n);
Consequently the program was not able to calculate zd or rs.
There was a check for fac > 0, but it was a few lines too late. By moving that up several lines in the code I was able to resolve the problem. Here's what the final code segment looks like.
if (fac > 0.0)
{
vard = ((en - 1) * en * en * Math.Pow(en + 1, 2) / 36) * fac;
zd = (d - aved) / Math.Sqrt(vard);
probd = erfcc(Math.Abs(zd) / 1.4142136);
rs = (1 - (6 / en3n) * (d + (sf + sg) / 12)) / Math.Sqrt(fac);
fac = (rs + 1) * (1 - rs);
t = rs * Math.Sqrt((en - 2) / fac);
df = en - 2;
probrs = betai(0.5 * df, 0.5, df / (df + t * t));
}
else
{
rs = 0;
probrs = 0.0;
}
fac = (1.0 - sf/en3n) * (1.0-sg/en3n);
Consequently the program was not able to calculate zd or rs.
There was a check for fac > 0, but it was a few lines too late. By moving that up several lines in the code I was able to resolve the problem. Here's what the final code segment looks like.
if (fac > 0.0)
{
vard = ((en - 1) * en * en * Math.Pow(en + 1, 2) / 36) * fac;
zd = (d - aved) / Math.Sqrt(vard);
probd = erfcc(Math.Abs(zd) / 1.4142136);
rs = (1 - (6 / en3n) * (d + (sf + sg) / 12)) / Math.Sqrt(fac);
fac = (rs + 1) * (1 - rs);
t = rs * Math.Sqrt((en - 2) / fac);
df = en - 2;
probrs = betai(0.5 * df, 0.5, df / (df + t * t));
}
else
{
rs = 0;
probrs = 0.0;
}