ceplot {condvis} | R Documentation |
Interactive conditional expectation plot
Description
Creates an interactive conditional expectation plot, which consists of two main parts. One part is a single plot depicting a section through a fitted model surface, or conditional expectation. The other part shows small data summaries which give the current condition, which can be altered by clicking with the mouse.
Usage
ceplot(data, model, response = NULL, sectionvars = NULL,
conditionvars = NULL, threshold = NULL, lambda = NULL,
distance = c("euclidean", "maxnorm"), type = c("default", "separate",
"shiny"), view3d = FALSE, Corder = "default", selectortype = "minimal",
conf = FALSE, probs = FALSE, col = "black", pch = NULL,
residuals = FALSE, xsplotpar = NULL, modelpar = NULL,
xcplotpar = NULL)
Arguments
data |
A dataframe containing the data to plot |
model |
A model object, or list of model objects |
response |
Character name of response in |
sectionvars |
Character name of variable(s) from |
conditionvars |
Character names of conditioning variables from
|
threshold |
This is a threshold distance. Points further than
|
lambda |
A constant to multiply by number of factor mismatches in
constructing a general dissimilarity measure. If left |
distance |
A character vector describing the type of distance measure to
use, either |
type |
This specifies the type of interactive plot. |
view3d |
Logical; if |
Corder |
Character name for method of ordering conditioning variables.
See |
selectortype |
Type of condition selector plots to use. Must be
|
conf |
Logical; if |
probs |
Logical; if |
col |
Colour for observed data. |
pch |
Plot symbols for observed data. |
residuals |
Logical; if |
xsplotpar |
Plotting parameters for section visualisation as a list,
passed to |
modelpar |
Plotting parameters for models as a list, passed to
|
xcplotpar |
Plotting parameters for condition selector plots as a list,
passed to |
References
O'Connell M, Hurley CB and Domijan K (2017). “Conditional Visualization for Statistical Models: An Introduction to the condvis Package in R.”Journal of Statistical Software, 81(5), pp. 1-20. <URL:http://dx.doi.org/10.18637/jss.v081.i05>.
See Also
Examples
## Not run:
## Example 1: Multivariate regression, xs one continuous predictor
mtcars$cyl <- as.factor(mtcars$cyl)
library(mgcv)
model1 <- list(
quadratic = lm(mpg ~ cyl + hp + wt + I(wt^2), data = mtcars),
additive = mgcv::gam(mpg ~ cyl + hp + s(wt), data = mtcars))
conditionvars1 <- list(c("cyl", "hp"))
ceplot(data = mtcars, model = model1, response = "mpg", sectionvars = "wt",
conditionvars = conditionvars1, threshold = 0.3, conf = T)
## Example 2: Binary classification, xs one categorical predictor
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$am <- as.factor(mtcars$am)
library(e1071)
model2 <- list(
svm = svm(am ~ mpg + wt + cyl, data = mtcars, family = "binomial"),
glm = glm(am ~ mpg + wt + cyl, data = mtcars, family = "binomial"))
ceplot(data = mtcars, model = model2, sectionvars = "wt", threshold = 1,
type = "shiny")
## Example 3: Multivariate regression, xs both continuous
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$gear <- as.factor(mtcars$gear)
library(e1071)
model3 <- list(svm(mpg ~ wt + qsec + cyl + hp + gear,
data = mtcars, family = "binomial"))
conditionvars3 <- list(c("cyl","gear"), "hp")
ceplot(data = mtcars, model = model3, sectionvars = c("wt", "qsec"),
threshold = 1, conditionvars = conditionvars3)
ceplot(data = mtcars, model = model3, sectionvars = c("wt", "qsec"),
threshold = 1, type = "separate", view3d = T)
## Example 4: Multi-class classification, xs both categorical
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$vs <- as.factor(mtcars$vs)
mtcars$am <- as.factor(mtcars$am)
mtcars$gear <- as.factor(mtcars$gear)
mtcars$carb <- as.factor(mtcars$carb)
library(e1071)
model4 <- list(svm(carb ~ ., data = mtcars, family = "binomial"))
ceplot(data = mtcars, model = model4, sectionvars = c("cyl", "gear"),
threshold = 3)
## Example 5: Multi-class classification, xs both continuous
data(wine)
wine$Class <- as.factor(wine$Class)
library(e1071)
model5 <- list(svm(Class ~ ., data = wine, probability = TRUE))
ceplot(data = wine, model = model5, sectionvars = c("Hue", "Flavanoids"),
threshold = 3, probs = TRUE)
ceplot(data = wine, model = model5, sectionvars = c("Hue", "Flavanoids"),
threshold = 3, type = "separate")
ceplot(data = wine, model = model5, sectionvars = c("Hue", "Flavanoids"),
threshold = 3, type = "separate", selectortype = "pcp")
## Example 6: Multi-class classification, xs with one categorical predictor,
## and one continuous predictor.
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$carb <- as.factor(mtcars$carb)
library(e1071)
model6 <- list(svm(cyl ~ carb + wt + hp, data = mtcars, family = "binomial"))
ceplot(data = mtcars, model = model6, threshold = 1, sectionvars = c("carb",
"wt"), conditionvars = "hp")
## End(Not run)