The documentation omits to mention the stride parameter, but looking at the meaning of 'stride' in MatLab, I am guessing that it allows you to use say every third element of data by setting a stride of 3.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was not offering a solution, just an explanation of what stride might possibly mean.
I am no mathematician, I only have the vaguest notion of what a covariance is, much less how it is calculated. The PDF version of the manual makes more sense that web versions since the mathematical notation is rendered conventionally rather than the weird ASCII notation ( http://people.scs.fsu.edu/~burkardt/pdf/gsl.pdf ). Anyway, now I have seen how it is calculated, I can see how the answer is 1.0, so I can only assume that your understanding of what the function does is incorrect.
Hi,
I want to know why the code below gives the wrong result.
code:
Out:
The covariance is 0.66666 and not 1, anyone can help me?
anyone know what is stride1 and stride2?
double gsl_stats_covariance (const double data1[], const size_t stride1, const double data2[], const size_t stride2, const size_t n)
tks
The documentation omits to mention the stride parameter, but looking at the meaning of 'stride' in MatLab, I am guessing that it allows you to use say every third element of data by setting a stride of 3.
It doesn't work:
Out:
Covariance: -0.16667
tks...
I was not offering a solution, just an explanation of what stride might possibly mean.
I am no mathematician, I only have the vaguest notion of what a covariance is, much less how it is calculated. The PDF version of the manual makes more sense that web versions since the mathematical notation is rendered conventionally rather than the weird ASCII notation ( http://people.scs.fsu.edu/~burkardt/pdf/gsl.pdf ). Anyway, now I have seen how it is calculated, I can see how the answer is 1.0, so I can only assume that your understanding of what the function does is incorrect.
mean_t = 2
mean_g = 2
n = 3
cov = (1/(n-1)) * sum[i=1..n]{ (t[i] - mean_t) * (g[i] - mean_g) }
i = 1: (1-2)(1-2) = 1
i = 2: (2-2)(2-2) = 0
i = 3: (3-2)*(3-2) = 1
sum 2
cov = 1/2 * 2 = 1
Clifford
... I am guessing perhaps you has 1/n rather than 1/(n-1)