A print()
-method for objects from model_parameters()
.
Usage
# S3 method for parameters_model
print(
x,
pretty_names = TRUE,
split_components = TRUE,
select = NULL,
caption = NULL,
digits = 2,
ci_digits = 2,
p_digits = 3,
footer_digits = 3,
show_sigma = FALSE,
show_formula = FALSE,
zap_small = FALSE,
groups = NULL,
column_width = NULL,
ci_brackets = c("[", "]"),
...
)
# S3 method for parameters_model
summary(object, ...)
Arguments
- x, object
An object returned by
model_parameters()
.- pretty_names
Return "pretty" (i.e. more human readable) parameter names.
- split_components
Logical, if
TRUE
(default), For models with multiple components (zero-inflation, smooth terms, ...), each component is printed in a separate table. IfFALSE
, model parameters are printed in a single table and aComponent
column is added to the output.- select
Character vector (or numeric index) of column names that should be printed. If
NULL
(default), all columns are printed. The shortcutselect = "minimal"
prints coefficient, confidence intervals and p-values, whileselect = "short"
prints coefficient, standard errors and p-values.- caption
Table caption as string. If
NULL
, no table caption is printed.- digits, ci_digits, p_digits
Number of digits for rounding or significant figures. May also be
"signif"
to return significant figures or"scientific"
to return scientific notation. Control the number of digits by adding the value as suffix, e.g.digits = "scientific4"
to have scientific notation with 4 decimal places, ordigits = "signif5"
for 5 significant figures (see alsosignif()
).- footer_digits
Number of decimal places for values in the footer summary.
- show_sigma
Logical, if
TRUE
, adds information about the residual standard deviation.- show_formula
Logical, if
TRUE
, adds the model formula to the output.- zap_small
Logical, if
TRUE
, small values are rounded afterdigits
decimal places. IfFALSE
, values with more decimal places thandigits
are printed in scientific notation.- groups
Named list, can be used to group parameters in the printed output. List elements may either be character vectors that match the name of those parameters that belong to one group, or list elements can be row numbers of those parameter rows that should belong to one group. The names of the list elements will be used as group names, which will be inserted as "header row". A possible use case might be to emphasize focal predictors and control variables, see 'Examples'. Parameters will be re-ordered according to the order used in
groups
, while all non-matching parameters will be added to the end.- column_width
Width of table columns. Can be either
NULL
, a named numeric vector, or"fixed"
. IfNULL
, the width for each table column is adjusted to the minimum required width. If a named numeric vector, value names are matched against column names, and for each match, the specified width is used. If"fixed"
, and table is split into multiple components, columns across all table components are adjusted to have the same width.- ci_brackets
Logical, if
TRUE
(default), CI-values are encompassed in square brackets (else in parentheses).- ...
Arguments passed to or from other methods.
Details
summary()
is a convenient shortcut for
print(object, select = "minimal", show_sigma = TRUE, show_formula = TRUE)
.
Interpretation of Interaction Terms
Note that the interpretation of interaction terms depends on many
characteristics of the model. The number of parameters, and overall
performance of the model, can differ or not between a * b
a : b
, and a / b
, suggesting that sometimes interaction terms
give different parameterizations of the same model, but other times it gives
completely different models (depending on a
or b
being factors
of covariates, included as main effects or not, etc.). Their interpretation
depends of the full context of the model, which should not be inferred
from the parameters table alone - rather, we recommend to use packages
that calculate estimated marginal means or marginal effects, such as
modelbased, emmeans, ggeffects, or
marginaleffects. To raise awareness for this issue, you may use
print(...,show_formula=TRUE)
to add the model-specification to the output
of the print()
method for model_parameters()
.
Labeling the Degrees of Freedom
Throughout the parameters package, we decided to label the residual
degrees of freedom df_error. The reason for this is that these degrees
of freedom not always refer to the residuals. For certain models, they refer
to the estimate error - in a linear model these are the same, but in - for
instance - any mixed effects model, this isn't strictly true. Hence, we
think that df_error
is the most generic label for these degrees of
freedom.
See also
There is a dedicated method to use inside rmarkdown files,
print_md()
.
Examples
# \donttest{
library(parameters)
if (require("glmmTMB", quietly = TRUE)) {
model <- glmmTMB(
count ~ spp + mined + (1 | site),
ziformula = ~mined,
family = poisson(),
data = Salamanders
)
mp <- model_parameters(model)
print(mp, pretty_names = FALSE)
print(mp, split_components = FALSE)
print(mp, select = c("Parameter", "Coefficient", "SE"))
print(mp, select = "minimal")
}
#> # Fixed Effects (Count Model)
#>
#> Parameter | Log-Mean | SE | 95% CI | z | p
#> ---------------------------------------------------------------
#> (Intercept) | -0.36 | 0.28 | [-0.90, 0.18] | -1.30 | 0.194
#> sppPR | -1.27 | 0.24 | [-1.74, -0.80] | -5.27 | < .001
#> sppDM | 0.27 | 0.14 | [ 0.00, 0.54] | 1.95 | 0.051
#> sppEC-A | -0.57 | 0.21 | [-0.97, -0.16] | -2.75 | 0.006
#> sppEC-L | 0.67 | 0.13 | [ 0.41, 0.92] | 5.20 | < .001
#> sppDES-L | 0.63 | 0.13 | [ 0.38, 0.87] | 4.96 | < .001
#> sppDF | 0.12 | 0.15 | [-0.17, 0.40] | 0.78 | 0.435
#> minedno | 1.27 | 0.27 | [ 0.74, 1.80] | 4.72 | < .001
#>
#> # Fixed Effects (Zero-Inflated Model)
#>
#> Parameter | Log-Odds | SE | 95% CI | z | p
#> ---------------------------------------------------------------
#> (Intercept) | 0.79 | 0.27 | [ 0.26, 1.32] | 2.90 | 0.004
#> minedno | -1.84 | 0.31 | [-2.46, -1.23] | -5.87 | < .001
#>
#> # Random Effects Variances
#>
#> Parameter | Coefficient | 95% CI
#> -------------------------------------------------
#> SD (Intercept: site) | 0.33 | [0.18, 0.63]
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald z-distribution approximation.
#> # Fixed Effects
#>
#> Parameter | Coefficient | SE | 95% CI | z | p | Effects | Component
#> -----------------------------------------------------------------------------------------------------
#> (Intercept) | -0.36 | 0.28 | [-0.90, 0.18] | -1.30 | 0.194 | fixed | conditional
#> spp [PR] | -1.27 | 0.24 | [-1.74, -0.80] | -5.27 | < .001 | fixed | conditional
#> spp [DM] | 0.27 | 0.14 | [ 0.00, 0.54] | 1.95 | 0.051 | fixed | conditional
#> spp [EC-A] | -0.57 | 0.21 | [-0.97, -0.16] | -2.75 | 0.006 | fixed | conditional
#> spp [EC-L] | 0.67 | 0.13 | [ 0.41, 0.92] | 5.20 | < .001 | fixed | conditional
#> spp [DES-L] | 0.63 | 0.13 | [ 0.38, 0.87] | 4.96 | < .001 | fixed | conditional
#> spp [DF] | 0.12 | 0.15 | [-0.17, 0.40] | 0.78 | 0.435 | fixed | conditional
#> mined [no] | 1.27 | 0.27 | [ 0.74, 1.80] | 4.72 | < .001 | fixed | conditional
#> (Intercept) | 0.79 | 0.27 | [ 0.26, 1.32] | 2.90 | 0.004 | fixed | zero_inflated
#> minedno | -1.84 | 0.31 | [-2.46, -1.23] | -5.87 | < .001 | fixed | zero_inflated
#> SD (Intercept: site) | 0.33 | | [ 0.18, 0.63] | | | random | conditional
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald z-distribution approximation.
#> # Fixed Effects (Count Model)
#>
#> Parameter | Log-Mean | SE
#> -----------------------------
#> (Intercept) | -0.36 | 0.28
#> spp [PR] | -1.27 | 0.24
#> spp [DM] | 0.27 | 0.14
#> spp [EC-A] | -0.57 | 0.21
#> spp [EC-L] | 0.67 | 0.13
#> spp [DES-L] | 0.63 | 0.13
#> spp [DF] | 0.12 | 0.15
#> mined [no] | 1.27 | 0.27
#>
#> # Fixed Effects (Zero-Inflated Model)
#>
#> Parameter | Log-Odds | SE
#> -----------------------------
#> (Intercept) | 0.79 | 0.27
#> mined [no] | -1.84 | 0.31
#>
#> # Random Effects Variances
#>
#> Parameter | Coefficient
#> ----------------------------------
#> SD (Intercept: site) | 0.33
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald z-distribution approximation.
#> # Fixed Effects (Count Model)
#>
#> Parameter | Log-Mean | 95% CI | p
#> ------------------------------------------------
#> (Intercept) | -0.36 | [-0.90, 0.18] | 0.194
#> spp [PR] | -1.27 | [-1.74, -0.80] | < .001
#> spp [DM] | 0.27 | [ 0.00, 0.54] | 0.051
#> spp [EC-A] | -0.57 | [-0.97, -0.16] | 0.006
#> spp [EC-L] | 0.67 | [ 0.41, 0.92] | < .001
#> spp [DES-L] | 0.63 | [ 0.38, 0.87] | < .001
#> spp [DF] | 0.12 | [-0.17, 0.40] | 0.435
#> mined [no] | 1.27 | [ 0.74, 1.80] | < .001
#>
#> # Fixed Effects (Zero-Inflated Model)
#>
#> Parameter | Log-Odds | 95% CI | p
#> ------------------------------------------------
#> (Intercept) | 0.79 | [ 0.26, 1.32] | 0.004
#> mined [no] | -1.84 | [-2.46, -1.23] | < .001
#>
#> # Random Effects Variances
#>
#> Parameter | Coefficient | 95% CI
#> -------------------------------------------------
#> SD (Intercept: site) | 0.33 | [0.18, 0.63]
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald z-distribution approximation.
# group parameters ------
data(iris)
model <- lm(
Sepal.Width ~ Sepal.Length + Species + Petal.Length,
data = iris
)
# don't select "Intercept" parameter
mp <- model_parameters(model, parameters = "^(?!\\(Intercept)")
groups <- list(
"Focal Predictors" = c("Speciesversicolor", "Speciesvirginica"),
"Controls" = c("Sepal.Length", "Petal.Length")
)
print(mp, groups = groups)
#> Parameter | Coefficient | SE | 95% CI | t(145) | p
#> ------------------------------------------------------------------------------
#> Focal Predictors | | | | |
#> Species [versicolor] | -0.89 | 0.20 | [-1.29, -0.49] | -4.43 | < .001
#> Species [virginica] | -0.88 | 0.28 | [-1.43, -0.33] | -3.15 | 0.002
#> Controls | | | | |
#> Sepal Length | 0.38 | 0.07 | [ 0.24, 0.52] | 5.31 | < .001
#> Petal Length | -0.04 | 0.08 | [-0.21, 0.13] | -0.50 | 0.618
#> (Intercept) | 1.60 | 0.28 | [ 1.06, 2.15] | 5.80 | < .001
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald t-distribution approximation.
# or use row indices
print(mp, groups = list(
"Focal Predictors" = c(1, 4),
"Controls" = c(2, 3)
))
#> Parameter | Coefficient | SE | 95% CI | t(145) | p
#> ------------------------------------------------------------------------------
#> Focal Predictors | | | | |
#> (Intercept) | 1.60 | 0.28 | [ 1.06, 2.15] | 5.80 | < .001
#> Species [virginica] | -0.88 | 0.28 | [-1.43, -0.33] | -3.15 | 0.002
#> Controls | | | | |
#> Sepal Length | 0.38 | 0.07 | [ 0.24, 0.52] | 5.31 | < .001
#> Species [versicolor] | -0.89 | 0.20 | [-1.29, -0.49] | -4.43 | < .001
#> Petal Length | -0.04 | 0.08 | [-0.21, 0.13] | -0.50 | 0.618
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald t-distribution approximation.
# only show coefficients, CI and p,
# put non-matched parameters to the end
data(mtcars)
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$gear <- as.factor(mtcars$gear)
model <- lm(mpg ~ hp + gear * vs + cyl + drat, data = mtcars)
# don't select "Intercept" parameter
mp <- model_parameters(model, parameters = "^(?!\\(Intercept)")
print(mp, groups = list(
"Engine" = c("cyl6", "cyl8", "vs", "hp"),
"Interactions" = c("gear4:vs", "gear5:vs")
))
#> Parameter | Coefficient | SE | 95% CI | t(22) | p
#> -----------------------------------------------------------------------
#> Engine | | | | |
#> cyl [6] | -2.47 | 2.21 | [ -7.05, 2.12] | -1.12 | 0.276
#> cyl [8] | 1.97 | 5.11 | [ -8.63, 12.58] | 0.39 | 0.703
#> vs | 3.18 | 3.79 | [ -4.68, 11.04] | 0.84 | 0.410
#> hp | -0.06 | 0.02 | [ -0.11, -0.02] | -2.91 | 0.008
#> Interactions | | | | |
#> gear [4] * vs | -2.90 | 4.67 | [-12.57, 6.78] | -0.62 | 0.541
#> gear [5] * vs | 2.59 | 4.54 | [ -6.82, 12.00] | 0.57 | 0.574
#> (Intercept) | 16.63 | 7.77 | [ 0.53, 32.74] | 2.14 | 0.044
#> gear [4] | 3.10 | 4.34 | [ -5.90, 12.10] | 0.71 | 0.482
#> gear [5] | 4.80 | 3.48 | [ -2.42, 12.01] | 1.38 | 0.182
#> drat | 2.70 | 2.03 | [ -1.52, 6.91] | 1.33 | 0.198
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald t-distribution approximation.
# }