[R] Hat values for generalized additive models

Simon Wood snw at mcs.st-and.ac.uk
Tue Sep 10 12:11:05 CEST 2002


> Is there a simple way to get the hat values out of a GAM object? 
>
- I'll put out a patch release (0.8-3) which will provide these, soon.
 
> Looking through the code, I couldn't see anywhere where the hat matrix is
> constructed. I tried the appended patch (against mgcv_0.8-1.tar.gz). This
> returns sensible hat values for normal errors, however the hat values using
> Poisson data don't look as good:
- When I try this the hat values look fine to me. As the degree of
smoothing is relaxed in gam(), so that you move away from fitting a glm to
fitting a smooth, then the hat matrix becomes different to the hat matrix
for the glm. In the Poisson example given below, slightly more than 1
degree of freedom is often selected for the smooth, so you'd expect the
hat matrix elements to differ from those of a straight line fit to the
same data (from 0.8-2, you can set the smoothing parameters "by hand" to
examine this).

Simon

  ______________________________________________________________________
> Simon Wood  snw at st-and.ac.uk  http://www.ruwpa.st-and.ac.uk/simon.html
> The Mathematical Institute, North Haugh, St. Andrews, Fife KY16 9SS UK
> Direct telephone: (0)1334 463799          Indirect fax: (0)1334 463748 


> require(mgcv)
> x=seq(0,1,length=1001)
> mu=x
> 
> y=rnorm(1001,mu)
> plot(gam(y~s(x))$hat,hat(glm(y~x)$qr))
> 
> y=rpois(1001,exp(mu))
> plot(gam(y~s(x),family=poisson)$hat,hat(glm(y~x,family=poisson)$qr))


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list