if (FALSE) {
## tensor product `tesmi1' example...
## simulating data...
require(scam)
simu <- function(x,z) exp(4*x)/(1+exp(4*x))+2*sin(pi*z)
xs <- seq(-1,3,length=30); zs <- seq(0,1,length=30)
pr <- data.frame(x=rep(xs,30),z=rep(zs,rep(30,30)))
truth <- matrix(simu(pr$x,pr$z),30,30)
set.seed(24)
n <- 500
x <- runif(n)*4-1
z <- runif(n)
f <- simu(x,z)
y <- f + rnorm(n)*.3
## fit model ...
b <- scam(y~s(x,z,bs="tesmi1",k=c(10,10)))
old.par <- par(mfrow=c(2,2))
persp(xs,zs,truth);title("truth")
vis.scam(b,theta=40,phi=20);title("tesmi1")
plot(b,se=TRUE)
plot(y,b$fitted.values,xlab="Simulated data",ylab="Fitted data")
par(old.par)
## example with cyclic cubic regression spline along the second covariate...
simu2 <- function(x,z)
exp(4*x)/(1+exp(4*x))+sin(2*pi*z)
xs <- seq(-1,3,length=30); zs <- seq(0,1,length=30)
pr <- data.frame(x=rep(xs,30),z=rep(zs,rep(30,30)))
truth2 <- matrix(simu2(pr$x,pr$z),30,30)
set.seed(2)
n <- 500
x <- runif(n)*4-1
z <- runif(n)
f <- simu2(x,z)
y <- f + rnorm(n)*.2
## fit model ...
b1 <- scam(y~s(x,z,bs="tesmi1",xt=list("cc"),k=10))
old.par <- par(mfrow=c(2,2))
plot(b1,se=TRUE)
vis.scam(b1,theta=40,phi=20);title("tesmi1, cyclic")
plot(y,b1$fitted.values,xlab="Simulated data",ylab="Fitted data")
persp(xs,zs,truth2,theta = 30, phi = 40);title("truth")
par(old.par)
}
Run the code above in your browser using DataLab