MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Linear Regression and Hat Matrix


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


  • Prev by Date: Re: use of SetDelayed functions in Plot and Solve
  • Next by Date: Re: filled plot on part of x-interval
  • Previous by thread: Re: Linear Regression and Hat Matrix
  • Next by thread: [Fwd: Re: Trigonometric math functions]