Re: Linear Regression and Hat Matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg44610] Re: Linear Regression and Hat Matrix
- From: Antti Penttilä@smc.vnet.net
- Date: Tue, 18 Nov 2003 06:41:39 -0500 (EST)
- Organization: University of Helsinki
- References: <bpa1m8$19f$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Axel Kowald wrote: > 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] Your formula is right, but the matrix 'data' is not the desing matrix of this model. The design matrix is a matrix with all the explaining variables as colums, and with intercept term included in the model, your design or X-matrix is now: 1 1 1 2 1 3 1 4 X = 1 5 1 6 1 7 1 8 1 9 -- Antti Penttilä Antti.I.Penttila at helsinki.removethis.fi