View source: R/extract_param.R
| extract_param | R Documentation |
extract_param() extracts model coefficients and inferential statistics
using parameters::model_parameters(). It returns a compact,
non-redundant parameter table and, when appropriate, transforms coefficients
and confidence intervals into a more directly interpretable metric.
Depending on the model family and link function, the interpreted estimate may represent an odds ratio, risk ratio, incidence rate ratio, hazard ratio, or another multiplicative ratio. For models for which no meaningful automatic transformation is available, the original coefficient is retained.
The function also computes an approximate Cohen's d for each coefficient: from the log odds ratio for logistic models, and from the coefficient-level t or z statistic otherwise.
extract_param(
model,
conf_level = 0.95,
include_intercept = FALSE,
effects = "fixed",
component = "conditional",
transform = c("auto", "none", "exponentiate")
)
model |
A fitted statistical model supported by
|
conf_level |
A single numeric value between 0 and 1 specifying the confidence
level. The default is |
include_intercept |
Logical. Should the intercept be included in the
returned table? The default is |
effects |
Character string specifying the model effects to extract for
models that distinguish between fixed and random effects. The default is
|
component |
Character string specifying the model component to extract
for models with multiple components, such as zero-inflated or hurdle
models. The default is |
transform |
Character string specifying how model coefficients should be transformed for interpretation. Possible values are:
The default is |
The Estimate column always contains the coefficient on the scale on which
the model was fitted. For generalized models, this is generally the scale of
the linear predictor.
When transform = "auto", the following transformations are applied:
No transformation. Interpreted_Estimate is equal
to Estimate.
The coefficient is exponentiated and interpreted as an odds ratio.
The coefficient is exponentiated and interpreted as a risk ratio.
The coefficient is exponentiated and interpreted as an incidence rate ratio.
The coefficient is exponentiated and interpreted as a multiplicative ratio.
The coefficient is exponentiated and interpreted as a hazard ratio.
No automatic exponentiation is performed for links such as probit,
cauchit, or cloglog, because exponentiating an individual coefficient
does not generally produce a standard effect measure with a direct
interpretation.
The interpreted estimates are not necessarily predictions on the response scale. For example, an odds ratio is a ratio of odds rather than a predicted probability. Predicted probabilities or expected responses require the intercept and values of the other model predictors.
Confidence intervals and p-values use the same inferential method as the significance labels of the plotting functions, so that an interval excluding zero always corresponds to a significant coefficient:
linear mixed models fitted with lme4 or lmerTest use Satterthwaite degrees of freedom when lmerTest is installed, as in their p-values;
generalized linear (mixed) models use Wald intervals, which
correspond to the Wald z tests reported by summary(); profile
intervals can disagree with these tests near the significance threshold;
other models use the default method of
parameters::model_parameters().
Approximate Cohen's d values are computed as follows, as reported in
d_method:
for models with a logit link, the log odds ratio is converted as
d = \beta \sqrt{3} / \pi (Chinn, 2000), which treats the
logistic distribution of the latent response as the reference
standard deviation; the same conversion is applied to the confidence
limits;
t statistics are converted using effectsize::t_to_d() with the
coefficient-specific degrees of freedom;
z statistics are converted using effectsize::z_to_d() with the
number of observations returned by stats::nobs().
The conversions based on t or z do not depend on how the contrast is
scaled. The conversion from the log odds ratio refers to the coefficient
as coded: for a contrast whose coefficient equals a scale factor s
multiplied by the compared difference (for example Helmert contrasts; see
contrasts_onepred()), the d of the compared difference is d / s.
The plotting functions apply this rescaling.
These conversions are approximations and assume conditions implicit in the conversion formulas. In particular, the conversion to Cohen's d assumes two groups of approximately equal size, and the conversion from the log odds ratio assumes a logistic latent response. Directly estimated effect sizes should be preferred when the necessary data and an appropriate estimator are available.
A data frame with one row for each extracted model parameter and the following columns:
Name of the model parameter.
Untransformed model coefficient on the model scale.
Standard error of the untransformed coefficient.
Confidence level used for the interval.
Lower confidence limit of Estimate.
Upper confidence limit of Estimate.
Coefficient-level test statistic.
Type of test statistic, usually "t" or "z".
Coefficient-level degrees of freedom, when available.
Coefficient-level p-value, when available.
Coefficient transformed into the
interpretation indicated by Estimate_type.
Lower confidence limit of the interpreted estimate.
Upper confidence limit of the interpreted estimate.
Interpretation of Interpreted_Estimate, such as
"Coefficient", "Odds ratio", "Risk ratio",
"Incidence rate ratio", "Hazard ratio", or "Multiplicative ratio".
Approximate Cohen's d.
Lower confidence limit of approximate Cohen's d.
Upper confidence limit of approximate Cohen's d.
Conversion used for d: "log odds ratio", "t", or
"z"; NA when no conversion was possible.
The coefficient transformation is based on the model family and link
detected through stats::family() whenever available. Some model classes
may use non-standard structures or parameterizations and may therefore
require transform = "none" or transform = "exponentiate" to override
automatic behaviour.
In models with multiple components, the interpretation may depend on the
component selected through component.
Chinn, S. (2000). A simple method for converting an odds ratio to effect size for use in meta-analysis. Statistics in Medicine, 19(22), 3127-3131.
set.seed(123)
# Linear regression
dat_lm <- data.frame(
y = rnorm(120),
x = rnorm(120),
group = factor(rep(c("A", "B", "C"), each = 40))
)
contrasts(dat_lm$group) <- contr.sum(3)
mod_lm <- lm(y ~ x + group, data = dat_lm)
extract_param(mod_lm)
# Binomial logistic regression
dat_glm <- data.frame(
y = rbinom(200, size = 1, prob = 0.40),
x = rnorm(200),
group = factor(sample(c("A", "B", "C"), 200, replace = TRUE))
)
contrasts(dat_glm$group) <- contr.sum(3)
mod_glm <- glm(
y ~ x + group,
data = dat_glm,
family = binomial(link = "logit")
)
extract_param(mod_glm)
# Disable automatic coefficient transformation
extract_param(mod_glm, transform = "none")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.