x1 <- rnorm(15)
x2 <- rnorm(15)
y <- x1 + x2 + rnorm(15)
DiceView:::open3d(); DiceView:::plot3d(x1,x2,y)
model <- lm(y ~ x1 + x2)
sectionview3d(function(x) sum(x),
dim=2, Xlim=cbind(range(x1),range(x2)), add=TRUE, col='black')
sectionview3d(function(x) {
x = as.data.frame(x)
colnames(x) <- names(model$coefficients[-1])
p = predict.lm(model, newdata=x, se.fit=TRUE)
list(mean=p$fit, se=p$se.fit)
}, vectorized=TRUE, dim=2, Xlim=cbind(range(x1),range(x2)), add=TRUE)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin)
sectionview3d(X, y)
if (requireNamespace("DiceKriging")) { library(DiceKriging)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin)
model <- km(design = X, response = y, covtype="matern3_2")
sectionview3d(model)
}
if (requireNamespace("rlibkriging")) { library(rlibkriging)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin)
model <- Kriging(X = X, y = y, kernel="matern3_2")
sectionview3d(model)
}
if (requireNamespace("rlibkriging")) { library(rlibkriging)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin) + 5*rnorm(15)
model <- NuggetKriging(X = X, y = y, kernel="matern3_2")
sectionview3d(model)
}
if (requireNamespace("rlibkriging")) { library(rlibkriging)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin) + 5*rnorm(15)
model <- NoiseKriging(X = X, y = y, kernel="matern3_2", noise=rep(5^2,15))
sectionview3d(model)
}
x1 <- rnorm(15)
x2 <- rnorm(15)
y <- x1 + x2^2 + rnorm(15)
model <- glm(y ~ x1 + I(x2^2))
sectionview3d(model)
if (requireNamespace("DiceEval")) { library(DiceEval)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin)
model <- modelFit(X, y, type = "StepLinear")
sectionview3d(model)
}
## A 2D example - Branin-Hoo function
sectionview3d(branin, dim=2, col='black')
if (FALSE) {
## a 16-points factorial design, and the corresponding response
d <- 2; n <- 16
design.fact <- expand.grid(seq(0, 1, length = 4), seq(0, 1, length = 4))
design.fact <- data.frame(design.fact); names(design.fact) <- c("x1", "x2")
y <- branin(design.fact); names(y) <- "y"
if (requireNamespace("DiceKriging")) { library(DiceKriging)
## model: km
model <- DiceKriging::km(design = design.fact, response = y)
sectionview3d(model)
sectionview3d(branin, dim=2, col='red', add=TRUE)
}
if (requireNamespace("rlibkriging")) { library(rlibkriging)
## model: Kriging
model <- rlibkriging::Kriging(X = as.matrix(design.fact), y = as.matrix(y), kernel="matern3_2")
sectionview3d(model)
sectionview3d(branin, dim=2, col='red', add=TRUE)
}
## model: glm
model <- glm(y ~ 1+ x1 + x2 + I(x1^2) + I(x2^2) + x1*x2, data=cbind(y,design.fact))
sectionview3d(model)
sectionview3d(branin, dim=2, col='red', add=TRUE)
if (requireNamespace("DiceEval")) { library(DiceEval)
## model: StepLinear
model <- modelFit(design.fact, y, type = "StepLinear")
sectionview3d(model)
sectionview3d(branin, dim=2, col='red', add=TRUE)
}
}
Run the code above in your browser using DataLab