Calculates the Accumulated Local Effects (ALE) from an ERF object

calc_ALE(
  fit,
  var,
  save = TRUE,
  out.folder = NULL,
  cores = parallel::detectCores() - 4,
  type = "response",
  K = 50
)

Arguments

fit

The fitted object returned from calling ens_random_forests()

var

The name of the response variable

save

A logical flag to save the output as an RData object, default is TRUE.

out.folder

A path to the folder to write out too. If NULL then a folder is generated in the working directory

cores

An integer value that either indicates the number of cores to use for parallel processing or a negative value to indicate the number of cores to leave free. Default is to leave two cores free.

type

is either 'response' or 'prob' from predict.randomForest; if 'prob' then n sets of predictions are returned for the n levels in var; if "response" then the factorized predicted response values are returned

Value

A list that contains a data.frame for each variable, ordered by the mean variable importance, and a vector of the covariate values (used for rug plot in plot_ALE). The columns in each data.frame are as follows:

  • x: the covariate values that the ALE was calculated for

  • class: the class of the covariate; used by subsequent plot_ALE function

  • q: the quantile of the x value of the covariate

  • f.X: the ALEs evaluated at a given x value

Examples

#run an ERF with 10 RFs and 
ens_rf_ex <- ens_random_forests(df=simData$samples, var="obs", covariates=grep("cov", colnames(simData$samples),value=T), save=FALSE, cores=1)
#> rounding n.forests to the nearest one

ALEdf <- calc_ALE(ens_rf_ex, save=FALSE)
#> No name of response variable, making one
#> rounding n.forests to the nearest one
head(ALEdf[[1]]$df)
#>            x   class      q        f.1        f.2        f.3        f.4
#> 1 -0.6322850 numeric 0.0002 -0.3150314 -0.3059006 -0.2780686 -0.3339576
#> 2 -0.4659179 numeric 0.0202 -0.3150314 -0.3059006 -0.2780686 -0.3339576
#> 3 -0.4094575 numeric 0.0401 -0.3150314 -0.3059006 -0.2780686 -0.3339576
#> 4 -0.3715804 numeric 0.0600 -0.3150314 -0.3059006 -0.2780686 -0.3339576
#> 5 -0.3321141 numeric 0.0800 -0.3150314 -0.3059006 -0.2780686 -0.3339576
#> 6 -0.2917534 numeric 0.1001 -0.3150314 -0.3059006 -0.2780686 -0.3339576
#>          f.5        f.6        f.7        f.8        f.9       f.10
#> 1 -0.3081547 -0.2988771 -0.3124441 -0.2597704 -0.3602964 -0.3139273
#> 2 -0.3081547 -0.2988771 -0.3124441 -0.2597704 -0.3602964 -0.3139273
#> 3 -0.3081547 -0.2988771 -0.3124441 -0.2597704 -0.3602964 -0.3139273
#> 4 -0.3081547 -0.2988771 -0.3124441 -0.2597704 -0.3602964 -0.3139273
#> 5 -0.3081547 -0.2988771 -0.3124441 -0.2597704 -0.3602964 -0.3139273
#> 6 -0.3081547 -0.2988771 -0.3124441 -0.2597704 -0.3602964 -0.3139273