library(scam)
set.seed(2)
n <- 200
x1 <- runif(n)*6-3
f1 <- 3*exp(-x1^2) # unconstrained term
x2 <- runif(n)*4-1;
f2 <- exp(4*x2)/(1+exp(4*x2)) # monotone increasing smooth
f <- f1+f2
y <- f+rnorm(n)*0.2
dat <- data.frame(x1=x1,x2=x2,y=y)
b <- scam(y~s(x1,k=15,bs="cr",m=2)+s(x2,k=30,bs="mpi",m=2),
family=gaussian(link="identity"),data=dat)
newd <- data.frame(x1=seq(-2.9,2.9,length.out=30),x2=seq(-0.9,2.9,length.out=30))
pred <- predict.scam(b,newd)
pred
predict(b,newd,type="terms",se=TRUE)
plot(b,se=TRUE,residuals=TRUE,pages=1)
Run the code above in your browser using DataLab