Re: Difference Fit vs. Correlation
- To: mathgroup at smc.vnet.net
- Subject: [mg96815] Re: Difference Fit vs. Correlation
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 25 Feb 2009 04:06:41 -0500 (EST)
On 2/24/09 at 5:48 AM, clausenator at gmail.com (Claus) wrote: >Hi, in the code below, using Correlation I get 0.501338, using Fit I >get 0.514093. How come? <snip> >In[60]:= lm = LinearModelFit[GaltonDat, {1, x}, x] >In[62]:= lm["BestFit"] >Out[62]= 33.8866 + 0.514093 x >In[63]:= r2 = Correlation[GaltonX, GaltonY] >Out[63]= 0.501338 You seem to expect the slope of the best fit line to have the same value as the correlation between x and y. These are two separate things and will never have the same value with real data. The slope of the best fit line is given by Covariance[x,y]/Variance[y] The correlation between x and y (Pearson's correlation) is given by Covariance[x,y]/Sqrt[ Variance[x] Variance[y] ] The only case where the slope and correlation have the same value is the trivial case where x = y and there is no error term, i.e., perfect correlation with a slope of 1.