# Re: [R] pearson's correlation

From: Claus Wilke <cwilke_at_mail.utexas.edu>
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))
 0.7561354
> cor(x,y)
 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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help