Skip to contents

Create density plot for the data, overlaid with ICE curves at quantiles of the variable(s) of interest.

Usage

g_density_ice_plot(
  object,
  new_data,
  var_name,
  var_label = NULL,
  qtiles = seq(0, 1, by = 0.1),
  task = c("regression", "classification")
)

g_density_ice_plot_list(
  object,
  new_data,
  var_names,
  var_labels = NULL,
  qtiles = seq(0, 1, by = 0.1),
  task = c("regression", "classification")
)

Arguments

object

Object of class sculpture (rough, detailed)

new_data

Data to make quantiles on

var_name

String specifying which variable to generate ICE

var_label

String (optional) specifying variable label (x label of the plot)

qtiles

Quantiles to generate ICE curves

task

Prediction task type (regression or classification)

var_names

Vector of strings specifying which variables to generate ICE

var_labels

Named vector of strings specifying variable labels.

Value

g_density_ice_plot(): ggplot object

g_density_ice_plot_list(): list of ggplot objects

Details

g_density_ice_plot() creates a density plot for a single variable.

g_density_ice_plot_list() creates a list of density plots for multiple variables.

These functions should be amenable to any 1st-order model without interaction terms, however not implemented yet, such as handling predict() function output for binary endpoint

Examples

if (FALSE) {
df <- mtcars
df$cyl <- as.factor(df$cyl)
model <- lm(hp ~ ., data = df)
model_predict <- function(x) predict(model, newdata = x)
covariates <- setdiff(colnames(df), "hp")
pm <- sample_marginals(df[covariates], n = 50, seed = 5)

rs <- sculpt_rough(
  dat = pm,
  model_predict_fun = model_predict,
  n_ice = 5,
  seed = 1,
  verbose = 0
)

g_density_ice_plot(rs, new_data = pm, var_name = "mpg")
g_list <- g_density_ice_plot_list(
  rs, new_data = pm, var_names = c("mpg", "cyl", "disp", "drat")
)
grid::grid.draw(gridExtra::arrangeGrob(grobs = g_list))
}