lm_list_to_partable {lmhelprs} | R Documentation |
Convert a 'lm_list' Object To a Parameter Table
Description
Convert the output of
many_lm()
to a lavann
-style
parameter table.
Usage
lm_list_to_partable(
object,
keep_intercepts = FALSE,
vcov_args = list(),
pvalue_fun = NULL,
rsquare = FALSE,
ci = FALSE,
ci_fun = stats::confint,
ci_args = list(level = 0.95)
)
Arguments
object |
The output of
|
keep_intercepts |
Logical. If
|
vcov_args |
A named list of
arguments to be passed to |
pvalue_fun |
The function to be used to compute the p-values of regression coefficients. Ignored for now. Included for adding this feature in the future. |
rsquare |
Logical. Whether
R-squares will be included in the
output, with |
ci |
Logical. If |
ci_fun |
The function to be used
to form the confidence intervals for
regression coefficients. Default
is |
ci_args |
A named list of
arguments to be passed to |
Details
This function convert a a
lit of lm
objects, such as the
output of many_lm()
or
manymome::lm2list()
, to a table of
parameter estimates similar to the
output of lavaan::parameterTable.
The output is designed to be used by
semPlot::semPaths()
and so contains
only information necessary for the
plot.
The output of stats::lm()
is
already supported by
semPlot::semPaths()
, and it can
also combine a list of regression
models into on single plot. However,
it will convert interaction terms to
knots. Moreover, if two interaction
terms in two different models share
the a variable, it will be incorrectly
combined to become a single knot
(Version 1.1.6). Therefore, this
function was developed to let users
to draw the model as if it were a
path model in structural equation
modeling.
Value
A data frame object with columns such
as lhs
, op
, rhs
, and est
,
major columns of the output of
lavaan::parameterTable()
necessary
for plotting the model using
semPlot::semPaths()
.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
See Also
many_lm()
and manymome::lm2list()
.
Examples
data(data_test1)
mod <- "x3 ~ x2*x1
x4 ~ x3
x5 ~ x4 + x3"
out <- many_lm(mod, data_test1)
out_ptable <- lm_list_to_partable(out)
out_ptable
m <- matrix(c("x1", "x2", "x2:x1", NA, "x3", NA, "x4", NA, NA, NA, "x5", NA),
nrow = 3, ncol = 4)
m
# The output can be used by semPlot::semPaths()
if (requireNamespace("semPlot", quietly = TRUE)) {
library(semPlot)
p <- semPaths(out_ptable,
what = "paths",
whatLabels = "est",
nCharNodes = 0,
style = "ram",
layout = m,
exoCov = FALSE,
DoNotPlot = TRUE)
plot(p)
# If it is desired to use knots to
# denote interaction terms, then,
# the output of many_lm() can be used
# directly.
m2 <- matrix(c("x1", NA, "x2", NA, "x3", NA, "x4", NA, NA, NA, "x5", NA),
nrow = 3, ncol = 4)
p2 <- semPaths(out,
what = "paths",
whatLabels = "est",
nCharNodes = 0,
style = "ram",
layout = m2,
exoCov = FALSE,
intercepts = FALSE,
DoNotPlot = TRUE)
plot(p2)
# This illustrates the problem with using
# the list of lm-outputs directly when
# a variable is involved in the interaction terms
# of two or more models.
m3 <- matrix(c("x2", NA, "x1", NA, "x3",
NA, NA, NA, NA, NA,
NA, "x4", NA, "x5", NA),
nrow = 5, ncol = 3)
mod3 <- "x4 ~ x2*x1
x5 ~ x3*x1"
out3 <- many_lm(mod3, data_test1)
p3 <- semPaths(out3,
what = "paths",
whatLabels = "est",
nCharNodes = 0,
style = "ram",
layout = m3,
exoCov = FALSE,
intercepts = FALSE,
DoNotPlot = TRUE)
plot(p3)
}