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)
}
Run the code above in your browser using DataLab