marg {modmarg} | R Documentation |
Estimating predictive margins on a model
Description
This function estimates the predictive effects and levels for variables within a model using the delta method.
Usage
marg(
mod,
var_interest,
data = NULL,
weights = NULL,
vcov_mat = NULL,
dof = NULL,
type = "levels",
base_rn = 1,
at_var_interest = NULL,
at = NULL,
cofint = 0.95,
...
)
Arguments
mod |
model object, currently only support those of class |
var_interest |
name of the variable of interest, must correspond to a covariate in the model |
data |
data.frame that margins should run over, defaults changes based on class-specific method |
weights |
numeric, vector of weights used to generate predicted levels,
defaults changes based on class-specific method. Must be equal to the number
of rows in |
vcov_mat |
the variance-covariance matrix, defaults changes based on class-specific method |
dof |
integer, the degrees of freedom used for the T statistic in an OLS model, defaults changes based on class-specific method |
type |
either |
base_rn |
numeric, if |
at_var_interest |
vector, if type == 'levels', the values for the
variable of interest at which levels should be calculated.
If |
at |
list, should be in the format of |
cofint |
numeric, confidence interval (must be less than 1), defaults to 0.95 |
... |
additional parameters passed to class-specific methods |
Details
The variable for the predictive margin is specified by var_interest
. If
margins are only needed at particular values of var_interest
,
at_var_interest
should be used. If margins of var_interest
are
needed at across the levels of a different variable in the model,
at
should be used.
If higher-order polynomial terms (e.g. y ~ x + x^2
) are added
using the R function poly
, the raw = TRUE
argument should be used to include the basic polynomial terms
instead of orthogonal polynomial terms. If orthogonal polynomials are used,
marg
will fail when the user specifies at
for a small set
of values for the variable in question (e.g. at = list(x = 10)
),
since poly
needs more data to calculate orthogonal polynomials
(e.g. poly(10, 2)
fails, but poly(c(10, 8, 3), 2)
will run).
P values are calculated with T tests for gaussian families, and Z tests
otherwise. If a new variance-covariance matrix is provided (e.g. for
clustering standard errors), the degrees of freedom for the T test / p-value
calculation may need to be specified using dof
.
This function currently only supports glm
and
ivreg
objects. If you would like to use lm
objects, consider running a glm
with family gaussian
.
When calculating predicted levels and effects for models built using weights,
marg
returns weighted averages for levels and effects by default.
Users can remove this option by setting weights = NULL
.
Value
list of dataframes with predicted margins/effects, standard errors, p-values, and confidence interval bounds