Plot out model values

mod_plot(model = NULL, formula = NULL, data = NULL, bootstrap = 0,
  nlevels = 3, at = list(), class_level = NULL,
  interval = c("none", "confidence", "prediction"),
  post_transform = NULL, size = 1, alpha = 0.8, ...)

Arguments

model

A model to display graphically. Can also be an ensemble produced with mod_ensemble().

formula

A formula setting the y ~ x + color variables.

data

An optional data frame from which to extract levels for explanatory variables.

bootstrap

The number of bootstrap replications of the model to generate and plot. Use as an alternative to interval for confidence intervals.

nlevels

The number of levels to display for those variables shown at discrete levels.

at

A named list giving specific values at which to hold the variables. You can accomplish this without forming a list by using .... See examples.

class_level

A character string indicating the level of the response variable to use in the plot when the model is produce a probabilty for a classifier. (Default: the first level.)

interval

One of "none", "confidence", "prediction" indicating which type of interval to display.

post_transform

A function providing a scalar transformation and new name for the response variable. Example: post_transform = c(price = exp) to undo a log transformation of price.

size

A numerical value for line width (default: 1)

alpha

A numerical value between 0 and 1 for transparency (default: 0.8)

...

Used to choose specific values for explantory variables. See examples.

Examples

# NOT RUN {
mod1 <- lm(wage ~ age * sex + sector, data = mosaicData::CPS85)
mod_plot(mod1)
mod_plot(mod1, n = Inf, interval = "confidence")
mod_plot(mod1, ~ sector + sex + age) # not necessarily a good ordering
mod_plot(mod1, ~ age + sex + sector, nlevels = 8)
mod2 <- lm(log(wage) ~ age + sex + sector, data = mosaicData::CPS85)
mod_plot(mod2, post_transform = c(wage = exp),
     interval = "confidence") # undo the log in the display
mod3 <- glm(married == "Married" ~ age + sex * sector,
            data = mosaicData::CPS85, family = "binomial")
mod_plot(mod3)
E3 <- mod_ensemble(mod3, 10)
mod_plot(E3)
mod4 <- rpart::rpart(sector ~ age + sex + married, data = mosaicData::CPS85)
mod_plot(mod4)
mod_plot(mod4, class_level = "manag")
mod5 <- randomForest::randomForest(
         sector ~ age + sex + married, data = mosaicData::CPS85)
mod_plot(mod5)
mod_plot(mod5, class_level = "manag")
# }