33 short *accept1,
short *accept2,
34 long rows,
long *count) {
35 double sum1[2] = {0, 0}, sum2[2] = {0, 0}, sum12 = 0;
41 for (i = 0; i < rows; i++) {
42 if (isnan(data1[i]) || isnan(data2[i]) || isinf(data1[i]) || isinf(data2[i]))
44 if ((accept1 && !accept1[i]) || (accept2 && !accept2[i]))
48 sum1[1] += data1[i] * data1[i];
50 sum2[1] += data2[i] * data2[i];
51 sum12 += data1[i] * data2[i];
55 d1 = count1 * sum1[1] - sum1[0] * sum1[0];
56 d2 = count1 * sum2[1] - sum2[0] * sum2[0];
57 if (d1 <= 0 || d2 <= 0)
61 r = (count1 * sum12 - sum1[0] * sum2[0]) / sqrt(d1);
82 if ((r = fabs(r)) > 1)
103 short *accept1,
short *accept2,
104 long rows,
long *count,
long shift) {
105 double sum1[2] = {0, 0}, sum2[2] = {0, 0}, sum12 = 0;
117 for (i = i1; i < i2; i++) {
119 if (is < 0 || is >= rows) {
120 fprintf(stderr,
"shift limits set incorrectly\n");
123 if (isnan(data1[i]) || isnan(data2[is]) || isinf(data1[i]) || isinf(data2[is]))
125 if ((accept1 && !accept1[i]) || (accept2 && !accept2[is]))
129 sum1[1] += data1[i] * data1[i];
130 sum2[0] += data2[is];
131 sum2[1] += data2[is] * data2[is];
132 sum12 += data1[i] * data2[is];
136 d1 = (*count) * sum1[1] - sum1[0] * sum1[0];
137 d2 = (*count) * sum2[1] - sum2[0] * sum2[0];
138 if (d1 <= 0 || d2 <= 0)
142 r = ((*count) * sum12 - sum1[0] * sum2[0]) / sqrt(d1);
double linearCorrelationSignificance(double r, long rows)
Compute the statistical significance of a linear correlation coefficient.
double shiftedLinearCorrelationCoefficient(double *data1, double *data2, short *accept1, short *accept2, long rows, long *count, long shift)
Compute the linear correlation coefficient between two data sets with a given shift.
double linearCorrelationCoefficient(double *data1, double *data2, short *accept1, short *accept2, long rows, long *count)
Compute the linear correlation coefficient for two data sets.
double rSigLevel(double r0, long nu)
Computes the probability that the linear correlation coefficient exceeds a given value.