ame: Average Marginal Effects

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/ame.R

Description

Compute average marginal effects for generalized linear and generalized additive models using Krinsky-Robb Monte-Carlo simulation.

Usage

1
ame(model, cont_vars, fac_vars, nsim = 100, seed = 1)

Arguments

model

an object of class glm.

cont_vars

a character vector containing the names of continuous model variables.

fac_vars

a character vector with factor model variables.

nsim

number of simulations. Default is 100.

seed

Seed value for the random number generator. Default value is 1.

Value

ame returns an object of class "ame". The functions summary (summary.ame) and print (print.summary.ame) are used to display a summary of the computed average marginal effects.

An object of class "ame" is a list that contains at least the following components:

continuous

a named list containing average marginal effects for each continuous variable. If no variable is specified, defaults to NULL. The list has attributes variable_type and variable_names.

factor

a named list containing first differences for each factor variable. If no factor is specified, defaults to NULL. The list has attributes variable_type and variable_names.

Furthermore, objects of class "ame" store the model family and link in the attributes model_family, model_link, and the random number generator seed and number of draws from the multivariate normal in the attributes seed and n_sim.

Author(s)

Julia Partheymueller, Alexander Staudt (astaudt@mail.uni-mannheim.de)

References

Krinsky I, Robb AL (1991). "Three Methods for Calculating the Statistical Properties of Elasticities: A Comparison." Empirical Economics 16(2), 199–209.

Brambor T, Clark WR, Golder M (2006). "Understanding Interaction Models: Improving Empirical Analyses." Political Analysis 14(1), 63–82. url: http://localgov.fsu.edu/readings_papers/Research Methods/Brambor_et_al_Multipolicative_Interactions.pdf

See Also

King G, Tomz M, Wittenberg J (2000). "Making the Most of Statistical Analyses: Improving Interpretation and Presentation." American Journal of Political Science 44(2), 347–361. url: http://www.polmeth.wustl.edu/files/polmeth/king98f.pdf.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# generate some data (factor, dummy, continuous)
set.seed(100)

y <- rbinom(100, size = 1, prob = 0.5)
mcat <- as.factor(rpois(100, 3))
dummy <- as.factor(rbinom(100, size = 1, prob = 0.5))
cont <- runif(100, -10, 10)
data <- data.frame(y, mcat, dummy, cont)

# run glm model
glm_fit <- glm(y ~ mcat + dummy * cont, data = data, family = binomial(link = "logit"))

summary(glm_fit)

# compute average marginal effects
glm_ame <- ame(glm_fit, cont_vars = c("cont"), fac_vars = c("mcat", "dummy"), nsim = 1000)

summary(glm_ame)

# linear model using glm
lm1 <- glm(mpg ~ cyl + hp + wt, data = mtcars, family = gaussian)
lm2 <- glm(mpg ~ cyl * hp + wt, data = mtcars, family = gaussian)

summary(lm1)
summary(lm2)

# compute average marginal effects
lm1_ame <- ame(lm1, cont_vars = c("cyl", "hp", "wt"), nsim = 1000, seed = 99)
lm2_ame <- ame(lm2, cont_vars = c("cyl", "hp", "wt"), nsim = 1000, seed = 99)

# display results
summary(lm1_ame)
summary(lm2_ame)

staudtlex/ame documentation built on Feb. 12, 2020, 10:26 p.m.