if (FALSE) {
## tensor product `tecxcv' example
## simulating data...
require(scam)
simu <- function(x,z) {2*x^2 - 4*z^2 }
xs <- zs <- seq(-1,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(5)
n <- 500
x <- 2*runif(n)-1
z <- 2*runif(n)-1
f <- simu(x,z)
y <- f + rnorm(n)*.1
## fit model ...
b <- scam(y~s(x,z,k=c(10,10),bs="tecxcv"),optimizer=c("efs","bfgs"))
summary(b)
old.par <- par(mfrow=c(2,2),mar=c(4,4,2,2))
plot(b,se=TRUE)
plot(b,pers=TRUE,theta = 30, phi = 40);title("tecxcv")
plot(y,b$fitted.values,xlab="Simulated data",ylab="Fitted data",pch=".",cex=3)
persp(xs,zs,truth,theta = 30, phi = 40);title("truth")
par(old.par)
vis.scam(b,theta = 30, phi = 40)
}
Run the code above in your browser using DataLab