[R] gam (package gam) - diagonal of smoother matrix

Paulo Barata pbarata at infolink.com.br
Tue Jul 27 02:42:34 CEST 2010


Dear R-list members,

Once a gam (package gam) model has been fitted with family=poisson,
is there some R function that could extract the diagonal elements
of the smoother matrix S, to be used in a cross-validation for the
selection of the best smoothing parameter, following equation 3.19
on page 48 of the book T.J. Hastie and R.J. Tibshirani, Generalized
Additive Models, Chapman and Hall/CRC, 1990 ?

A sample code for fitting the model is:

n <- 100
x <- runif(n,-5,5)
y <- round(25 - x^2 + rpois(n,3), 0)
plot(x,y,xlim=c(-5,5),ylim=c(0,40))
library(gam)
r <- gam(y~lo(x,span=0.5),family=poisson)
pr <- predict(r,type='response')
o <- order(x)
lines(x[o],pr[o])

Thank you very much.

Regards,

Paulo Barata

------------------------------------------------------------------
Paulo Barata
Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation
Rua Leopoldo Bulhoes 1480 - 8A
21041-210  Rio de Janeiro - RJ
Brazil

E-mail: pbarata at infolink.com.br
Alternative e-mail: paulo.barata at ensp.fiocruz.br



More information about the R-help mailing list