all_indirect_paths {manymome} | R Documentation |
Enumerate All Indirect Effects in a Model
Description
Check all indirect paths in a model and
return them as a list of arguments of x
, y
,
and m
, to be used by indirect_effect()
.
Usage
all_indirect_paths(
fit = NULL,
exclude = NULL,
x = NULL,
y = NULL,
group = NULL
)
all_paths_to_df(all_paths)
Arguments
fit |
A fit object. Either the output of
|
exclude |
A character vector of variables to be excluded in the search, such as control variables. |
x |
A character vector of variables that will be
included as the |
y |
A character vector of variables that will be
included as the |
group |
Either the group number
as appeared in the |
all_paths |
An |
Details
It makes use of igraph::all_simple_paths()
to identify paths in a model.
Multigroup Models
Since Version 0.1.14.2, support for
multigroup models has been added for models
fitted by lavaan
. If a model has more
than one group and group
is not
specified, than paths in all groups
will be returned. If group
is
specified, than only paths in the
selected group will be returned.
Value
all_indirect_paths()
returns
a list of the class all_paths
. Each argument is a
list of three character vectors,
x
, the name of the predictor that starts a path, y
,
the name of the outcome that ends a path, and m
, a
character vector of one or more names of the mediators,
from x
to y
. This class has a print method.
all_paths_to_df()
returns a data frame with three
columns, x
, y
, and m
, which can be used by
functions such as indirect_effect()
.
Functions
-
all_indirect_paths()
: Enumerate all indirect paths. -
all_paths_to_df()
: Convert the output ofall_indirect_paths()
to a data frame with three columns:x
,y
, andm
.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
See Also
indirect_effect()
, lm2list()
.
many_indirect_effects()
Examples
library(lavaan)
data(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, data_serial_parallel,
fixed.x = FALSE)
# All indirect paths
out1 <- all_indirect_paths(fit)
out1
names(out1)
# Exclude c1 and c2 in the search
out2 <- all_indirect_paths(fit, exclude = c("c1", "c2"))
out2
names(out2)
# Exclude c1 and c2, and only consider paths start
# from x and end at y
out3 <- all_indirect_paths(fit, exclude = c("c1", "c2"),
x = "x",
y = "y")
out3
names(out3)
# Multigroup models
data(data_med_complicated_mg)
mod <-
"
m11 ~ x1 + x2 + c1 + c2
m12 ~ m11 + c1 + c2
m2 ~ x1 + x2 + c1 + c2
y1 ~ m11 + m12 + x1 + x2 + c1 + c2
y2 ~ m2 + x1 + x2 + c1 + c2
"
fit <- sem(mod, data_med_complicated_mg, group = "group")
summary(fit)
all_indirect_paths(fit,
x = "x1",
y = "y1")
all_indirect_paths(fit,
x = "x1",
y = "y1",
group = 1)
all_indirect_paths(fit,
x = "x1",
y = "y1",
group = "Group B")