check_path | R Documentation |
It checks whether a path, usually an indirect path, exists in a model.
check_path(x, y, m = NULL, fit = NULL, est = NULL)
x |
Character. The name of predictor at the start of the path. |
y |
Character. The name of the outcome variable at the end of the path. |
m |
A vector of the variable
names of the mediators. The path goes
from the first mediator successively
to the last mediator. If |
fit |
The fit object. Currently
only supports a
|
est |
The output of
|
It checks whether the path
defined by a predictor (x
), an
outcome (y
), and optionally a
sequence of mediators (m
), exists
in a model. It can check models in a
lavaan::lavaan-class
object or a
list of outputs of lm()
.
It also support
lavaan.mi
objects
returned by
semTools::runMI()
or
its wrapper, such as semTools::sem.mi()
.
For example, in the following model
in lavaan
syntax
m1 ~ x m2 ~ m1 m3 ~ x y ~ m2 + m3
This path is valid: x = "x", y = "y", m = c("m1", "m2")
This path is invalid: x = "x", y = "y", m = c("m2")
This path is also invalid: x = "x", y = "y", m = c("m1", "m2")
A logical vector of length
one. TRUE
if the path is valid,
FALSE
if the path is invalid.
library(lavaan)
data(data_serial_parallel)
dat <- data_serial_parallel
mod <-
"
m11 ~ x + c1 + c2
m12 ~ m11 + x + c1 + c2
m2 ~ x + c1 + c2
y ~ m12 + m2 + m11 + x + c1 + c2
"
fit <- sem(mod, dat,
meanstructure = TRUE, fixed.x = FALSE)
# The following paths are valid
check_path(x = "x", y = "y", m = c("m11", "m12"), fit = fit)
check_path(x = "x", y = "y", m = "m2", fit = fit)
# The following paths are invalid
check_path(x = "x", y = "y", m = c("m11", "m2"), fit = fit)
check_path(x = "x", y = "y", m = c("m12", "m11"), fit = fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.