
It computes the
Delta_Med proposed by Liu, Yuan,
and Li (2023), an
delta_med(
x,
y,
m,
fit,
paths_to_remove = NULL,
boot_out = NULL,
level = 0.95,
progress = TRUE,
skip_check_single_x = FALSE,
skip_check_m_between_x_y = FALSE,
skip_check_x_to_y = FALSE,
skip_check_latent_variables = FALSE,
boot_type = c("perc", "bc")
)
A delta_med
class object.
It is a list-like object with these
major elements:
delta_med
: The Delta_Med.
x
: The name of the x
-variable.
y
: The name of the y
-variable.
m
: A character vector of the
mediator(s) along a path. The path
runs from the first element to the
last element.
This class has a print
method,
a coef
method, and a confint
method. See print.delta_med()
,
coef.delta_med()
, and
confint.delta_med()
.
The name of the x
variable.
Must be supplied as a quoted string.
The name of the y
variable.
Must be supplied as a quoted string.
A vector of the variable
names of the mediator(s). If more
than one mediators, they do not have
to be on the same path from x
to y
.
Cannot be NULL
for this function.
The fit object. Must be a lavaan::lavaan object.
A character
vector of paths users want to
manually remove, specified in
lavaan
model syntax. For example,
c("m2~x", "m3~m2")
removes the
path from x
to m2
and the path
from m2
to m3
. The default is
NULL
, and the paths to remove will
be determined using the method
by Liu et al. (2023). If supplied,
then only paths specified explicitly
will be removed.
The
output of do_boot()
. If supplied,
the stored bootstrap estimates will
be used to form the nonparametric
percentile bootstrap confidence
interval of Delta_Med.
The level of confidence of the bootstrap confidence interval. Default is .95.
Logical. Display
bootstrapping progress or not.
Default is TRUE
.
Logical
Check whether the model has one and
only one x-variable. Default is TRUE
.
Logical. Check whether all m
variables are along a path from x
to y
. Default is TRUE
.
Logical.
Check whether there is a direct path
from x
to y
. Default is TRUE
.
Logical. Check whether the model
has any latent variables. Default
is TRUE
.
If bootstrap
confidence interval is to be formed,
the type of bootstrap confidence
interval. The supported types
are "perc"
(percentile bootstrap
confidence interval, the default and
recommended type) and "bc"
(bias-corrected, or BC, bootstrap
confidence interval).
The function identifies all the
path(s) pointing to the mediator(s)
of concern and fixes the path(s) to
zero, effectively removing the
mediator(s). However, the model is
not refitted, hence keeping the
estimates of all other parameters
unchanged.
It then uses lavaan::lav_model_set_parameters()
to update the parameters,
lavaan::lav_model_implied()
to
update the implied statistics, and
then calls lavaan::lavInspect()
to
retrieve the implied variance of the
predicted values of y
for computing
the y
can then yield Delta_Med.
For now, by default, it only computes Delta_Med for the types of models discussed in Liu et al. (2023):
Having one predictor (the
x
-variable).
Having one or more mediators, the
m
-variables, with
arbitrary way to mediate the effect
of x
on the outcome variable
(y
-variable).
Having one or more outcome variables. Although their models only have outcome variables, the computation of the Delta_Med is not affected by the presence of other outcome variables.
Having no control variables.
The mediator(s), m
, and the
y
-variable are continuous.
x
can be continuous
or categorical. If categorical, it
needs to be handle appropriately
when fitting the model.
x
has a direct
path to y
.
All the mediators listed in the
argument m
is present in at least
one path from x
to y.
None of the paths from x
to y
are moderated.
It can be used for other kinds
of models but support for them is
disabled by default. To use
this function for
cases not discussed in
Liu et al. (2023), please disable
relevant requirements stated above
using the relevant
skip_check_*
arguments. An error
will be raised if the models failed
any of the checks not skipped by
users.
It computes Delta_Med, an
y
-variable)
to another variable (the x
-variable)
through one or more mediators
(m
, or m1
, m2
, etc. when
there are more than one mediator).
The Delta_Med of one or more
mediators was computed as the
difference between
two
y
is predicted by x
and all
mediators.
Delta_Med is given by
Please refer to Liu et al. (2023) for the technical details.
The function can also form a nonparametric percentile bootstrap confidence of Delta_Med.
Liu, H., Yuan, K.-H., & Li, H. (2023). A systematic framework for defining R-squared measures in mediation analysis. Psychological Methods. Advance online publication. https://doi.org/10.1037/met0000571
print.delta_med()
,
coef.delta_med()
, and
confint.delta_med()
.
library(lavaan)
dat <- data_med
mod <-
"
m ~ x
y ~ m + x
"
fit <- sem(mod, dat)
dm <- delta_med(x = "x",
y = "y",
m = "m",
fit = fit)
dm
print(dm, full = TRUE)
# Call do_boot() to generate
# bootstrap estimates
# Use 2000 or even 5000 for R in real studies
# Set parallel to TRUE in real studies for faster bootstrapping
boot_out <- do_boot(fit,
R = 45,
seed = 879,
parallel = FALSE,
progress = FALSE)
# Remove 'progress = FALSE' in practice
dm_boot <- delta_med(x = "x",
y = "y",
m = "m",
fit = fit,
boot_out = boot_out,
progress = FALSE)
dm_boot
confint(dm_boot)
Run the code above in your browser using DataLab