
Plot ICE of MID Model with ggplot2 Package
Source:R/ggmid_mid_conditional.R
ggmid.mid.conditional.Rd
For "mid.conditional" objects, ggmid()
visualizes ICE curves of a MID model.
Usage
# 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, ...)
Arguments
- object
a "mid.conditional" object to be visualized.
- type
a character string specifying the type of the plot. One of "iceplot" or "centered". If "centered", the ICE values of each observation are set to zero at the leftmost point of the varriable.
- theme
a character string specifying the color theme or any item that can be used to define "color.theme" object.
- term
an optional character string specifying an interaction term. If passed, the ICE curve for the specified term is plotted.
- var.alpha
a name of the variable or an expression to be used to set
alpha
.- var.color
a name of the variable or an expression to be used to set
colour
.- var.linetype
a name of the variable or an expression to be used to set
linetype
.- var.linewidth
a name of the variable or an expression to be used to set
linewidth
.- reference
an integer specifying the index of the sample points to be used as reference point for the centered ICE plot. Default is
1
. If negative, the maximum value of the variable is used.- dots
logical. If
TRUE
, the points representing the predictions for each observation are plotted.- sample
an optional vector specifying the names of observations to be plotted.
- ...
optional parameters to be passed to the main layer.
Details
The S3 method of ggmid()
for "mid.conditional" objects creates a "ggplot" object that visualizes ICE curves of a fitted MID model using geom_line()
.
Examples
data(airquality, package = "datasets")
library(midr)
mid <- interpret(Ozone ~ .^2, airquality, lambda = 0.1)
#> 'model' not passed: response variable in 'data' is used
ice <- mid.conditional(mid, "Temp", data = airquality)
ggmid(ice, var.color = "Wind")
ggmid(ice, type = "centered", theme = "Purple-Yellow",
var.color = factor(Month), var.linetype = Wind > 10)