contourview.function | R Documentation |
Plot a contour view of a prediction model or function, including design points if available.
## S3 method for class ''function''
contourview(
fun,
vectorized = FALSE,
center = NULL,
lty_center = 2,
col_center = "black",
axis = NULL,
npoints = 21,
levels = 10,
lty_levels = 3,
col_levels = if (!is.null(col) & length(col) == 1) col.levels(col, levels - 1) else if
(!is.null(col) & length(col) == 2) cols.levels(col[1], col[2], levels - 1) else
col.levels("blue", levels - 1),
col = NULL,
col_fading_interval = 0.5,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = if (!add) matrix(c(0, 1), 2, 2) else NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
## S3 method for class 'matrix'
contourview(
X,
y,
center = NULL,
lty_center = 2,
col_center = "black",
axis = NULL,
col_points = if (!is.null(col)) col else "red",
col = NULL,
bg_fading = 1,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = if (!add) matrix(c(0, 1), 2, 2) else NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
## S3 method for class 'character'
contourview(eval_str, axis = NULL, mfrow = NULL, ...)
## S3 method for class 'km'
contourview(
km_model,
type = "UK",
center = NULL,
axis = NULL,
npoints = 21,
levels = pretty(km_model@y, 10),
col_points = if (!is.null(col) & length(col) == 1) col else "red",
col_levels = if (!is.null(col) & length(col) == 1) col.levels(col, levels) else if
(!is.null(col) & length(col) == 2) cols.levels(col[1], col[2], levels - 1) else
col.levels("blue", levels),
col = NULL,
conf_level = 0.5,
conf_fading = 0.5,
bg_fading = 1,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
## S3 method for class 'Kriging'
contourview(
Kriging_model,
center = NULL,
axis = NULL,
npoints = 21,
levels = pretty(Kriging_model$y(), 10),
col_points = if (!is.null(col) & length(col) == 1) col else "red",
col_levels = if (!is.null(col) & length(col) == 1) col.levels(col, levels) else if
(!is.null(col) & length(col) == 2) cols.levels(col[1], col[2], levels - 1) else
col.levels("blue", levels),
col = NULL,
conf_level = 0.5,
conf_fading = 0.5,
bg_fading = 1,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
## S3 method for class 'NuggetKriging'
contourview(
NuggetKriging_model,
center = NULL,
axis = NULL,
npoints = 21,
levels = pretty(NuggetKriging_model$y(), 10),
col_points = if (!is.null(col) & length(col) == 1) col else "red",
col_levels = if (!is.null(col) & length(col) == 1) col.levels(col, levels) else if
(!is.null(col) & length(col) == 2) cols.levels(col[1], col[2], levels - 1) else
col.levels("blue", levels),
col = NULL,
conf_level = 0.5,
conf_fading = 0.5,
bg_fading = 1,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
## S3 method for class 'NoiseKriging'
contourview(
NoiseKriging_model,
center = NULL,
axis = NULL,
npoints = 21,
levels = pretty(NoiseKriging_model$y(), 10),
col_points = if (!is.null(col) & length(col) == 1) col else "red",
col_levels = if (!is.null(col) & length(col) == 1) col.levels(col, levels) else if
(!is.null(col) & length(col) == 2) cols.levels(col[1], col[2], levels - 1) else
col.levels("blue", levels),
col = NULL,
conf_level = 0.5,
conf_fading = 0.5,
bg_fading = 1,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
## S3 method for class 'glm'
contourview(
glm_model,
center = NULL,
axis = NULL,
npoints = 21,
levels = pretty(glm_model$fitted.values, 10),
col_points = if (!is.null(col) & length(col) == 1) col else "red",
col_levels = if (!is.null(col) & length(col) == 1) col.levels(col, levels) else if
(!is.null(col) & length(col) == 2) cols.levels(col[1], col[2], levels - 1) else
col.levels("blue", levels),
col = NULL,
conf_level = 0.5,
conf_fading = 0.5,
bg_fading = 1,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
## S3 method for class 'list'
contourview(
modelFit_model,
center = NULL,
axis = NULL,
npoints = 21,
levels = pretty(modelFit_model$data$Y, 10),
col_points = if (!is.null(col) & length(col) == 1) col else "red",
col_levels = if (!is.null(col) & length(col) == 1) col.levels(col, levels) else if
(!is.null(col) & length(col) == 2) cols.levels(col[1], col[2], levels - 1) else
col.levels("blue", levels),
col = NULL,
bg_fading = 1,
mfrow = NULL,
Xlab = NULL,
ylab = NULL,
Xlim = NULL,
ylim = NULL,
title = NULL,
title_sep = " | ",
add = FALSE,
...
)
contourview(...)
fun |
a function or 'predict()'-like function that returns a simple numeric or mean and standard error: list(mean=...,se=...). |
vectorized |
is fun vectorized? |
center |
optional coordinates (as a list or data frame) of the center of the section view if the model's dimension is > 2. |
lty_center |
line type for the section center of the plot (if any). |
col_center |
color for the section center of the plot (if any). |
axis |
optional matrix of 2-axis combinations to plot, one by row. The value |
npoints |
an optional number of points to discretize plot of response surface and uncertainties. |
levels |
(number of) contour levels to display. |
lty_levels |
contour line type. |
col_levels |
color for the surface. |
col |
color of the object (use col_* for specific objects). |
col_fading_interval |
an optional factor of alpha (color channel) fading used to plot function output intervals (if any). |
mfrow |
an optional list to force |
Xlab |
an optional list of string to overload names for X. |
ylab |
an optional string to overload name for y. |
Xlim |
an optional list to force x range for all plots. The default value |
ylim |
an optional list to force y range for all plots. |
title |
an optional overload of main title. |
title_sep |
customize subtitle with fixed input. |
add |
to print graphics on an existing window. |
... |
arguments of the |
X |
the matrix of input design. |
y |
the array of output values (two columns means an interval). |
col_points |
color of points. |
bg_fading |
an optional factor of alpha (color channel) fading used to plot design points outside from this section. |
eval_str |
the expression to evaluate in each subplot. |
km_model |
an object of class |
type |
the kriging type to use for model prediction. |
conf_level |
confidence hulls to display. |
conf_fading |
an optional factor of alpha (color channel) fading used to plot confidence hull. |
Kriging_model |
an object of class |
NuggetKriging_model |
an object of class |
NoiseKriging_model |
an object of class |
glm_model |
an object of class |
modelFit_model |
an object returned by DiceEval::modelFit. |
If available, experimental points are plotted with fading colors. Points that fall in the specified section (if any) have the color specified col_points
while points far away from the center have shaded versions of the same color. The amount of fading is determined using the Euclidean distance between the plotted point and center
.
Yann Richet, IRSN
sectionview.function
for a section plot, and sectionview3d.function
for a 2D section plot.
sectionview.matrix
for a section plot, and sectionview3d.matrix
for a 2D section plot.
contourview.matrix
for a section plot.
sectionview.km
for a section plot, and sectionview3d.km
for a 2D section plot.
sectionview.Kriging
for a section plot, and sectionview3d.Kriging
for a 2D section plot.
sectionview.NuggetKriging
for a section plot, and sectionview3d.NuggetKriging
for a 2D section plot.
sectionview.NoiseKriging
for a section plot, and sectionview3d.NoiseKriging
for a 2D section plot.
sectionview.glm
for a section plot, and sectionview3d.glm
for a 2D section plot.
sectionview.glm
for a section plot, and sectionview3d.glm
for a 2D section plot.
x1 <- rnorm(15)
x2 <- rnorm(15)
y <- x1 + x2 + rnorm(15)
model <- lm(y ~ x1 + x2)
contourview(function(x) sum(x),
Xlim=cbind(range(x1),range(x2)), col='black')
points(x1,x2)
contourview(function(x) {
x = as.data.frame(x)
colnames(x) <- all.vars(model$call)[-1]
predict.lm(model, newdata=x, se.fit=FALSE)
}, vectorized=TRUE, add=TRUE)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin)
contourview(X, y)
x1 <- rnorm(15)
x2 <- rnorm(15)
y <- x1 + x2^2 + rnorm(15)
model <- glm(y ~ x1 + I(x2^2))
contourview(model)
contourview("abline(h=0.25,col='red')")
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")
contourview(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")
contourview(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")
contourview(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))
contourview(model)
}
x1 <- rnorm(15)
x2 <- rnorm(15)
y <- x1 + x2^2 + rnorm(15)
model <- glm(y ~ x1 + I(x2^2))
contourview(model)
if (requireNamespace("DiceEval")) { library(DiceEval)
X = matrix(runif(15*2),ncol=2)
y = apply(X,1,branin)
model <- modelFit(X, y, type = "StepLinear")
contourview(model)
}
## A 2D example - Branin-Hoo function
contourview(branin, levels=30, col='black')
## Not run:
## 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)
contourview(model, levels=30)
contourview(branin, levels=30, col='red', add=TRUE)
}
if (requireNamespace("rlibkriging")) { library(rlibkriging)
## model: Kriging
model <- Kriging(X = as.matrix(design.fact), y = as.matrix(y), kernel="matern3_2")
contourview(model, levels=30)
contourview(branin, levels=30, 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))
contourview(model, levels=30)
contourview(branin, levels=30, col='red', add=TRUE)
if (requireNamespace("DiceEval")) { library(DiceEval)
## model: StepLinear
model <- modelFit(design.fact, y, type = "StepLinear")
contourview(model, levels=30)
contourview(branin, levels=30, col='red', add=TRUE)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.