[R] GAMs in R : How to put the new data into the model?

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Sep 29 10:54:26 CEST 2011

On Wed, 2011-09-28 at 02:10 -0700, pigpigmeow wrote:
> For example: 
> GAMs and after stepwise regression:

You probably don't want to be doing stepwise model/feature selection in
any regression model. Marra & Wood (2011, Computational Statistics and
Data Analysis 55; 2372-2387) show results that suggest adding an extra
penalty term during model fitting, that allows terms to be penalised out
of the model, performs well for feature selection in a series of GAM

You can turn this on in mgcv::gam() via the `select` argument by setting
it to `TRUE`.

> cod<-gam(newCO~RH+s(solar,bs="cr")+windspeed+s(transport,bs="cr"),family=gaussian
> (link=log),groupD,methods=REML)
> I used 10 year meterorology data (2000-2010) to form equation of
> concentration of carbon monoxide.
> NOW, I have 2011 meteorology data, I want to use the above GAMs to get the
> predict value of concentration of carbon monoxide.

So put your 2011 data into a data frame with (at the minimum) the column

`RH`, `solar`, `windspeed`, `transport`

If that data frame were called, say, `dat2011` then you provide the
`predict()` method for "gam" objects with both the fitted model **and**
the new data (`dat2011`), e.g.:

pred <- predict(cod, newdata = dat2011)

See ?predict.gam for more details. You are probably going to need type =
"response" so you get values back on the scale of the response not the
the link function.



> How can I put the 2011 data into this gam and get the expected value of
> concentration of Carbon monoxide??
> --
> View this message in context: http://r.789695.n4.nabble.com/GAMs-in-R-How-to-put-the-new-data-into-the-model-tp3849851p3850473.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk

More information about the R-help mailing list