The theoretical (exact) value of this correlation is 0 which can be seen
by looking at the numerator of the correlation function:
Sum [ (x_i - mu_x) (y_i - mu_y) ]
= Sum [ x_i y_i - mu_x y_i - mu_y x_i + mu_x mu_y ]
= 1 - mu_x Sum [ y_i] - mu_y Sum [ x_i ] + N mu_x mu_y
= 1 - (0.2) (5) - (1/3) (3) + 1
= 0
Both of the codes you are using are giving values close to 0 (they are
both below the GSL_DBL_EPSILON value) and the fact that they differ
slightly isn't indicating a problem with the codes.
Schleicher, Martin wrote:
Hi,
I'm trying to compute the correlation between two arrays and get a different
value to what I get using Mathematica or even Excel.
This is part of my code, where ci and cj are 2 pointers to gsl vectors:
double correl;
gsl_vector_view mci = gsl_matrix_row(C, i);
gsl_vector_memcpy(ci, &mci.vector);
gsl_vector_view mcj = gsl_matrix_row(C, j);
gsl_vector_memcpy(cj, &mcj.vector);
correl = gsl_stats_correlation(ci->data, ci->stride, cj->data, cj->stride,
NSONGS);
The two arrays / vectors are:
1 0 1 0 0 0 0 0 0 0 0 0 0 0 1
1 1 0 1 1 0 0 0 0 0 0 0 0 1 0
And the result for correl is -9.58308e-21 when it 'should' be -1.96262e-17.
Am I doing something wrong?
Thanks in advance,
Martin
_______________________________________________
Bug-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gsl
_______________________________________________
Bug-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gsl