Prints tables (i.e. data frame) in different output formats.
print_md()
is an alias for display(format = "markdown")
and
print_html()
is an alias for display(format = "html")
. A third option is
display(format = "tt")
, which returns a tinytable
object, which is either
printed as markdown or HTML table, depending on the environment.
Usage
# S3 method for class 'parameters_model'
display(object, format = "markdown", ...)
Arguments
- object
An object returned by one of the package's function, for example
model_parameters()
,simulate_parameters()
,equivalence_test()
orprincipal_components()
.- format
String, indicating the output format. Can be
"markdown"
"html"
, or"tt"
.format = "tt"
creates atinytable
object, which is either printed as markdown or HTML table, depending on the environment. Seeinsight::export_table()
for details.- ...
Arguments passed to the underlying functions, such as
print_md()
orprint_html()
.
Value
If format = "markdown"
, the return value will be a character
vector in markdown-table format. If format = "html"
, an object of
class gt_tbl
. If format = "tt"
, an object of class tinytable
.
Details
display()
is useful when the table-output from functions,
which is usually printed as formatted text-table to console, should
be formatted for pretty table-rendering in markdown documents, or if
knitted from rmarkdown to PDF or Word files. See
vignette
for examples.
Examples
model <- lm(mpg ~ wt + cyl, data = mtcars)
mp <- model_parameters(model)
display(mp)
#>
#>
#> |Parameter | Coefficient | SE | 95% CI | t(29) | p |
#> |:-----------|:-----------:|:----:|:--------------:|:-----:|:------:|
#> |(Intercept) | 39.69 | 1.71 | (36.18, 43.19) | 23.14 | < .001 |
#> |wt | -3.19 | 0.76 | (-4.74, -1.64) | -4.22 | < .001 |
#> |cyl | -1.51 | 0.41 | (-2.36, -0.66) | -3.64 | 0.001 |
# \donttest{
data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
out <- compare_parameters(lm1, lm2, lm3)
print_html(
out,
select = "{coef}{stars}|({ci})",
column_labels = c("Estimate", "95% CI")
)
Estimate
95% CI
Estimate
95% CI
Estimate
95% CI
# line break, unicode minus-sign
print_html(
out,
select = "{estimate}{stars}<br>({ci_low} \u2212 {ci_high})",
column_labels = c("Est. (95% CI)")
)
Parameter
Est. (95% CI)
Est. (95% CI)
Est. (95% CI)
# }
# \donttest{
data(iris)
data(Salamanders, package = "glmmTMB")
m1 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
m2 <- lme4::lmer(
Sepal.Length ~ Petal.Length + Petal.Width + (1 | Species),
data = iris
)
m3 <- glmmTMB::glmmTMB(
count ~ spp + mined + (1 | site),
ziformula = ~mined,
family = poisson(),
data = Salamanders
)
out <- compare_parameters(m1, m2, m3, effects = "all", component = "all")
display(out, format = "tt")
#>
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Parameter | m1 | m2 | m3 |
#> +=====================================+==========================+=====================+==========================+
#> | Fixed Effects |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | (Intercept) | 4.21 ( 3.41, 5.02) | 2.51 ( 1.20, 3.83) | -0.36 ( -0.90, 0.18) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Species (versicolor) × Petal Length | 0.29 ( -0.30, 0.87) | | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Petal Length | 0.54 (-4.76e-03, 1.09) | 0.89 ( 0.75, 1.04) | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Species (versicolor) | -1.81 ( -2.99, -0.62) | | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Species (virginica) | -3.15 ( -4.41, -1.90) | | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Species (virginica) × Petal Length | 0.45 ( -0.12, 1.03) | | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Petal Width | | -0.02 (-0.33, 0.28) | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | spp (EC-L) | | | 0.67 ( 0.41, 0.92) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | spp (PR) | | | -1.27 ( -1.74, -0.80) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | spp (DM) | | | 0.27 (-1.52e-03, 0.54) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | spp (EC-A) | | | -0.57 ( -0.97, -0.16) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | spp (DES-L) | | | 0.63 ( 0.38, 0.87) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | spp (DF) | | | 0.12 ( -0.17, 0.40) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | mined (no) | | | 1.27 ( 0.74, 1.80) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Fixed Effects (Zero-Inflation Component) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | (Intercept) | | | 0.79 ( 0.26, 1.32) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | minedno | | | -1.84 ( -2.46, -1.23) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | Random Effects |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | SD (Residual) | | 0.34 ( 0.30, 0.38) | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | SD (Intercept: Species) | | 1.07 ( 0.39, 2.91) | |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
#> | SD (Intercept: site) | | | 0.33 ( 0.18, 0.63) |
#> +-------------------------------------+--------------------------+---------------------+--------------------------+
display(out, select = "{estimate}|{ci}", format = "tt")
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | | m1 | m2 | m3 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Parameter | Coefficient | CI | Coefficient | CI | Log-Mean | CI |
#> +=====================================+=============+==================+=============+=============+==========+==================+
#> | Fixed Effects |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | (Intercept) | 4.21 | 3.41, 5.02 | 2.51 | 1.20, 3.83 | -0.36 | -0.90, 0.18 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Species (versicolor) × Petal Length | 0.29 | -0.30, 0.87 | | | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Petal Length | 0.54 | -4.76e-03, 1.09 | 0.89 | 0.75, 1.04 | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Species (versicolor) | -1.81 | -2.99, -0.62 | | | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Species (virginica) | -3.15 | -4.41, -1.90 | | | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Species (virginica) × Petal Length | 0.45 | -0.12, 1.03 | | | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Petal Width | | | -0.02 | -0.33, 0.28 | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | spp (EC-L) | | | | | 0.67 | 0.41, 0.92 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | spp (PR) | | | | | -1.27 | -1.74, -0.80 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | spp (DM) | | | | | 0.27 | -1.52e-03, 0.54 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | spp (EC-A) | | | | | -0.57 | -0.97, -0.16 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | spp (DES-L) | | | | | 0.63 | 0.38, 0.87 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | spp (DF) | | | | | 0.12 | -0.17, 0.40 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | mined (no) | | | | | 1.27 | 0.74, 1.80 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Fixed Effects (Zero-Inflation Component) |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | (Intercept) | | | | | 0.79 | 0.26, 1.32 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | minedno | | | | | -1.84 | -2.46, -1.23 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | Random Effects |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | SD (Residual) | | | 0.34 | 0.30, 0.38 | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | SD (Intercept: Species) | | | 1.07 | 0.39, 2.91 | | |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
#> | SD (Intercept: site) | | | | | 0.33 | 0.18, 0.63 |
#> +-------------------------------------+-------------+------------------+-------------+-------------+----------+------------------+
# }