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))
[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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive