ForwardMarginalEffect {fmeffects}R Documentation

R6 Class representing a forward marginal effect (FME)

Description

The FME is a forward difference in prediction due to a specified change in feature values.

Public fields

feature

vector of features

predictor

Predictor object

step.size

vector of step sizes for features specified by "feature"

data.step

the data.table with the data matrix after the step

ep.method

string specifying extrapolation detection method

compute.nlm

logical specifying if NLM should be computed

nlm.intervals

number of intervals for computing NLMs

step.type

"numerical" or "categorical"

extrapolation.ids

vector of observation ids classified as extrapolation points

results

data.table with FMEs and NLMs computed

ame

Average Marginal Effect (AME) of observations in results

anlm

Average Non-linearity Measure (ANLM) of observations in results

computed

logical specifying if compute() has been run

Methods

Public methods


Method new()

Create a new ForwardMarginalEffect object.

Usage
ForwardMarginalEffect$new(
  predictor,
  feature,
  step.size,
  ep.method = "none",
  compute.nlm = FALSE,
  nlm.intervals = 1
)
Arguments
predictor

Predictor object.

feature

Feature vector.

step.size

Vector of step sizes.

ep.method

String specifying extrapolation detection method.

compute.nlm

Compute NLM with FMEs? Defaults to FALSE.

nlm.intervals

How many intervals for NLM computation. Defaults to 1.

Returns

A new ForwardMarginalEffect object.

Examples
# Train a model:

library(mlr3verse)
library(ranger)
data(bikes, package = "fmeffects")
forest = lrn("regr.ranger")$train(as_task_regr(x = bikes, id = "bikes", target = "count"))

# Create an `ForwardMarginalEffect` object:
effects = ForwardMarginalEffect$new(makePredictor(forest, bikes, "count"),
                  feature = c("temp", "humidity"),
                  step.size = c(1, 0.01),
                  ep.method = "envelope")

Method compute()

Computes results, i.e., FME (and NLMs) for non-extrapolation points, for a ForwardMarginalEffect object.

Usage
ForwardMarginalEffect$compute()
Returns

A ForwardMarginalEffect object with results.

Examples
# Compute results:
effects$compute()

Method plot()

Plots results, i.e., FME (and NLMs) for non-extrapolation points, for an FME object.

Usage
ForwardMarginalEffect$plot(with.nlm = FALSE, jitter = c(0, 0))
Arguments
with.nlm

Plots NLMs if computed, defaults to FALSE.

jitter

Jitters data. A two-dimensional numeric vector, corresponds to "width" and "height". See ?ggplot2::geom_jitter for details. Not available if step.type is categorical. Defaults to no jittering, i.e., c(0, 0).

Examples
# Compute results:
effects$plot()

Method clone()

The objects of this class are cloneable with this method.

Usage
ForwardMarginalEffect$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `ForwardMarginalEffect$new`
## ------------------------------------------------


# Train a model:

library(mlr3verse)
library(ranger)
data(bikes, package = "fmeffects")
forest = lrn("regr.ranger")$train(as_task_regr(x = bikes, id = "bikes", target = "count"))

# Create an `ForwardMarginalEffect` object:
effects = ForwardMarginalEffect$new(makePredictor(forest, bikes, "count"),
                  feature = c("temp", "humidity"),
                  step.size = c(1, 0.01),
                  ep.method = "envelope")

## ------------------------------------------------
## Method `ForwardMarginalEffect$compute`
## ------------------------------------------------

# Compute results:
effects$compute()

## ------------------------------------------------
## Method `ForwardMarginalEffect$plot`
## ------------------------------------------------

# Compute results:
effects$plot()

[Package fmeffects version 0.1.2 Index]