Re: corr & corrcoef



Yes, we are talking about the diagonal of the Pvalue ...

Let me try:

x = rand(10,2);
[r,p] = corrcoef(x)
r =
1.0000 0.2682
0.2682 1.0000
p =
1.0000 0.4537
0.4537 1.0000
[r,p] = corr(x)
r =
1.0000 0.2682
0.2682 1.0000
p =
0 0.4537
0.4537 0

Both corr and corrcoef produce the same correlation between the x columns
(0.2682) and the same p-value for it (0.4537).

It generally doesn't make sense to test whether a variable is correlated
with itself. So corrcoef gives 1 along the diagonal of the correlation
matrix, but gives 1 as its p-value. That way if you search for significant
correlations, you'll never flag the diagonal as significant.

The corr function is a little more general and can compute correlations
between pairs of columns from two different inputs. In that case the result
won't necessarily be square, it won't necessarily have 1's along the
diagonal, and a correlation of 1 is highly significant. So it gives the
p-value as 0 when the correlation is 1. But still, if you compute a
correlation matrix for a single input, the entries along the diagonal are
necessarily 1 and the p-value is not meaningful.

So it's perhaps unfortunate that these two functions have adopted different
conventions for what to put along the diagonal for the matrix of p-values
when there's a single input matrix, but you don't want to use those diagonal
values anyway.

-- Tom


.



Relevant Pages

  • Re: corr & corrcoef
    ... think it should test the probability of not being correlate, both with the corr and with corrcoef function; so I'm expecting 0 both for the function corr and corrcoef; instead th function corrcoef has as output 1. ... Since the two function seems to calculate the same thing (pearson correlation index, and in fact the correlation index are the same), so there must be a difference in the test, since the resulting pValue are different. ...
    (comp.soft-sys.matlab)
  • Re: corr & corrcoef
    ... we are talking about the diagonal of the Pvalue: ... so I'm expecting 0 both for the function corr and corrcoef; ... (pearson correlation index, ...
    (comp.soft-sys.matlab)
  • What does it MEAN?
    ... Pearson Product Moment Correlation - Ungrouped Data ... p-value = 0.0249951301761135 ...
    (sci.stat.math)
  • Re: What does it MEAN?
    ... Pearson Product Moment Correlation - Ungrouped Data ... The way the P-value is ...
    (sci.stat.math)
  • Re: p-values for partial correlation
    ... > suppose I have computed a correlation between X and Y and I have ... When the sample size is large, the null distribution of a Spearman r ... is close to that of a Pearson r, and a p-value can be obtained by ... Spearman r as if it were a partial Pearson r: ...
    (sci.math)