Skip to content

partial residuals in plot.gam()

2 messages · Henric Nilsson, Simon Wood

#
All,

Sorry for bombarding you with GAM related questions, but...

I know a partial residual option in plot.gam() is on Simon Wood's todo 
list, but since I'm in the midst of a project and not yet having acquired 
sufficient R knowledge to code something usable myself I'll have to put my 
trust in you. Anybody got some code lying around for doing this? Or if 
someone can supply me with enough hints for doing it myself, I'd be most 
grateful.

Thanks,
Henric
#
- sorry partial residuals still no done, but here's a `do-it-yourself' 
example....

# set up a simulated example....
n<-400;sig2<-4
x0 <- runif(n, 0, 1);x1 <- runif(n, 0, 1)
x2 <- runif(n, 0, 1);x3 <- runif(n, 0, 1)
pi <- asin(1) * 2
f <- 2 * sin(pi * x0)
f <- f + exp(2 * x1) - 3.75887
f <- f + 0.2 * x2^11 * (10 * (1 - x2))^6 + 10 * (10 * x2)^3 * 
     (1 -x2)^10 - 1.396
e <- rnorm(n, 0, sqrt(abs(sig2)))
y <- f + e

# fit GAM....
b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3))
# produce a plot just for second term
plot(b,select=2)
# and add partial residuals...
d<-predict(b,type="terms")
points(x1,b$residuals+d[3,],col=2)


Thanks also for the previous suggestions - I'll add them to the list, but
I doubt any will be in version 0.9, which is a bit too near to
completion now. 

Simon

_____________________________________________________________________