margeff | R Documentation |
This function estimates discrete marginal effects (i.e., changes in the expected response) for (generalized) linear and nonlinear regression models as the difference or ratio of expected responses. It can also approximate "instantaneous" marginal effects. The standard error of the marginal effect is computed using the delta method with numerical differentiation.
margeff(
model,
a,
b,
df,
cnames,
type = c("difference", "percent", "factor"),
delta = 1,
level = 0.95,
fcov = vcov,
...
)
model |
Model object of class |
a |
List or data frame defining values of the explanatory variables. |
b |
List or data frame defining values of the explanatory variables. |
df |
Degrees of freedom for the confidence interval. If omitted it is extracted from the model object. |
cnames |
Optional names for the marginal effects. |
type |
Type of marginal effect (difference, percent, or factor). Difference is the default. |
delta |
Divisor for the marginal effect (default is one). This has no effect unless |
level |
Confidence level in (0,1). |
fcov |
Function for estimating the variance-covariance matrix of the model parameters. |
A (discrete) marginal effect is defined as the difference [E(Y|X = a) - E(Y|X = b)]/\delta
where a
and b
represent specified values of the explanatory variables. Typically these differ only in terms of the value of one explanatory variable to estimate the marginal effect of changing that explanatory variable when the other explanatory variables are held constant at specified values. Also typically \delta
would be set to one unless a change of scale is desired or one wishes to approximate the instantaneous marginal effect (see below).
For continuous explanatory variables the "instantaneous" marginal effect is a limiting case of the discrete marginal effect. For example, if there are two explanatory variables — X_1
and X_2
— the marginal effect of X_1
at X_1 = x_1
and X_2 = x_2
can be defined as the limit of [E(Y|X_1 = x_1 + \delta, X_2 = x_2) - E(Y|X_1 = x_1, X_2 = x_2)]/\delta
as \delta
goes to zero (i.e., the derivative E(Y|X_1=x_1,X_2=x_2)
with respect to x_1
). This can be approximated numerically by setting \delta
to a relatively small number.
A marginal effect can also be defined as the percent change in the expected response, 100[E(Y|X = a) - E(Y|X = b)]/E(Y|X = b)
. A positive value is the percent increase in the expected response, and a negative value is the percent decrease in the expected response.
Finally the marginal effect can be defined by the factor E(Y|X = a)/E(Y|X = b)
.
m <- glm(cbind(deaths, total - deaths) ~ insecticide * log2(deposit),
family = binomial, data = insecticide)
# discrete marginal effect of increasing deposit from 4 to 6 for each insecticide
margeff(m,
a = list(deposit = 6, insecticide = levels(insecticide$insecticide)),
b = list(deposit = 4, insecticide = levels(insecticide$insecticide)),
cnames = levels(insecticide$insecticide))
# approximate "instantaneous" marginal effects for each insecticide at a deposit of 5
margeff(m,
a = list(deposit = 5 + 0.001, insecticide = levels(insecticide$insecticide)),
b = list(deposit = 5, insecticide = levels(insecticide$insecticide)),
cnames = levels(insecticide$insecticide), delta = 0.001)
# percent change in expected proportion of deaths when increasing deposit from 4 to 6
margeff(m,
a = list(deposit = 6, insecticide = levels(insecticide$insecticide)),
b = list(deposit = 4, insecticide = levels(insecticide$insecticide)),
cnames = levels(insecticide$insecticide), type = "percent")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.