dame: Distribution-weighted average marginal effect

View source: R/dame.R

dameR Documentation

Distribution-weighted average marginal effect

Description

dame computes the distribution-weighted average marginal effects (DAME) as described in Zhirnov, Moral, and Sedashov (2021).

Usage

dame(
  x,
  over = NULL,
  model = NULL,
  data = NULL,
  formula = NULL,
  link = NULL,
  coefficients = NULL,
  vcov = NULL,
  nbins = 10,
  bin_id = NULL,
  use_distinct_values = FALSE,
  discrete = FALSE,
  discrete_step = 1,
  at = NULL,
  mc = FALSE,
  pct = c(lb = 2.5, ub = 97.5),
  iter = 1000,
  weights = NULL
)

Arguments

x

a character string representing the name of the main variable of interest. Marginal effects will be computed for this variable.

over

a character string representing the name of the conditionning variable. DAME will be computed for the bins long the range of this variable.

model

fitted model object. The package works best with GLM objects and will extract the formula, dataset, family, coefficients, and the QR components of the design matrix if arguments formula, data, link, coefficients, and/or vcov are not explicitly specified.

data

the dataset to be used to compute marginal effects (if not specified, it is extracted from the fitted model object).

formula

the formula used in estimation (if not specified, it is extracted from the fitted model object).

link

the name of the link function used in estimation (if not specified, it is extracted from the fitted model object).

coefficients

the named vector of coefficients produced during the estimation (if not specified, it is extracted from the fitted model object).

vcov

the variance-covariance matrix to be used for computing standard errors (if not specified, it is extracted from the fitted model object).

nbins

the number of bins to be used for aggregating marginal effects; the default is 10 bins of equal size; ignored if bin_id is specified or use_distinct_values is TRUE.

bin_id

a numeric vector identifying the bins used for aggregating marginal effects (if not specified and use_distinct_values=FALSE, the function uses nbins bins with roughly equal number of observations; if not specified and use_distinct_values=TRUE, the function uses all unique values of the over variable).

use_distinct_values

logical; if TRUE, the function uses all unique values of the over variable; ignored if bin_id is specified.

discrete

logical. If TRUE, the function will compute the effect of a discrete change in x. If FALSE, the function will compute the partial derivative of x.

discrete_step

The size of a discrete change in x used in computations (used only if discrete=TRUE).

at

an optional named list of values of independent variables. These variables will be set to these value before computations. The remaining numeric variables (except x and over) will be set to their means. The remaining factor variables will be set to their modes.

mc

logical. If TRUE, the standard errors and confidence intervals will be computed using simulations. If FALSE (default), the delta method will be used.

pct

a named numeric vector with the sampling quantiles to be output with the DAME estimates (the names are used as the new variable names). Default = c(lb=2.5,ub=97.5).

iter

the number of interations used in Monte-Carlo simulations. Default = 1,000.

weights

an optional vector of sampling weights.

Value

dame returns a data frame with the estimates of the distribution-weighted average marginal effects, standard errors, confidence intervals, the corresponding bin IDs (by default, the median value of the conditioning variable within the bin), and the targeted combinations of at values if specified.

Author(s)

Function dame is an implementation of a procedure described in Zhirnov, Moral, and Sedashov (2021). Standard errors are computed using either the delta method (Greene 2012) for more details) or Monte-Carlo simulations (King, Tomz, and Wittenberg 2000).

References

Greene, William. 2012. Econometric Analysis, 7 ed. Pearson Education Limited.

King, Garry, Michael Tomz, and Jason Wittenberg. 2000. “Making the Most of Statistical Analyses: Improving Interpretation and Presentation.” American Journal of Political Science 44(2): 341-355.

Zhirnov, Andrei, Mert Moral, and Evgeny Sedashov (2021). “Taking Distributions Seriously: On the Interpretation of the Estimates of Interactive Nonlinear Models.” Working paper.

Examples

##poisson regression with 2 variables and an interaction between them
#fit the regression first
data <- data.frame(y = rpois(10000, 10), x2 = rpois(10000, 5),
x1 = rpois(10000, 3), w=c("a","b","c","d"))
y <- glm(y ~ x1*x2 + w, data = data, family = "poisson")
#compute DAME
dame(model = y, x = "x1", over = "x2")
## Not run: 
## logit
m <- glm(any_dispute ~ flows.ln*polity2 + gdp_pc, data=strikes, family="binomial")
summary(m)
## DAME with a robust (heteroscedasticity-consistent) variance-covariance matrix and 4 bins
library(sandwich)
dame(model=m, x="flows.ln", over="polity2", nbins=4, vcov=vcovHC(m))

## End(Not run)

andreizhirnov/DAME documentation built on Nov. 21, 2022, 5:55 p.m.