[R-sig-eco] gam plotting (package: mgcv)
Gavin Simpson
gavin.simpson at ucl.ac.uk
Mon Jul 25 12:40:38 CEST 2011
On Mon, 2011-07-25 at 12:14 +0200, Marc Taylor wrote:
> Dear r-sig-ecology list users,
>
> I have been using the mgcv package for fitting a GAM model to a large set of
> spatial/temporal data with several predictors. Each variable contains >
> 1,000,000 values...
> I have been able to successfully fit a model using the bam() function for
> large data sets. It takes a while but the results seem to be favorable. My
> setup looks something like this:
>
> require(mgcv)
> bs="cr";k=10
> res <- bam(CHLA ~ s(SSS, bs = bs, k = k) + s(SST, bs = bs, k = k) +
> s(SIarea,
> bs = bs, k = k) + s(ZOOC, bs = bs, k = k) + s(DIN, bs = bs,
> k = k) + s(DSI, bs = bs, k = k) + s(DFE, bs = bs, k = k), data=DB)
>
> I was hoping someone might be able to suggest a way to extract the values of
> plot.gam (smooth function and standard error). My reason for wanting to do
> this is to be able to create a single graphic of several different gam fits
> at a later time. The "res" object above becomes very large, and I would like
> to avoid saving the entire object.
I think you are going to have to keep `res` around. However, you don't
want to extract things from the object to produce plots (plotting 1M
observations is not going to be quick or pretty in R). It has to be
created anyway, so storing it for a while while you use it isn't a
problem.
Instead, `predict()` from the fitted model for say 100-200 observations
over the range of each covariate. Use `type = "terms"` to get back the
individual contributions of the smooth terms to the fitted/predicted
values. using `se.fit = TRUE` will also return standard errors on those
terms, which you can use to build approximate 95% confidence intervals.
HTH
G
> Many thanks for your help.
>
> Cheers,
> Marc
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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-sig-ecology
mailing list