Learn R Programming

DiceView (version 2.2-0)

contourview.function: Plot a contour view of a prediction model or function, including design points if available.

Description

Plot a contour view of a prediction model or function, including design points if available.

Usage

# S3 method for `function`
contourview(
  fun,
  vectorized = FALSE,
  dim = NULL,
  center = NULL,
  axis = NULL,
  npoints = 20,
  nlevels = 10,
  col_surf = "blue",
  filled = FALSE,
  mfrow = NULL,
  Xlab = NULL,
  ylab = NULL,
  Xlim = NULL,
  title = NULL,
  add = FALSE,
  ...
)

# S3 method for matrix contourview( X, y, sdy = NULL, center = NULL, axis = NULL, col_points = "red", bg_blend = 1, mfrow = NULL, Xlab = NULL, ylab = NULL, Xlim = NULL, title = NULL, add = FALSE, ... )

# S3 method for km contourview( km_model, type = "UK", center = NULL, axis = NULL, npoints = 20, nlevels = 10, col_points = "red", col_surf = "blue", filled = FALSE, bg_blend = 1, mfrow = NULL, Xlab = NULL, ylab = NULL, Xlim = NULL, title = NULL, add = FALSE, ... )

# S3 method for Kriging contourview( Kriging_model, center = NULL, axis = NULL, npoints = 20, nlevels = 10, col_points = "red", col_surf = "blue", filled = FALSE, bg_blend = 1, mfrow = NULL, Xlab = NULL, ylab = NULL, Xlim = NULL, title = NULL, add = FALSE, ... )

# S3 method for NuggetKriging contourview( NuggetKriging_model, center = NULL, axis = NULL, npoints = 20, nlevels = 10, col_points = "red", col_surf = "blue", filled = FALSE, bg_blend = 1, mfrow = NULL, Xlab = NULL, ylab = NULL, Xlim = NULL, title = NULL, add = FALSE, ... )

# S3 method for NoiseKriging contourview( NoiseKriging_model, center = NULL, axis = NULL, npoints = 20, nlevels = 10, col_points = "red", col_surf = "blue", filled = FALSE, bg_blend = 1, mfrow = NULL, Xlab = NULL, ylab = NULL, Xlim = NULL, title = NULL, add = FALSE, ... )

# S3 method for glm contourview( glm_model, center = NULL, axis = NULL, npoints = 20, nlevels = 10, col_points = "red", col_surf = "blue", filled = FALSE, bg_blend = 1, mfrow = NULL, Xlab = NULL, ylab = NULL, Xlim = NULL, title = NULL, add = FALSE, ... )

# S3 method for list contourview( modelFit_model, center = NULL, axis = NULL, npoints = 20, nlevels = 10, col_points = "red", col_surf = "blue", bg_blend = 1, filled = FALSE, mfrow = NULL, Xlab = NULL, ylab = NULL, Xlim = NULL, title = NULL, add = FALSE, ... )

contourview(...)

Arguments

fun

a function or 'predict()'-like function that returns a simple numeric or mean and standard error: list(mean=...,se=...).

vectorized

is fun vectorized?

dim

input variables dimension of the model or function.

center

optional coordinates (as a list or data frame) of the center of the section view if the model's dimension is > 2.

axis

optional matrix of 2-axis combinations to plot, one by row. The value NULL leads to all possible combinations i.e. choose(D, 2).

npoints

an optional number of points to discretize plot of response surface and uncertainties.

nlevels

number of contour levels to display.

col_surf

color for the surface.

filled

use filled.contour

mfrow

an optional list to force par(mfrow = ...) call. The default value NULL is automatically set for compact view.

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 NULL is automatically set to include all design points.

title

an optional overload of main title.

add

to print graphics on an existing window.

...

arguments of the contourview.km, contourview.glm, contourview.Kriging or contourview.function function

X

the matrix of input design.

y

the array of output values.

sdy

optional array of output standard error.

col_points

color of points.

bg_blend

an optional factor of alpha (color channel) blending used to plot design points outside from this section.

km_model

an object of class "km".

type

the kriging type to use for model prediction.

Kriging_model

an object of class "Kriging".

NuggetKriging_model

an object of class "Kriging".

NoiseKriging_model

an object of class "Kriging".

glm_model

an object of class "glm".

modelFit_model

an object returned by DiceEval::modelFit.

Author

Yann Richet, IRSN

Details

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.

See Also

sectionview.function for a section plot, and sectionview3d.function for a 2D section plot. Vectorize.function to wrap as vectorized a non-vectorized function.

sectionview.matrix for a section plot, and sectionview3d.matrix for a 2D 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.

Examples

Run this code
x1 <- rnorm(15)
x2 <- rnorm(15)


y <- x1 + x2 + rnorm(15)
model <- lm(y ~ x1 + x2)

contourview(function(x) sum(x),
                     dim=2, Xlim=cbind(range(x1),range(x2)), col='black')
points(x1,x2)

contourview(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)

contourview(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")

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, dim=2, nlevels=30, 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)
contourview(model, nlevels=30)
contourview(branin, dim=2, nlevels=30, col='red', add=TRUE)
}

## model: Kriging
if (requireNamespace("rlibkriging")) { library(rlibkriging)
model <- Kriging(X = as.matrix(design.fact), y = as.matrix(y), kernel="matern3_2")
contourview(model, nlevels=30)
contourview(branin, dim=2, nlevels=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, nlevels=30)
contourview(branin, dim=2, nlevels=30, col='red', add=TRUE)

if (requireNamespace("DiceEval")) { library(DiceEval)
## model: StepLinear
model <- modelFit(design.fact, y, type = "StepLinear")
contourview(model, nlevels=30)
contourview(branin, dim=2, nlevels=30, col='red', add=TRUE)
}
}

Run the code above in your browser using DataLab