Learn R Programming

morf (version 1.0.0)

marginal_effects: Marginal Effects for Modified Ordered Random Forests

Description

Nonparametric estimation of marginal effects using an morf object.

Usage

marginal_effects(
  object,
  data = NULL,
  eval = "atmean",
  bandwitdh = 0.01,
  inference = FALSE
)

Value

Object of class morf.marginal.

Arguments

object

An morf object.

data

Data set of class data.frame to estimate marginal effects. It must contain at least the same covariates used to train the forests. If NULL, marginal effects are estimated on object$full_data.

eval

Evaluation point for marginal effects. Either "mean", "atmean" or "atmedian".

bandwitdh

How many standard deviations x_up and x_down differ from x.

inference

Whether to extract weights and compute standard errors. The weights extraction considerably slows down the program.

Author

Riccardo Di Francesco

Details

marginal_effects can estimate mean marginal effects, marginal effects at the mean, or marginal effects at the median, according to the eval argument.

The routine assumes that covariates with more than ten unique values are continuous. Otherwise, covariates are assumed to be discrete.

See Also

morf

Examples

Run this code
## Load data from orf package.
set.seed(1986)

library(orf)
data(odata)
odata <- odata[1:200, ] # Subset to reduce elapsed time.

y <- as.numeric(odata[, 1])
X <- as.matrix(odata[, -1])

## Fit morf . Use large number of trees.
forests <- morf(y, X, n.trees = 4000)

## Marginal effects at the mean.
me <- marginal_effects(forests, eval = "atmean")
print(me)
summary(me)

## LATEX.
print(me, latex = TRUE)

# \donttest{
## Compute standard errors. This requires honest forests.
honest_forests <- morf(y, X, n.trees = 4000, honesty = TRUE)
honest_me <- marginal_effects(honest_forests, eval = "atmean", inference = TRUE)
honest_me$standard.errors
honest_me$p.values # These are not corrected for multiple hypotheses testing!

print(honest_me, latex = TRUE)# }

Run the code above in your browser using DataLab