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

plot_ALE_multi(
  ALE,
  xquantiles = c(0.025, 0.975),
  yquantiles = c(0.1, 0.5, 0.9),
  name,
  cex.axis = 1,
  cex.lab = 1,
  rug = TRUE,
  rug.col = "gray50",
  xaxs = TRUE,
  gap.axis = NA,
  rug.tick = 0.02,
  rug.lwd = 0.5,
  rug.alpha = 0.2,
  rug.max = 1000,
  poly.colp = c("#fcde9c", "#e34f6f", "#7c1d6f"),
  poly.alpha = 0.5,
  level.names
)

Arguments

ALE

an ALE object for a given variable; indexed as a list for full functionality

xquantiles

lower and upper quantile bounds to limit x values to

yquantiles

lower, middle, and upper quantiles to plot the confidence interval around the ALE predictions

name

the x-axis label of the variable; self-supplied if indexed as a list

cex.axis

the cex of the axis

cex.lab

the cex of the labels

rug

logical for turning the rug plot on/off (defaults to table values for class=='factor')

rug.col

color of rug ticks

rug.tick

length of rug ticks

rug.lwd

width of rug ticks

rug.alpha

transparency of rug ticks

rug.max

maximum number of ticks to plot (useful for big data)

poly.colp

is a vector of colors equal to n levels in response metric

poly.alpha

is a transparency value between 0 and 1 for the confidence interval polygon from the ERF predictions

level.names

names of the multivariate levels

Value

A plot of the ALEs

Examples

#run an ERF with 10 RFs and 
logit <- function(x){log(x/(1-x))}
inv_logit <- function(x){exp(x)/(exp(x)+1)}

x_mat <- as.data.frame(replicate(4, rnorm(1e4)))
x_mat_bin <- t(rmultinom(1e4,1,prob=c(0.33,0.33,0.33)))
x_mat$V5 <- factor(apply(x_mat_bin,1,function(x)which(x==1)))

y_gin <- function(){
  eff <- rnorm(ncol(x_mat)-1)
eff_bin <- rnorm(ncol(x_mat_bin))
y_logit <- t(eff %*% t(x_mat[,-5])) + t(eff_bin %*% t(x_mat_bin))
y <- inv_logit(y_logit)
return(y)
}

y_poss <- data.frame(y1 = y_gin(),
                    y2 = y_gin(),
                    y3 = y_gin())

y_bin <- apply(y_poss,1,function(x) rmultinom(1,1,x))
y <- apply(y_bin,2,function(x)which(x==1))
df <- data.frame(y = factor(y),x_mat)

ens_rf_ex <- ens_random_forests(df=df, var="obs", covariates=colnames(df[,-1]), save=FALSE, cores=1)
#> rounding n.forests to the nearest one
#> Error in `[.data.frame`(df, , var): undefined columns selected


ALE_df <- ALE_fn(ens_rf_ex, save=FALSE, multi=TRUE, type='prob')
#> Error in ALE_fn(ens_rf_ex, save = FALSE, multi = TRUE, type = "prob"): unused argument (save = FALSE)

plot_ALE_multi(ALE_df[1])
#> Error in eval(expr, envir, enclos): object 'ALE_df' not found