# [R] pearson's correlation

Claus Wilke cwilke at mail.utexas.edu
Sat Apr 5 23:04:39 CEST 2008

```> 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

--
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
cwilke at mail.utexas.edu
512 471 6028

```