# [R] Deviance explained by individual terms in GAM

garth dboyce at dal.ca
Wed Jul 3 01:29:55 CEST 2013

```Hello,

I am fitting GAMs using mgcv. My models have both linear and functional
effects, for instance:

b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3) + x4 + as.factor(x5),data=dat)

I would like to extract the proportion of deviance explained by a single
term in the model, for instance, s(x1).
Having read through some R help posts I realize that if all terms in the
model are functional (i.e. ‘smooth’) that this is achievable by calculating
the difference in deviance explained between models with s(x1), and without
it, provided that the model parameters in both models are held fixed (i.e.
are identical). For instance, if all model covariates are functional this
would be achieved (according to a post by Simon Wood;
http://r.789695.n4.nabble.com/Re-variance-explained-by-each-predictor-in-GAM-td896222.html#a896223)
with:

dat <- gamSim(1,n=400,dist="normal",scale=2)
b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)
b2<-gam(y~s(x0)+s(x1)+s(x3),sp=b\$sp[-3],data=dat)
summary(b2)\$dev.expl
summary(b)\$dev.expl

This works great, and the “sp=” option in the above code holds the smoothing
parameters fixed. I’m looking to extend this so as to also hold any
non-smooth parameters fixed. Does anyone know how/if this would be possible?

Thanks so much.

--
View this message in context: http://r.789695.n4.nabble.com/Deviance-explained-by-individual-terms-in-GAM-tp4670756.html
Sent from the R help mailing list archive at Nabble.com.

```