R/tabularise.lm.R
tabularise_coef.lm.Rd
This function extracts and formats the table of coefficients from an lm
object, similar to stats::coef()
, but in a rich-formatted table using
{flextable}.
# S3 method for class 'lm'
tabularise_coef(
data,
header = FALSE,
title = header,
equation = header,
auto.labs = TRUE,
origdata = NULL,
labs = NULL,
lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")),
...,
kind = "ft"
)
An lm object
Logical. If TRUE
(FALSE
by default), a header is added to
the table. The header includes both the title and the equation (if
applicable). If set to FALSE
, neither the title nor the equation will be
displayed in the table header, even if the title
or equation
parameters
are provided.
If TRUE
(FALSE
by default) , add a title to the table header.
Default to the same value than header, except outside of a chunk where it is
FALSE
if a table caption is detected (tbl-cap
YAML entry).
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
TRUE
: The equation is generated and added to the table header. Its
parameters are also used in the "Term" column.
FALSE
(by default): No equation is generated or displayed, and its
parameters are not used in the "Term" column.
NA
: The equation is generated but not displayed in the table header.
Its parameters are used in the "Term" column.
Character string: A custom equation is provided directly and added to the table header.
If TRUE
(by default), use labels (and units) automatically
from data or origdata=
.
The original data set this model was fitted to. By default it
is NULL
and no label is used.
Labels to change the names of elements in the term
column of
the table. By default it is NULL
and nothing is changed.
The natural language to use. The default value can be set with,
e.g., options(SciViews_lang = "fr")
for French.
Additional arguments
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default).
A flextable object that you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
data(iris)
# Fit a simple linear model: Petal.Length as a function of Sepal.Length
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length)
tabularise::tabularise$coef(iris_lm)
Term
Estimate
Intercept
-7.10
Sepal.Length
1.86
# If the 'iris' dataset has labels and units, they can be used to enhance
# the output table
iris <- svBase::labelise(iris, self = FALSE, label = list(
Sepal.Length = "Length of the sepals",
Petal.Length = "Length of the petals",
Species = "Species"), units = c(rep("cm", 4), NA))
iris_lm1 <- lm(data = iris, Petal.Length ~ Sepal.Length + Species)
tabularise::tabularise$coef(iris_lm1)
Term
Estimate
Intercept
-1.702
Length of the sepals [cm]
0.632
Species [versicolor]
2.210
Species [virginica]
3.090
# The same table but without showing the model equation
tabularise::tabularise$coef(iris_lm, equation = FALSE)
Term
Estimate
Intercept
-7.10
Sepal.Length
1.86
iris_lm2 <- lm(data = iris, Petal.Length ~ Sepal.Length * Species)
tabularise::tabularise$coef(iris_lm2)
Term
Estimate
Intercept
0.803
Length of the sepals [cm]
0.132
Species [versicolor]
-0.618
Species [virginica]
-0.193
Length of the sepals [cm] x Species [versicolor]
0.555
Length of the sepals [cm] x Species [virginica]
0.618