Skip to contents

Plot additivity scatterplot(-s) with R^2 value(-s)

Usage

g_additivity(sp, lp, descriptions = NULL, cex = 4, plot_only = TRUE)

Arguments

sp

Sculpted predictions. Either as a vector or as a list of those.

lp

Learner predictions. Either as a vector or as a list of those. Same size as sp.

descriptions

(Optional) Descriptions of the models to be shown on the plot. Same size as sp if sp is provided as a list.

cex

cex graphical parameter.

plot_only

(logical) Return plot only or plot with the R^2 value? Defaults to the first (i.e. TRUE).

Value

If plot_only, then a plot. If !plot_only, then a plot and a data.frame.

Examples

df <- mtcars
df$vs <- as.factor(df$vs)
model <- rpart::rpart(
  hp ~ mpg + carb + vs,
  data = df,
  control = rpart::rpart.control(minsplit = 10)
)
model_predict <- function(x) predict(model, newdata = x)
covariates <- c("mpg", "carb", "vs")
pm <- sample_marginals(df[covariates], n = 50, seed = 5)

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

g_additivity(
  sp = predict(rs, pm),
  lp = model_predict(pm),
  descriptions = "Product Marginal"
)