Generates and returns the data required to plot the response curves of a model fitted with rf(), rf_repeat(), or rf_spatial().

get_response_curves(
  model = NULL,
  variables = NULL,
  quantiles = c(0.1, 0.5, 0.9),
  grid.resolution = 200,
  verbose = TRUE
)

Arguments

model

A model fitted with rf(), rf_repeat(), or rf_spatial().

variables

Character vector, names of predictors to plot. If NULL, the most important variables (importance higher than the median) in model are selected. Default: NULL.

quantiles

Numeric vector with values between 0 and 1, argument probs of quantile. Quantiles to set the other variables to. Default: c(0.1, 0.5, 0.9)

grid.resolution

Integer between 20 and 500. Resolution of the plotted curve Default: 100

verbose

Logical, if TRUE the plot is printed. Default: TRUE

Value

A data frame with the following columns:

  • response: Predicted values of the response, obtained with stats::predict().

  • predictor: Values of the given predictor.

  • quantile: Grouping column, values of the quantiles at which the other predictors are set to generate the response curve.

  • model: Model number, only relevant if the model was produced with rf_repeat().

  • predictor.name: Grouping variable, name of the predictor.

  • response.name: Grouping variable, name of the response variable.

Details

All variables that are not plotted in a particular response curve are set to the values of their respective quantiles, and the response curve for each one of these quantiles is shown in the plot.

See also

Examples

if(interactive()){ #loading example data data(plant_richness_df) #fitting random forest model out <- rf( data = plant_richness_df, dependent.variable.name = "richness_species_vascular", predictor.variable.names = colnames(plant_richness_df)[5:21], n.cores = 1, verbose = FALSE ) #getting data frame with response curves p <- get_response_curves(out) head(p) }