Re: Difference Fit vs. Correlation

• To: mathgroup at smc.vnet.net
• Subject: [mg96866] Re: Difference Fit vs. Correlation
• From: Claus <clausenator at gmail.com>
• Date: Thu, 26 Feb 2009 07:57:35 -0500 (EST)
• Organization: Comp.Center (RUS), U of Stuttgart, FRG
• References: <go0j8u\$n53\$1@smc.vnet.net>

```Gentlemen,
thanks for your comments, I was writing my original post in a hurry, and
I must have been in a hurry when I was writing the original code.
My problem was that I had calculated the slope of the regression line by
multiplying Correlation[GaltonX,GaltonY] with
StandardDeviation[GaltonX]/StandardDeviation[GaltonY]

However, the correct slope of the regression line is
Correlation[GaltonX,GaltonY] *
StandardDeviation[GaltonY]/StandardDeviation[GaltonX]

Below is some code that should clarify things (use GaltonX and GaltonY
from original post).

Thank you,
Claus

In[98]:= lm = LinearModelFit[Transpose@{GaltonX, GaltonY}, {1, x}, x]
lm["BestFit"]

Out[98]= FittedModel[\!\(\*
PanelBox[
TagBox[
RowBox[{"33.88660435407788`", " ", "+",
RowBox[{"0.5140930386233082`", " ", "x"}]}],
Short],
FrameMargins->5]\)]

Out[99]= 33.8866 + 0.514093 x

should be the same if I use the original pairs

In[100]:= lm2 = LinearModelFit[GaltonDat, {1, x}, x]
lm2["BestFit"]

Out[100]= FittedModel[\!\(\*
PanelBox[
TagBox[
RowBox[{"33.88660435407788`", " ", "+",
RowBox[{"0.5140930386233082`", " ", "x"}]}],
Short],
FrameMargins->5]\)]

Out[101]= 33.8866 + 0.514093 x

In[102]:= CorrelXY = Correlation[GaltonX, GaltonY]

Out[102]= 0.501338

In[103]:= SDevX = StandardDeviation[GaltonX]
SDevY = StandardDeviation[GaltonY]
MY = Mean[GaltonY]
MX = Mean[GaltonX]
CovXY = Covariance[GaltonX, GaltonY]

Out[103]= 2.74487

Out[104]= 2.8147

Out[105]= 68.6841

Out[106]= 67.6871

Out[107]= 3.87333

CorrelXY2 should be the same as CorrelXY

In[108]:= CorrelXY2 = CovXY/(SDevX*SDevY)

Out[108]= 0.501338

Slope of the regression line

In[109]:= slopeRegrL = CorrelXY*SDevY/SDevX

Out[109]= 0.514093

In[110]:= interceptRegrL = MY - slopeRegrL*MX

Out[110]= 33.8866

In[111]:= regrLine = interceptRegrL + slopeRegrL*x

Out[111]= 33.8866 + 0.514093 x

Now this is the same as the result from LinearModelFit

In[112]:= lm["BestFit"]

Out[112]= 33.8866 + 0.514093 x

```

• Prev by Date: Re: Eigensystem sometimes returns non-orthonormal
• Next by Date: Re: Manipulating list of functions
• Previous by thread: Re: Difference Fit vs. Correlation
• Next by thread: Re: Difference Fit vs. Correlation