Re: [R] Simulate from a GAM model

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Tue, 01 Jul 2008 22:41:32 +0100

On Tue, 2008-07-01 at 17:12 +0000, Mark Lyman wrote:
> Does anybody have any suggestions on how I might simulate from fitted GAM
> model? I am using the gam function in the mgcv package to fit a variable
> coefficient model like the following from the examples. I would like simulate
> based on the fitted model like the simulate function in the stats package does
> for lm models.
>
> library(mgcv)
> set.seed(10)
> ## simulate date from y = f(x2)*x1 + error
> dat <- gamSim(3,n=400)
> b<-gam(y ~ s(x2,by=x1),data=dat)

How about:

fit <- fitted(b)
sim.sd <- sqrt(deviance(b) / df.residual(b)) simu <- fit + rnorm(length(fit), mean = 0, sd = sim.sd) simu

where simu contains a single simulation from the model.

G

>
>
> Thanks for any help you can give,
> Mark Lyman
>
> ______________________________________________
> 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.



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. Received on Tue 01 Jul 2008 - 21:44:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jul 2008 - 22:31:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive