Hello R users, I may be thinking about this all wrong. If I am, please let me know.
My question is about bootstrapping gam models. I want to know if there is a way to produce bootstrapped smoothers in a gam model that has more than one significant explanatory term. I know how to achieve this when the model only has one term. The code that I am using to do so is below. It produces a nice graph of y values in response to my explanatory variable (x), along with bootstrapped smoothers in a grey color and the smoother produced by the gam package in black. In my mind this is a very useful graph to help determine the "realness" of the fitted smoother that gam produces. I should note a thanks to Charles Geyer who had code on his STATS 5601 website that has helped me immensely thus far. x <- SI1 ## my explanatory variable y <- NO3.sp3 ## my dependent/response variable model <- gam(y ~ s(x, bs = "cr")) ## I know I can use other smoother types. I am still experimenting with this aspect. plot(x, y) curve(predict(model, newdata = data.frame(x = x)), add = TRUE) n <- length(x) nboot <- 100 for (i in 1:nboot) { k.star <- sample(n, replace = TRUE) x.star <- x[k.star] y.star <- y[k.star] model.star <- gam(y.star ~ s(x.star, bs = "cr")) curve(predict(model.star, data.frame(x.star = x)), add = TRUE, col = "grey") } points(x, y, pch = 16) curve(predict(model, newdata = data.frame(x = x)), add = TRUE, lwd = 2) But now lets say I have a model with two explanatory variables ( x and z) and for the sake of this discussion, both terms are significant (i.e., the data is better explained by having them in the model). The model in this case would be: new.model <- gam(y ~ s(x, bs = "cr")+ s(z, bs = "cr")) I know by using "plot (new.model, resid = T, pch = 16)" I can see the smoothers and 95% CI produced by the gam package with the data values overlayed. Is there a way to produce bootstrapped smoothers for each term from the same model (new.model) so that I can visualize them in the same way as the plot function allows me? I thought of having separate single-term models for each explanatory variable (Y~s(x) and y~s(z)), but doing so is not correct since removing one term from a model causes the parameter values of the other term to change. Any suggestions on the bootstrapping code that would produce such a graphical output would be appreciated, especially since I am new to the bootstrapping coding. I hope that is clear and thanks in advance for any help that anyone can offer. -- Basil Iannone University of Illinois at Chicago Department of Biological Sciences (MC 066) 845 W. Taylor St. Chicago, IL 60607-7060 Email: bian...@uic.edu Phone: 312-355-3231 Fax: 312-413-2435 http://www2.uic.edu/~bianno2 [[alternative HTML version deleted]] _______________________________________________ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology