[R] variance explained by each term in a GAM
Pierre Kleiber
pkleiber.hi at gmail.com
Fri Mar 11 02:49:11 CET 2011
Picking up an ancient thread (from Oct 2007), I have a somewhat more complex
problem than given in Simon Wood's example below. My full model has more than
two smooths as well as factor variables as in this simplified example:
b <- gam(y~fv1+s(x1)+s(x2)+s(x3))
Judging from Simon's example, my guess is to fit reduced models to get
components of deviance as follows:
b1 <- gam(y~s(x1)+s(x2)+s(x3),sp=b$sp)
b2 <- gam(y~fv1+s(x2)+s(x3),sp=b$sp[-1])
b3 <- gam(y~fv1+s(x1)+s(x3),sp=b$sp[-2])
b4 <- gam(y~fv1+s(x1)+s(x2),sp=b$sp[-3])
b0 <- gam(y~1)
And then proceed as in Simon's example, i.e.
(deviance(b1)-deviance(b))/deviance(b0) ## prop explained by fv1
(deviance(b2)-deviance(b))/deviance(b0) ## prop explained by x1
etc.
Am I more or less on the right track?
Thanks, Pierre
On Tue Oct 9 20:25:24 CEST 2007, Simon Wood wrote:
> I think that your approach is reasonable, except that you should use the same
> smoothing parameters throughout. i.e the reduced models should use the same
> smoothing parameters as the full model. Otherwise you get in trouble if x1
> and x2 are correlated, since the smoothing parameters will then tend to
> change alot when terms are dropped as one smooth tries to `do the work' of
> the other. Here's an example, (which is modifiable to illustrate the problem
> with not fixing the sp's)
>
> ## simulate some data
> set.seed(0)
> n<-400
> x1 <- runif(n, 0, 1)
> ## to see problem with not fixing smoothing parameters
> ## remove the `##' from the next line, and the `sp'
> ## arguments from the `gam' calls generating b1 and b2.
> x2 <- runif(n, 0, 1) ## *.1 + x1
> f1 <- function(x) exp(2 * x)
> f2 <- function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10
> f <- f1(x1) + f2(x2)
> e <- rnorm(n, 0, 2)
> y <- f + e
> ## fit full and reduced models...
> b <- gam(y~s(x1)+s(x2))
> b1 <- gam(y~s(x1),sp=b$sp[1])
> b2 <- gam(y~s(x2),sp=b$sp[2])
> b0 <- gam(y~1)
> ## calculate proportions deviance explained...
> (deviance(b1)-deviance(b))/deviance(b0) ## prop explained by s(x2)
> (deviance(b2)-deviance(b))/deviance(b0) ## prop explained by s(x1)
>
>
>
>
>
> On Monday 08 October 2007 20:19, Julian M Burgos wrote:
>> Hello fellow R's,
>>
>> I do apologize if this is a basic question. I'm doing some GAMs using the
>> mgcv package, and I am wondering what is the most appropriate way to
>> determine how much of the variability in the dependent variable is
>> explained by each term in the model. The information provided by
>> summary.gam() relates to the significance of each term (F, p-value) and to
>> the "wiggliness" of the fitted smooth (edf), but (as far as I understand)
>> there is no information on the proportion of variance explained.
>>
>> One alternative may be to fit alternative models without each term, and
>> calculate the reduction in deviance. For example:
>>
>> m1=gam(y~s(x1) + s(x2)) # Full model
>> m2=gam(y~s(x2))
>> m3=gam(y~s(x1))
>>
>> ddev1=deviance(m1)-deviance(m2)
>> ddev2=deviance(m1)-deviance(m3)
>>
>> Here, ddev1 would measure the relative proportion of the variability in y
>> explained by x1, and ddev2 would do the same for x2. Does this sound like
>> an appropriate approach?
>>
>> Julian
>>
>> Julian Burgos
>> FAR lab
>> University of Washington
>>
>> ______________________________________________
>> 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.
>
--
---------------------------------------------------------------------
Pierre Kleiber, Ph.D Email: pierre.kleiber at noaa.gov
Pacific Island Fisheries Science Center Tel. wk: 808 983-5399
NOAA Fisheries hm: 808 737-7544
2570 Dole St., Honolulu, HI 96822-2396
---------------------------------------------------------------------
"♫ It's a long long way from Amphioxus, but we all come from there ♫"
--- Philip H. Pope
More information about the R-help
mailing list