mpred: Generic Predictive Margins¶
Many dependent variables of interest in the study of political behaviour and
opinion formation are categorical. Statistical models involving such dependent
variables generally pose a challenge for their interpretation (apart from the fact that
estimation usually is more difficult than in models for numeric dependent
variables). Because of the difficulty of interpretation one may want to resort
to graphics in which predicted values of a depedent variables are plotted
against values of one or more independent variables of interest. The problem of
such plots based on models for categorical responses is that the pattern of
dependence between dependent variable and independent variable of interest
usually is non-linear and typically also depends on values of other independent
variables that may not of interest. E.g. in a logistic regression of a binary
dependent variable with independent variables
and
,
the unit change of a positive outcome probability
is not constant (as in a linear regression), but depends on the particular value
of . Furthermore, it also depends on the particular value of
. This
variation in the unit change, when identified as the “unit effect” of
on
, has led various authors to claim that the presence of interaction terms
(e.g.
) in a logistic regression model (or other model for categorical
dependent variables) is neither a necessary or sufficient condition for the
existence of interaction effects (citation coming soon).
A way out of the ensuing complications is to focus instead on the expectation or
the average of this unit change:
where is either the density function or probability mass function of
or the emprical distribution of
. If the empirical distribution is
used then this difference is a difference of what is also called the
predictive margins of
for
and
. A predictive margin
for
from the logistic regression model under discussion is defined as
where is the sample size and
are the sample values of
. There is an apparent relation between a predictive margin and the
“do-operator” in the terminology of Judea Pearl. It is defined in the present
context (if
is discrete) as
where the sum is over the range of so that
. A
predictive margin could be interpreted as an estimate of
.
This package provides a generic function to compute predictive margins from models with given covariate settings. All classes of model objects can be used that have a predict() method that allows for a newdata= argument. The package is available not (yet) available from CRAN but only on GitHub.
If you have the package devtools installed, you can install the package by
library(devtools)
install_github("melff/mpred/pkg")