margins | R Documentation |
This wrapper function calls a different function to calculate marginal effects depending on the model type. The marginal effects of the variables are evaluated at specified points, such as the sample means or averages, or at custom-defined cases.
margins(model, df, at = "AE", verbose = TRUE)
model |
An object representing a fitted model. Must be of class |
df |
A |
at |
A character string or list specifying where to evaluate the marginal effects:
|
verbose |
Logical; if |
The function computes marginal effects for zero-truncated Poisson or negative binomial regression models.
It handles different model types; oneinflmodel
for one-inflated models, and truncmodel
for standard count models.
The marginal effects are evaluated at either all data points and averaged (AE
, the default), at the sample means of the variables (EM
), or at a custom case.
The marginal effects for dummy variables are actually the differences in expected outcomes for values of the dummy of 1 and 0.
The marginal effects are displayed along with their statistical significance, evaluated based on the chosen at
parameter.
If verbose=TRUE
(default), prints the marginal effects, their standard errors, z-values, p-values, and significance levels.
If verbose=FALSE
, returns a list containing the following components:
where
A description of how the marginal effects have been evaluated.
dEdq
The marginal effect. The partial derivative of the expected count with respect to a variable q
in the X
and or Z
matrix, or the difference in expectation if q
is binary.
se
The standard errors of the marginal effects evaluated numerically and using a Jacobian via the delta method.
dEdq_nb
, dEdq_nb_noinfl
, dEdq_pois
,
dEdq_pois_noinfl
, model.frame
,
model.matrix
, numericDeriv
df <- data.frame(x = rnorm(100), z = rnorm(100), y = rpois(100, lambda = 5))
model <- oneinfl(y ~ x | z, df = df, dist = "Poisson")
margins(model, df, at = "AE") # Average Effect
margins(model, df, at = "EM", verbose=FALSE) # Effect at Means, suppress printing
margins(model, df, at = list(x = 1, z = 0)) # Custom case
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.