View source: R/ggmid_mid_conditional.R
ggmid.mid.conditional | R Documentation |
For "mid.conditional" objects, ggmid()
visualizes Individual Conditional Expectation (ICE) curves derived from a fitted MID model.
## S3 method for class 'mid.conditional'
ggmid(
object,
type = c("iceplot", "centered"),
theme = NULL,
term = NULL,
var.alpha = NULL,
var.color = NULL,
var.linetype = NULL,
var.linewidth = NULL,
reference = 1L,
dots = TRUE,
sample = NULL,
...
)
## S3 method for class 'mid.conditional'
autoplot(object, ...)
object |
a "mid.conditional" object to be visualized. |
type |
the plotting style. One of "iceplot" or "centered". |
theme |
a character string or object defining the color theme. See |
term |
an optional character string specifying an interaction term. If passed, the ICE curve for the specified term is plotted. |
var.alpha |
a variable name or expression to map to the alpha aesthetic. |
var.color |
a variable name or expression to map to the color aesthetic. |
var.linetype |
a variable name or expression to map to the linetype aesthetic. |
var.linewidth |
a variable name or expression to map to the linewidth aesthetic. |
reference |
an integer specifying the index of the sample points to use as the reference for centering the c-ICE plot. |
dots |
logical. If |
sample |
an optional vector specifying the names of observations to be plotted. |
... |
optional parameters passed on to the main layer. |
This is an S3 method for the ggmid()
generic that produces ICE curves from a "mid.conditional" object.
ICE plots are a model-agnostic tool for visualizing how a model's prediction for a single observation changes as one feature varies.
This function plots one line for each observation in the data.
The type
argument controls the visualization style:
The default, type = "iceplot"
, plots the raw ICE curves.
The type = "centered"
option creates the centered ICE (c-ICE) plot, where each curve is shifted to start at zero, making it easier to compare the slopes of the curves.
The var.color
, var.alpha
, etc., arguments allow you to map aesthetics to other variables in your data using (possibly) unquoted expressions.
ggmid.mid.conditional()
returns a "ggplot" object.
mid.conditional
, ggmid
, plot.mid.conditional
data(airquality, package = "datasets")
library(midr)
mid <- interpret(Ozone ~ .^2, airquality, lambda = 0.1)
ice <- mid.conditional(mid, "Temp", data = airquality)
# Create an ICE plot, coloring lines by 'Wind'
ggmid(ice, var.color = "Wind")
# Create a centered ICE plot, mapping color and linetype to other variables
ggmid(ice, type = "centered", theme = "Purple-Yellow",
var.color = factor(Month), var.linetype = Wind > 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.