Skip to content
Prev 33014 / 398506 Next

partial residuals in plot.gam()

- 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

_____________________________________________________________________