Question

I have some vectors, for example, let´s call them a, b and c. All of them have the same size. I want to get the correlation between a and c, b and c.

I have tried that:

[rho1,pval1]=corr(a,c,'rows','complete')
[rho2,pval2]=corr(b,c,'rows','complete')


rho1=0.1054
pval1=0.2918
rho2=0.1174
pval2=0.2473


And I have thought that the results were OK, but later I have tried that:
[rho,pval]=corr([a b],c,'rows','complete')

And have given me different results:


rho=
0.1168
0.1150

pval=
0.2649
0.2726


Matlab´s help says that these function returns a p1-by-p2 matrix containing the pairwise correlation coefficient between each pair of columns in the n-by-p1 and n-by-p2 matrices X and Y.

What am I doing wrong? Thanks.

Note: The vectors are 289x1, so I can´t write them here.

Was it helpful?

Solution

SOLVED.The problem is that these vector have NaN's so the option 'complete' only takes the rows where there are no NaN's.If a vector (for example b) have a NaN will affect to the results of both correlations (a and b). The option that I need is 'pairwise'. Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top