marginal_effects: Marginal Effects for Ordered Correlation Forest

View source: R/marginal-effects.R

marginal_effectsR Documentation

Marginal Effects for Ordered Correlation Forest

Description

Nonparametric estimation of marginal effects using an ocf object.

Usage

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

Arguments

object

An ocf 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.

these_covariates

Named list with covariates' names as keys and strings denoting covariates' types as entries. Strings must be either "continuous" or "discrete". The names of the list indicate the covariates for which marginal effect estimation is desired. If NULL (the default), marginal effects are estimated for all covariates and covariates' types are inferred by the routine.

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.

Details

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

If these_covariates is NULL (the default), the routine assumes that covariates with with at most ten unique values are categorical and treats the remaining covariates as continuous.

Value

Object of class ocf.marginal.

Author(s)

Riccardo Di Francesco

References

  • Di Francesco, R. (2025). Ordered Correlation Forest. Econometric Reviews, 1–17. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/07474938.2024.2429596")}.

See Also

ocf

Examples

## Generate synthetic data.
set.seed(1986)

data <- generate_ordered_data(100)
sample <- data$sample
Y <- sample$Y
X <- sample[, -1]

## Fit ocf.
forests <- ocf(Y, X)

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

print(me)
print(me, latex = TRUE)
plot(me)

## Compute standard errors. This requires honest forests.
honest_forests <- ocf(Y, X, honesty = TRUE)
honest_me <- marginal_effects(honest_forests, eval = "atmean", inference = TRUE)

print(honest_me, latex = TRUE)
plot(honest_me)

## Subset covariates and select covariates' types.
my_covariates <- list("x1" = "continuous", "x2" = "discrete", "x4" = "discrete")
honest_me <- marginal_effects(honest_forests, eval = "atmean", inference = TRUE,
                              these_covariates = my_covariates)
print(honest_me)
plot(honest_me)


ocf documentation built on April 4, 2025, 4:44 a.m.