[R] variance explained by each predictor in GAM

Simon Wood s.wood at bath.ac.uk
Mon Jul 13 17:10:53 CEST 2009


You can get some idea by doing something like the following, which compares 
the r^2 for models b and b2, i.e. with and without s(x2).  It keeps the 
smoothing parameters fixed for the comparison. (s(x,fx=TRUE) removes 
penalization altogether btw, which is not what was wanted). 

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


On Monday 13 July 2009 15:09, Kayce Anderson wrote:
> Many thanks for the advice David. I would really like to figure out,
> though, how to get the contribution of each factor to the Rsq - something
> like a Beta coefficient for GAM.   Ideas?
> KC
>
> On Sun, Jul 12, 2009 at 5:41 PM, David Winsemius 
<dwinsemius at comcast.net>wrote:
> > On Jul 12, 2009, at 5:06 PM, Kayce Anderson wrote:
> >
> >  Hi,
> >
> >> I am using mgcv:gam and have developed a model with 5 smoothed
> >> predictors and one factor.
> >>
> >> gam1 <- gam(log.sp~ s(Spr.precip,bs="ts")  + s(Win.precip,bs="ts") + s(
> >> Spr.Tmin,bs="ts")  + s(P.sum.Tmin,bs="ts") + s( Win.Tmax,bs="ts")
> >> +factor(site),data=dat3)
> >>
> >>
> >> The total deviance explained = 70.4%.
> >>
> >>
> >> I would like to extract the variance explained by each predictor.  Is
> >> there
> >> a straightforward way to do this?  I have tried dropping a term and
> >> recalculating the model, but the edf's change if there is any
> >> correlation among variables, thereby making all of the relationships
> >> different.  I haven't yet figured out how to fix the smoothing terms- I
> >> get syntax error messages.  Among other variations, I tried, for
> >> example,
> >> log.sp~s(Spr.precip, sp=3.9, fx=TRUE) +...
> >
> > ?anova.gam
> >
> > Obviously I cannot test this with your dat3. You get an F-statistic for
> > each s() term by default and you are referred to saummary.gam for further
> > explanation.
> >
> > David Winsemius, MD
> > Heritage Laboratories
> > West Hartford, CT
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283




More information about the R-help mailing list