       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:= lm = LinearModelFit[Transpose@{GaltonX, GaltonY}, {1, x}, x]
lm["BestFit"]

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

Out= 33.8866 + 0.514093 x

should be the same if I use the original pairs

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

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

Out= 33.8866 + 0.514093 x

In:= CorrelXY = Correlation[GaltonX, GaltonY]

Out= 0.501338

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

Out= 2.74487

Out= 2.8147

Out= 68.6841

Out= 67.6871

Out= 3.87333

CorrelXY2 should be the same as CorrelXY

In:= CorrelXY2 = CovXY/(SDevX*SDevY)

Out= 0.501338

Slope of the regression line

In:= slopeRegrL = CorrelXY*SDevY/SDevX

Out= 0.514093

In:= interceptRegrL = MY - slopeRegrL*MX

Out= 33.8866

In:= regrLine = interceptRegrL + slopeRegrL*x

Out= 33.8866 + 0.514093 x

Now this is the same as the result from LinearModelFit

In:= lm["BestFit"]

Out= 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