Linear Regression and Hat Matrix

• To: mathgroup at smc.vnet.net
• Subject: [mg44589] Linear Regression and Hat Matrix
• From: kowald at molgen.mpg.de (Axel Kowald)
• Date: Mon, 17 Nov 2003 03:38:20 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Hi everybody,

I'm doing some linear regression and am a bit confused by Mathematicas
output. I do:
<<Statistics`LinearRegression`
data = {{1, 0.1}, {2, 0.2}, {3, 0.3}, {4, 0.4}, {5, 0.5},
{6,0.6}, {7, 0.7}, {8, 0.8}, {9, 0.3}};
Regress[data, {1, x}, x, RegressionReport -> {HatDiagonal}]

and get the HatDiagonal:
{HatDiagonal -> {0.377778,
0.261111, 0.177778, 0.127778, 0.111111, 0.127778, 0.177778,
0.261111, \
0.377778}}

That's fine. But if I try to construct the Hat Matrix by hand I get
something completely different. The hat matrix is defined as: X(X^T
X)^-1 X^T, so I do:

hat = data.Inverse[Transpose[data].data].Transpose[data]

However, the diagonal elements of the resulting matrix are completely
different.

{0.00490196, 0.0196078, 0.0441176, 0.0784314, 0.122549, 0.176471,
0.240196, \
0.313725, 1.}

What am I doing wrong?

Many thanks,

Axel Kowald

```

• Prev by Date: Re: Something wrong with this integral (see text)
• Next by Date: [Fwd: Re: Trigonometric math functions]
• Previous by thread: Problem with linear independence
• Next by thread: Re: Linear Regression and Hat Matrix