Bonjour, j'ai fais une petite routine qui permet de simuler 2 statistiques (enfin!). Et maintenant je cherche à calculer le coefficient de corrélation de Pearson. Pour cela j'ai repris ces lignes de codes :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
#include <math.h>
#define TINY 1.0e-20
 
void pearsn(float x[], float y[], unsigned long n, float *r, float *prob, float *z)
 
{
    float betai(float a, float b, float x);
    float erfcc(float x);
    unsigned long j;
    float yt, xt, t, df;
    float syy=0.0, sxy=0.0, sxx=0.0, ay=0.0, ax=0.0;
 
for (j=1;j<=n;j++)  {
    ax += x[j];
    ay += y[j];
    }
    ax /= n;
    ay /= n;
    for (j=1;j<=n;j++) {
        xt=x[j]-ax;
        yt=y[[j]-ay;
        sxx += xt*xt;
        syy += yt*yt;
        sxy += xt*yt;
    }
    *r=sxy/sqrt(sxx*syy);
    *z=0.5*log((1.0+(*r)+TINY)/(1.0-(*r)+TINY));
    df=n-2;
    t=(*r)*sqrt(df/((1.0-(*r)+TINY)*(1.0+(*r)+TINY)));
    *prob=betai(0.5*df, 0.5, df/(df+t*t));
}
En réalité mon problème est que je ne vois pas comment retourner le résultat de "*r" pour le reprendre plus loin dans mon programme, tout simplement . . .