R/plot_ALE_multi.R
plot_ALE_multi.Rd
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
)
an ALE object for a given variable; indexed as a list for full functionality
lower and upper quantile bounds to limit x values to
lower, middle, and upper quantiles to plot the confidence interval around the ALE predictions
the x-axis label of the variable; self-supplied if indexed as a list
the cex of the axis
the cex of the labels
logical for turning the rug plot on/off (defaults to table values for class=='factor')
color of rug ticks
length of rug ticks
width of rug ticks
transparency of rug ticks
maximum number of ticks to plot (useful for big data)
is a vector of colors equal to n levels in response metric
is a transparency value between 0 and 1 for the confidence interval polygon from the ERF predictions
names of the multivariate levels
A plot of the ALEs
#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