data.restore("Data/gam.datasets")
postscript("Plots/plot-07-01.ps")
attach(diabetes)
fit1 <- lm(log(C.Peptide)~Age+Base.Deficit)
pre <- predict.gam(fit1,type="terms")
par(mfrow=c(1,2))
plot(Age,log(C.Peptide))
o <- order(Age)
lines(Age[o],pre[o,1]+fit1$coef[1])
plot(Base.Deficit,log(C.Peptide))
o <- order(Base.Deficit)
lines(Base.Deficit[o],pre[o,2]+fit1$coef[1])
dev.off()

postscript("Plots/plot-07-02.ps")
fit1 <- gam(log(C.Peptide)~lo(Age,Base.Deficit,span=.15))
newAge <- seq(min(Age),max(Age),len=40)
newBase <- seq(min(Base.Deficit),max(Base.Deficit),len=40)
newcov <- expand.grid(Age=newAge,Base.Deficit=newBase)
surf <- predict.gam(fit1,newcov)
persp(newAge,newBase,surf,xlab="Age",ylab="Base Deficit",zlab="Predicted")
dev.off()

postscript("Plots/plot-07-03.ps")
fit1 <- gam(log(C.Peptide)~lo(Age,Base.Deficit,span=.66))
newAge <- seq(min(Age),max(Age),len=40)
newBase <- seq(min(Base.Deficit),max(Base.Deficit),len=40)
newcov <- expand.grid(Age=newAge,Base.Deficit=newBase)
surf <- predict.gam(fit1,newcov)
persp(newAge,newBase,surf,xlab="Age",ylab="Base Deficit",zlab="Predicted")
dev.off()


postscript("Plots/plot-07-04.ps")
par(mfrow=c(1,2))
fit1 <- gam(log(C.Peptide)~lo(Age,Base.Deficit,span=.66))
newAge <- seq(min(Age),max(Age),len=40)
newBase <- seq(min(Base.Deficit),max(Base.Deficit),len=40)
newcov <- expand.grid(Age=newAge,Base.Deficit=newBase)
surf <- predict.gam(fit1,newcov)
persp(newAge,newBase,surf,xlab="Age",ylab="Base Deficit",zlab="Predicted")
fit1 <- gam(log(C.Peptide)~lo(Age,span=.81)+lo(Base.Deficit,span=.81))
newAge <- seq(min(Age),max(Age),len=40)
newBase <- seq(min(Base.Deficit),max(Base.Deficit),len=40)
newcov <- expand.grid(Age=newAge,Base.Deficit=newBase)
surf <- predict.gam(fit1,newcov)
persp(newAge,newBase,surf,xlab="Age",ylab="Base Deficit",zlab="Predicted")
dev.off()


postscript("Plots/plot-07-05.ps")
fit1 <- gam(log(C.Peptide)~lo(Age,span=.81)+lo(Base.Deficit,span=.81))
pre <- predict.gam(fit1,type="terms")
par(mfrow=c(1,2))
plot(Age,log(C.Peptide))
o <- order(Age)
lines(Age[o],pre[o,1]+fit1$coef[1])
plot(Base.Deficit,log(C.Peptide))
o <- order(Base.Deficit)
lines(Base.Deficit[o],pre[o,2]+fit1$coef[1])
dev.off()

