Learn R Programming

parameters (version 0.22.0)

display.parameters_model: Print tables in different output formats

Description

Prints tables (i.e. data frame) in different output formats. print_md() is an alias for display(format = "markdown"), print_html() is an alias for display(format = "html"). print_table() is for specific use cases only, and currently only works for compare_parameters() objects.

Usage

# S3 method for parameters_model
display(
  object,
  format = "markdown",
  pretty_names = TRUE,
  split_components = TRUE,
  select = NULL,
  caption = NULL,
  subtitle = NULL,
  footer = NULL,
  align = NULL,
  digits = 2,
  ci_digits = digits,
  p_digits = 3,
  footer_digits = 3,
  ci_brackets = c("(", ")"),
  show_sigma = FALSE,
  show_formula = FALSE,
  zap_small = FALSE,
  font_size = "100%",
  line_padding = 4,
  column_labels = NULL,
  include_reference = FALSE,
  verbose = TRUE,
  ...
)

# S3 method for parameters_sem display( object, format = "markdown", digits = 2, ci_digits = digits, p_digits = 3, ci_brackets = c("(", ")"), ... )

# S3 method for parameters_efa_summary display(object, format = "markdown", digits = 3, ...)

# S3 method for parameters_efa display( object, format = "markdown", digits = 2, sort = FALSE, threshold = NULL, labels = NULL, ... )

# S3 method for equivalence_test_lm display(object, format = "markdown", digits = 2, ...)

print_table(x, digits = 2, p_digits = 3, theme = "default", ...)

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. For print_table(), an object of class tinytable is returned.

Arguments

object

An object returned by model_parameters(),simulate_parameters(), equivalence_test() or principal_components().

format

String, indicating the output format. Can be "markdown" or "html".

pretty_names

Can be TRUE, which will return "pretty" (i.e. more human readable) parameter names. Or "labels", in which case value and variable labels will be used as parameters names. The latter only works for "labelled" data, i.e. if the data used to fit the model had "label" and "labels" attributes. See also section Global Options to Customize Messages when Printing.

split_components

Logical, if TRUE (default), For models with multiple components (zero-inflation, smooth terms, ...), each component is printed in a separate table. If FALSE, model parameters are printed in a single table and a Component column is added to the output.

select

Determines which columns and and which layout columns are printed. There are three options for this argument:

  1. Selecting columns by name or index
    select can be a character vector (or numeric index) of column names that should be printed. There are two pre-defined options for selecting columns: select = "minimal" prints coefficients, confidence intervals and p-values, while select = "short" prints coefficients, standard errors and p-values.

  2. A string expression with layout pattern
    select is a string with "tokens" enclosed in braces. These tokens will be replaced by their associated columns, where the selected columns will be collapsed into one column. However, it is possible to create multiple columns as well. Following tokens are replaced by the related coefficients or statistics: {estimate}, {se}, {ci} (or {ci_low} and {ci_high}), {p} and {stars}. The token {ci} will be replaced by {ci_low}, {ci_high}. Furthermore, a | separates values into new cells/columns. If format = "html", a <br> inserts a line break inside a cell. See 'Examples'.

  3. A string indicating a pre-defined layout
    select can be one of the following string values, to create one of the following pre-defined column layouts:

    • "ci": Estimates and confidence intervals, no asterisks for p-values. This is equivalent to select = "{estimate} ({ci})".

    • "se": Estimates and standard errors, no asterisks for p-values. This is equivalent to select = "{estimate} ({se})".

    • "ci_p": Estimates, confidence intervals and asterisks for p-values. This is equivalent to select = "{estimate}{stars} ({ci})".

    • "se_p": Estimates, standard errors and asterisks for p-values. This is equivalent to select = "{estimate}{stars} ({se})"..

    • "ci_p2": Estimates, confidence intervals and numeric p-values, in two columns. This is equivalent to select = "{estimate} ({ci})|{p}".

    • "se_p2": Estimate, standard errors and numeric p-values, in two columns. This is equivalent to select = "{estimate} ({se})|{p}".

For model_parameters(), glue-like syntax is still experimental in the case of more complex models (like mixed models) and may not return expected results.

caption

Table caption as string. If NULL, depending on the model, either a default caption or no table caption is printed. Use caption = "" to suppress the table caption.

subtitle

Table title (same as caption) and subtitle, as strings. If NULL, no title or subtitle is printed, unless it is stored as attributes (table_title, or its alias table_caption, and table_subtitle). If x is a list of data frames, caption may be a list of table captions, one for each table.

footer

Can either be FALSE or an empty string (i.e. "") to suppress the footer, NULL to print the default footer, or a string. The latter will combine the string value with the default footer.

align

Only applies to HTML tables. May be one of "left", "right" or "center".

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, or digits = "signif5" for 5 significant figures (see also signif()).

footer_digits

Number of decimal places for values in the footer summary.

ci_brackets

Logical, if TRUE (default), CI-values are encompassed in square brackets (else in parentheses).

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 after digits decimal places. If FALSE, values with more decimal places than digits are printed in scientific notation.

font_size

For HTML tables, the font size.

line_padding

For HTML tables, the distance (in pixel) between lines.

column_labels

Labels of columns for HTML tables. If NULL, automatic column names are generated. See 'Examples'.

include_reference

Logical, if TRUE, the reference level of factors will be added to the parameters table. This is only relevant for models with categorical predictors. The coefficient for the reference level is always 0 (except when exponentiate = TRUE, then the coefficient will be 1), so this is just for completeness.

verbose

Toggle messages and warnings.

...

Arguments passed to or from other methods.

sort

Sort the loadings.

threshold

A value between 0 and 1 indicates which (absolute) values from the loadings should be removed. An integer higher than 1 indicates the n strongest loadings to retain. Can also be "max", in which case it will only display the maximum loading per variable (the most simple structure).

labels

A character vector containing labels to be added to the loadings data. Usually, the question related to the item.

x

An object returned by model_parameters().

theme

String, indicating the table theme. Can be one of "default", "grid", "striped", "bootstrap" or "darklines".

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.

print_table() is a special function for compare_parameters() objects, which prints the output as a formatted HTML table. It is still somewhat experimental, thus, only a fixed layout-style is available at the moment (columns for estimates, confidence intervals and p-values). However, it is possible to include other model components, like zero-inflation, or random effects in the table. See 'Examples'. An alternative is to set engine = "tt" in print_html() to use the tinytable package for creating HTML tables.

See Also

print.parameters_model() and print.compare_parameters()

Examples

Run this code
if (FALSE) { # require("gt", quietly = TRUE)
model <- lm(mpg ~ wt + cyl, data = mtcars)
mp <- model_parameters(model)
display(mp)

# \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")
)

# line break, unicode minus-sign
print_html(
  out,
  select = "{estimate}{stars}({ci_low} \u2212 {ci_high})",
  column_labels = c("Est. (95% CI)")
)
# }
}
if (FALSE) { # require("tinytable") && require("lme4") && require("glmmTMB")
# \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")
print_table(out)
# }
}

Run the code above in your browser using DataLab