[R] variance explained by each predictor in GAM

huidongtian tienhuitung at gmail.com
Tue Nov 8 10:22:35 CET 2011


Dear Prof. Wood,
    I read your methods of extracting the variance explained by each
predictor in different places. My question is: using the method you
suggested, the sum of the deviance explained by all terms is not equal to
the deviance explained by the full model. Could you tell me what caused such
problem? 

>  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...
>  dev.1 <- (deviance(b1)-deviance(b))/deviance(b0) ## prop explained by
> s(x2)
>  dev.2 <- (deviance(b2)-deviance(b))/deviance(b0) ## prop explained by
> s(x1)
> 
>  dev.1 + dev.2
[1] 0.6974949
>  summary(b)$dev.expl
[1] 0.7298136

I checked the two models (b1 & b2), found the model coefficients are
different with model b, so I feel it could be the problem.

wish to hear your comments.

Huidong Tian





--
View this message in context: http://r.789695.n4.nabble.com/Re-variance-explained-by-each-predictor-in-GAM-tp896222p4015368.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list