margins: Compute Marginal Effects for One-inflated models

View source: R/margins.R

marginsR Documentation

Compute Marginal Effects for One-inflated models

Description

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.

Usage

margins(model, df, at = "AE", verbose = TRUE)

Arguments

model

An object representing a fitted model. Must be of class oneinflmodel or truncmodel.

df

A data.frame containing the dataset used to fit the model. The variables in the data must match those used in the model.

at

A character string or list specifying where to evaluate the marginal effects:

  • "AE": Average Effect (marginal effect averaged over all data points; default).

  • "EM": Effect at Means (marginal effect evaluated at the sample means of the data).

  • A named list: A custom case specifying representative values for variables.

verbose

Logical; if TRUE (default), prints the summary output. If FALSE, suppresses output table and returns a list containing several components.

Details

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.

Value

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.

See Also

dEdq_nb, dEdq_nb_noinfl, dEdq_pois, dEdq_pois_noinfl, model.frame, model.matrix, numericDeriv

Examples

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


oneinfl documentation built on April 4, 2025, 12:05 a.m.