mem | R Documentation |
mem
computes the marginal effects of variable x
at the specified values of at
variables and the mean values of all the other variables (including x
).
mem( x, model = NULL, data = NULL, formula = NULL, link = NULL, coefficients = NULL, vcov = NULL, discrete = FALSE, discrete_step = 1, at = NULL, mc = FALSE, pct = c(lb = 2.5, ub = 97.5), iter = 1000, weights = NULL )
x |
a character string representing the name of the main variable of interest. Marginal effects will be computed for 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 |
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). |
discrete |
A logical variable. If TRUE, the function will compute the effect of a discrete change in |
discrete_step |
The size of a discrete change in |
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 |
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 = |
iter |
the number of interations used in Monte-Carlo simulations. Default = 1,000. |
weights |
an optional vector of sampling weights. |
mem
returns a data frame with the estimates of the marginal effects at means, along with standard errors, confidence intervals,
and the used values of the independent variables. All quantitative variable not included in at
are set to their means,
and all qualitative variables (except those listed in at
) are converted to factors and set to their modes.
##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 marginal effects at means mem(model = y, x = "x1", at=list(x2=seq(min(data$x2), max(data$x2), length.out=5))) ## Not run: ## logit m <- glm(any_dispute ~ flows.ln*polity2 + gdp_pc, data=strikes, family="binomial") summary(m) ## marginal effects at means with a robust (heteroscedasticity-consistent) variance-covariance matrix library(sandwich) mem(model=m, x="flows.ln", vcov=vcovHC(m), at=list(polity2=c(-10,0,10))) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.