Re: [R] pearson's correlation

From: Claus Wilke <>
Date: Sat, 05 Apr 2008 16:04:39 -0500

> I used the function cor to calculate the pearson correlation coefficient
> between variables. However, the resulting values do not correspond to the
> outcome of my excel-calculations, for which I used the formula
> Cor(x,y)=Cov(x,y)/(SD(x)*SD(y)) So my question is: How does the function
> "cor" compute the pearson correlation coefficient?
It would help if you specified exactly what you enter in R and what R's output is. In any case, in R the correlation coefficient (using the Person method) corresponds exactly to the formula you give, as a quick test shows:
> x=rnorm(100)
> y=rnorm(100)+x
> cov(x,y)/(sd(x)*sd(y))
[1] 0.7561354
> cor(x,y)
[1] 0.7561354

If Excel gives you something else, I'd rather doubt Excel than R.


Claus Wilke
Section of Integrative Biology 
 and Center for Computational Biology and Bioinformatics 
University of Texas at Austin
1 University Station C0930
Austin, TX 78712
512 471 6028

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 05 Apr 2008 - 21:13:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Apr 2008 - 22:30:26 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive