Re: [R] Correlation discrepancy

2011-08-23 Thread Kohta Ishikawa
Divide by 8 leads biased estimator of covariance. R cov function calculates unbiased estimator(divide by (sample size)-1). Regards, Kohta -- View this message in context: http://r.789695.n4.nabble.com/Correlation-discrepancy-tp3762457p3762491.html Sent from the R help mailing list archive at Nab

Re: [R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
Dear Mr Dimitris and Mr Harding, by mistake I have typed my colleagues name (i.e. Ashok) while thanking you. Please excuse me for that. Regards Vincy --- On Tue, 8/23/11, ted.hard...@wlandres.net wrote: From: ted.hard...@wlandres.net Subject: Re: [R] Correlation discrepancy To: r-help@r

Re: [R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
] Correlation discrepancy To: r-help@r-project.org Cc: "Vincy Pyne" Received: Tuesday, August 23, 2011, 11:38 AM In addition, something has gone wrong, Vincy, with your data x,y between evaluating cov(x,y) and evaluating your explicit formula. If I repeat your commands:   x = c(44,46,46,47,4

Re: [R] Correlation discrepancy

2011-08-23 Thread Ted Harding
In addition, something has gone wrong, Vincy, with your data x,y between evaluating cov(x,y) and evaluating your explicit formula. If I repeat your commands: x = c(44,46,46,47,45,43,45,44) y = c(44,43,41,41,46,48,44,43) cov(x, y) # [1] -2.428571 sum((x-mean(x))*(y-mean(y)))/8 # [1] -

Re: [R] Correlation discrepancy

2011-08-23 Thread Dimitris Rizopoulos
well, you don't have the correct denominator, i.e., n-1, with n denoting the sample size. Have a look at the *Details* section of the online help file for cov(), and try also sum((x-mean(x))*(y-mean(y)))/7 cov(x, y) I hope it helps. Best, Dimitris On 8/23/2011 1:18 PM, Vincy Pyne wrote: D

[R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
Dear R list, I have one very elementary question regrading correlation between two variables. x = c(44,46,46,47,45,43,45,44) y = c(44,43,41,41,46,48,44,43) > cov(x, y) [1] -2.428571 However, if I try to calculate the covariance using the formula as covariance = sum((x-mean(x))*(y-mean(y)))/8