bug-gsl
[Top][All Lists]
Advanced

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

Re: [Bug-gsl] gsl_stats_correlation bug?


From: Patrick Alken
Subject: Re: [Bug-gsl] gsl_stats_correlation bug?
Date: Tue, 17 Nov 2009 17:45:14 -0700
User-agent: Thunderbird 2.0.0.22 (X11/20090609)

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
address@hidden
http://lists.gnu.org/mailman/listinfo/bug-gsl





reply via email to

[Prev in Thread] Current Thread [Next in Thread]