# NOT RUN {
rm(list=ls())
# A 2D example
Branin <- function(x1,x2) {
x1 <- x1*15-5
x2 <- x2*15
(x2 - 5/(4*pi^2)*(x1^2) + 5/pi*x1 - 6)^2 + 10*(1 - 1/(8*pi))*cos(x1) + 10
}
# Linear model on 50 points
n <- 50
X <- matrix(runif(n*2),ncol=2,nrow=n)
Y <- Branin(X[,1],X[,2])
modLm <- modelFit(X,Y,type = "Linear",formula=Y~X1+X2+X1:X2+I(X1^2)+I(X2^2))
R2(Y,modLm$model$fitted.values)
crossValidation(modLm,K=10)$Q2
# kriging model : gaussian covariance structure, no trend, no nugget effect
# on 16 points
n <- 16
X <- data.frame(x1=runif(n),x2=runif(n))
Y <- Branin(X[,1],X[,2])
mKm <- modelFit(X,Y,type="Kriging",formula=~1, covtype="powexp")
K <- 10
out <- crossValidation(mKm, K)
par(mfrow=c(2,2))
plot(c(0,1:K),c(mKm$model@covariance@range.val[1],out$theta[,1]),
xlab='',ylab='Theta1')
plot(c(0,1:K),c(mKm$model@covariance@range.val[2],out$theta[,2]),
xlab='',ylab='Theta2')
plot(c(0,1:K),c(mKm$model@covariance@shape.val[1],out$shape[,1]),
xlab='',ylab='p1',ylim=c(0,2))
plot(c(0,1:K),c(mKm$model@covariance@shape.val[2],out$shape[,2]),
xlab='',ylab='p2',ylim=c(0,2))
par(mfrow=c(1,1))
# }
Run the code above in your browser using DataLab