- model
A model estimated using functions from mgcv
(e.g.,
gam
or bam
).
- data
A data frame that is used to calculate the marginal effect or set
to NULL
which will employ the data used when estimating the model.
The default is NULL
. Using a custom dataset may have unexpected
implications for continuous and character/factor variables. See "WARNINGS"
for more discussion.
- variables
A character vector that specifies the variables for which to
calculate effects. The default, NULL
, calculates effects for all
variables.
- continuous_type
A character value, with a default of "IQR"
,
that indicates the type of marginal effects to estimate when the variable
is continuous (i.e. not binary, logical, factor, or character). Options are
"IQR"
(compares the variable at its 25% and 75% percentile),
"minmax"
(compares the variable at its minimum and maximum),
"derivative"
(numerically approximates the derivative at each
observed value), "second_derivative"
(numerically approximates the
second derivative at each observed value), "onesd"
(compares one
standard deviation below and one standard deviation above the mean of the
variable). It also accepts a named list where each named element
corresponds to a continuous variable and has a two-length vector as each
element. The two values are then compared. If this is used, then all
continuous variables must have two values specified.
A special option ("predict"
) produces predictions (e.g.,
predict(model, type = "response")
) at each observed value and then
averages them together. This, in conjunction with conditional
,
provides a way of calculating quantities such as predicted probability
curves using an "observed value" approach (e.g., Hanmer and Kalkan 2013).
Examples are provided below.
- conditional
A data.frame or NULL
. This is an analogue of
Stata's at()
option and the at
argument in the margins
package. For a marginal effect on some variable "a"
, this specifies
fixed values for certain other covariates, e.g. data.frame("b" = 0)
.
If conditional
is NULL
, all other covariates are held at
their observed value. If conditional
is a data.frame, then each row
represents a different combination of covariate values to be held fixed,
and marginal effects are calculated separately for each row. Examples are
provided below.
- individual
A logical value. TRUE
calculates individual effects (i.e.
an effect for each observation in the data
). The default is
FALSE
.
- vcov
A matrix that specifies the covariance matrix of the parameters.
The default, NULL
, uses the standard covariance matrix from
mgcv
. This can be used to specify clustered or robust standard
errors using output from (for example) sandwich
.
- raw
A logical value. TRUE
returns the raw values used to
calculate the effect in addition to the estimated effect. The default is
FALSE
. If TRUE
, an additional column ...id
is present
in the estimated effects that reports whether the row corresponds to the
effect (effect
), the first value (raw_0
) or the second value
(raw_1
) where effect=raw_1 - raw_0
. For "derivative"
,
this is further scaled by the step size. For "second_derivative"
,
effect=raw_2 - 2 * raw_1 + raw_0
, scaled by the step size; see the
discussion for epsilon
for how the step size is calculated.
- use_original
A logical value that indicates whether to use the
estimation data (TRUE
) or data
(FALSE
) when
calculating quantities such as the IQR for continuous variables or the
levels to examine for factor variables. Default (FALSE
) uses the
provided data; if data = NULL
, this is equivalent to using the
estimation data. The "WARNINGS" section provides more discussion of this
option.
- epsilon
A numerical value that defines the step size when calculating
numerical derivatives (default of 1e-7). For "derivative"
, the step
size for the approximation is \(h = \epsilon \cdot \mathrm{max}(1,
\mathrm{max}(|x|))\), i.e. \(f'(x)
\approx \frac{f(x+h) - f(x-h)}{2h}\). Please
see Leeper (2016) for more details.
For "second_derivative"
, the step size is \(h = [\epsilon \cdot
\mathrm{max}(1, \mathrm{max}(|x|))]^{0.5}\), i.e. \(f''(x) \approx \frac{f(x+h) - 2 f(x) +
f(x-h)}{h^2}\)
- verbose
A logical value that indicates whether to report progress when
calculating the marginal effects. The default is FALSE
.
- QOI
A vector of quantities of interest calculate for
calculate_interactions
. Options include "AME"
(average
marginal effect), "ACE"
(average combination effect), "AIE"
(average interaction effect) and "AMIE"
(average marginal
interaction effect); see "Details" for more information. The default
setting calculates all four quantities.
- ...
An argument used for calculate_interactions
to pass
arguments to calculate_effects
. It is unused for
summary.gKRLS_mfx
.
- x
An object estimated using calculate_effects
.
- object
A model estimated using functions from mgcv
(e.g.,
gam
or bam
).