View source: R/marginal-effects.R
marginal_effects | R Documentation |
Nonparametric estimation of marginal effects using an ocf
object.
marginal_effects(
object,
data = NULL,
these_covariates = NULL,
eval = "atmean",
bandwitdh = 0.1,
inference = FALSE
)
object |
An |
data |
Data set of class |
these_covariates |
Named list with covariates' names as keys and strings denoting covariates' types as entries. Strings must be either |
eval |
Evaluation point for marginal effects. Either |
bandwitdh |
How many standard deviations |
inference |
Whether to extract weights and compute standard errors. The weights extraction considerably slows down the program. |
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.
Object of class ocf.marginal
.
Riccardo Di Francesco
Di Francesco, R. (2025). Ordered Correlation Forest. Econometric Reviews, 1–17. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/07474938.2024.2429596")}.
ocf
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.