| AverageMarginalEffects | R Documentation |
The AME is a simple mean FME and computed w.r.t. a feature variable and a model.
predictorPredictor object
featuresvector of features for which AMEs should be computed
ep.methodstring specifying extrapolation detection method
resultsdata.table with AMEs computed
computedlogical specifying if compute() has been run
new()Create a new AME object.
AverageMarginalEffects$new(model, data, features = NULL, ep.method = "none")
modelThe (trained) model, with the ability to predict on new data. This must be a train.formula (tidymodels), Learner (mlr3), train (caret), lm or glm object.
dataThe data used for computing AMEs, must be data.frame or data.table.
featuresIf not NULL, a named list of the names of the feature variables for which AMEs should be computed, together with the desired step sizes. For numeric features, the step size must be a single number. For categorial features, the step size must be a character vector of category names that is a subset of the levels of the factor variable.
ep.methodString specifying the method used for extrapolation detection. One of "none" or "envelope". Defaults to "none".
A new AME object.
# Train a model:
library(mlr3verse)
library(ranger)
set.seed(123)
data(bikes, package = "fmeffects")
task = as_task_regr(x = bikes, id = "bikes", target = "count")
forest = lrn("regr.ranger")$train(task)
# Compute AMEs for all features:
\dontrun{
overview = AverageMarginalEffects$new(
model = forest,
data = bikes)$compute()
summary(overview)
# Compute AMEs for a subset of features with non-default step.sizes:
overview = AverageMarginalEffects$new(model = forest,
data = bikes,
features = list(humidity = 0.1,
weather = c("clear", "rain")))$compute()
summary(overview)
}
compute()Computes results, i.e., AMEs including the SD of FMEs, for an AME object.
AverageMarginalEffects$compute()
An AME object with results.
# Compute results:
\dontrun{
overview$compute()
}
clone()The objects of this class are cloneable with this method.
AverageMarginalEffects$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `AverageMarginalEffects$new`
## ------------------------------------------------
# Train a model:
library(mlr3verse)
library(ranger)
set.seed(123)
data(bikes, package = "fmeffects")
task = as_task_regr(x = bikes, id = "bikes", target = "count")
forest = lrn("regr.ranger")$train(task)
# Compute AMEs for all features:
## Not run:
overview = AverageMarginalEffects$new(
model = forest,
data = bikes)$compute()
summary(overview)
# Compute AMEs for a subset of features with non-default step.sizes:
overview = AverageMarginalEffects$new(model = forest,
data = bikes,
features = list(humidity = 0.1,
weather = c("clear", "rain")))$compute()
summary(overview)
## End(Not run)
## ------------------------------------------------
## Method `AverageMarginalEffects$compute`
## ------------------------------------------------
# Compute results:
## Not run:
overview$compute()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.