is this gam::gam or mgcv::gam? If the latter, and if I understand what you want, if gam.out contains your GAM model fitted using gam() from mgcv, then:
out.term <- predict(gam.out, type = "terms") gives you the contributions of each covariate on the response for the fitted model. read :?predict.gam for details of what type = "terms" actually returns. Note that you should be wary of accessing the components of model fits directly. Instead, get the various bits using accessor functions, coefs() for $coefficients, fitted() for the fitted values etc. Often the components don't hold exactly what you think but which are processed correctly when accessed by the appropriate accessor function. HTH G On Sat, 2008-08-02 at 18:47 -0700, Andreas Winter wrote: > I would like to request help with the following: > I am trying to use a Generalized Additive Model (gam) to examine the > density distribution of fish as a function of latitude and longitude > as continuous variables, and year as a categorical variable. The model > is written as: > > gam.out <- gam(Density ~ s(Lat) + s(Lon) + as.factor(Year)) > > The fitted model prediction of the link function is gam.out > $linear.predictors. Presumably, gam.out$linear.predictors must be > derived from some combination of the original predictor variables > (Lat, Lon, Year), their corresponding coefficients and the intercept > (gam.out$coefficients), and the smooth outputs gam.out$smooth and/or > gam.out$sp. > > By comparison, for a glm model: > > glm.out <- glm(Density ~ Lat + Lon + as.factor(Year)) > > this is simply: > > glm.out$linear.predictors = glm.out$coefficients(intercept) + glm.out > $coefficients (year) + glm.out$coefficients(lat) x Lat + glm.out > $coefficients(lon) x Lon > > My problem is that I cannot figure out how to get the equivalent from > the gam model. I would like to know how to decompose gam.out > $linear.predictors into its components so that I can evaluate the > effects of the different predictor variables separately. > > I would appreciate any comments that can help me with this. > > Thank you, > > Andreas Winter > Blacksburg, VA > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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@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.