CalcMfx: Calculate marginal effects and ICE curves

Description Usage Arguments Details Value Slots

View source: R/Mfx_functions.R

Description

calculate marginal effects of features on predicted outcomes from an arbitrary prediction model. Also calculates the necessary components to construct individual conditional expectation (ICE) curves.

Usage

1
2
CalcMfx(object, X, pred_fun = predict, predictors = colnames(X),
  max_pts = 100, min_pts = 0, dydx_mean = FALSE, ...)

Arguments

object

a model object

X

an object of class data.frame containing data from which marginal effects should be calculated

pred_fun

a function that accepts two arguments corresponding to object and X, above. The function should return a vector of predicted responses. If this argument is not passed, the generic predict function will be tried.

predictors

a character vector of column names of X for which marginal effects are to be calculated

max_pts

an integer value or NA. If an integer, then max_pts number of values will be used to calculate marginal effects and ICE curves. If max_pts is NA, then each predictor's unique values will be used.

min_pts

a positive integer. Predictorswith fewer than min_pts unique values will be evaluated only at their unique values, rather than max_pts values. If you want to guarantee all points will be evaluated at max_pts values, set min_pts to 0.

dydx_mean

logical indicating whether to calculate the marginal effect based on the mean of the derivative of ICE curves. If FALSE, then the marginal effect is calculated at each actual observation then averaged.

...

arguments to be passed on to textmineR's function codeTmParallelApply.

Details

details coming soon

Value

Returns a list of class Mfx or Mfx_list depending on whether the predictors argument is of length 1 or greater. If length 1, then the result is of class Mfx. If greater than 1, the result is of class Mfx_list, each element of which is of class Mfx. An object of class Mfx has the following slots:

Slots

mfx

the calculated marginal effect

se

the standard error of the calculated marginal effect

conf

a 95

\item

dya vector of changes in the predicted value

\item

dxa vector of changes in the predictor (set by max_pts)

\item

xthe predictor vector set by max_pts

\item

yh0inital prediction corresponding to the first value of x

\item

true_valuesdata.frame with values for dx, dy, and predictions for the actual data points.

\item

varnamethe name of the predictor for which a marginal effect has been calculated

# examples coming soon


TommyJones/marginal documentation built on Nov. 21, 2019, 3:53 p.m.