plot.cond_indirect_effects | R Documentation |
Plot the conditional effects for different levels of moderators.
## S3 method for class 'cond_indirect_effects'
plot(
x,
x_label,
w_label = "Moderator(s)",
y_label,
title,
x_from_mean_in_sd = 1,
x_method = c("sd", "percentile"),
x_percentiles = c(0.16, 0.84),
x_sd_to_percentiles = NA,
note_standardized = TRUE,
no_title = FALSE,
line_width = 1,
point_size = 5,
graph_type = c("default", "tumble"),
use_implied_stats = TRUE,
facet_grid_cols = NULL,
facet_grid_rows = NULL,
facet_grid_args = list(as.table = FALSE, labeller = "label_both"),
digits = 4,
...
)
x |
The output of
|
x_label |
The label for the
X-axis. Default is the value of the
predictor in the output of
|
w_label |
The label for the
legend for the lines. Default is
|
y_label |
The label for the Y-axis. Default is the name of the response variable in the model. |
title |
The title of the graph.
If not supplied, it will be generated
from the variable names or labels (in
|
x_from_mean_in_sd |
How many SD from mean is used to define "low" and "high" for the focal variable. Default is 1. |
x_method |
How to define "high"
and "low" for the focal variable
levels. Default is in terms of the
standard deviation of the focal
variable, |
x_percentiles |
If |
x_sd_to_percentiles |
If
|
note_standardized |
If |
no_title |
If |
line_width |
The width of the
lines as used in
|
point_size |
The size of the
points as used in
|
graph_type |
If |
use_implied_stats |
For a
multigroup model, if |
facet_grid_cols , facet_grid_rows |
If either or both of them are set
to character vector(s) of moderator
names, then |
facet_grid_args |
The list of
arguments to be used in calling
|
digits |
The number of decimal
places to be printed for numerical
moderators when |
... |
Additional arguments. Ignored. |
This function is a plot
method of the output of
cond_indirect_effects()
. It will
use the levels of moderators in the
output.
It plots the conditional effect from
x
to y
in a model for different
levels of the moderators. For
multigroup models, the group will
be the 'moderator' and one line is
drawn for each group.
It does not support conditional
indirect effects. If there is one or
more mediators in x
, it will raise
an error.
Since Version 0.1.14.2, support for
multigroup models has been added for models
fitted by lavaan
. If the effect
for each group is drawn, the
graph_type
is automatically switched
to "tumble"
and the means and SDs
in each group will be used to determine
the locations of the points.
If the multigroup model has any equality
constraints, the implied means and/or
SDs may be different from those of
the raw data. For example, the mean
of the x
-variable may be constrained
to be equal in this model. To plot
the tumble graph using the model implied
means and SDs, set use_implied_stats
to TRUE
.
A path that involves a latent x
-variable
and/or a latent y
-variable can be
plotted. Because the latent variables
have no observed data, the model
implied statistics will always be used
to get the means and SDs to compute
values such as the low and high points
of the x
-variable.
A ggplot2
graph. Plotted if
not assigned to a name. It can be
further modified like a usual
ggplot2
graph.
Bodner, T. E. (2016). Tumble graphs: Avoiding misleading end point extrapolation when graphing interactions from a moderated multiple regression analysis. Journal of Educational and Behavioral Statistics, 41(6), 593-604. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.3102/1076998616657080")}
cond_indirect_effects()
library(lavaan)
dat <- modmed_x1m3w4y1
n <- nrow(dat)
set.seed(860314)
dat$gp <- sample(c("gp1", "gp2", "gp3"), n, replace = TRUE)
dat <- cbind(dat, factor2var(dat$gp, prefix = "gp", add_rownames = FALSE))
# Categorical moderator
mod <-
"
m3 ~ m1 + x + gpgp2 + gpgp3 + x:gpgp2 + x:gpgp3
y ~ m2 + m3 + x
"
fit <- sem(mod, dat, meanstructure = TRUE, fixed.x = FALSE)
out_mm_1 <- mod_levels(c("gpgp2", "gpgp3"),
sd_from_mean = c(-1, 1),
fit = fit)
out_1 <- cond_indirect_effects(wlevels = out_mm_1, x = "x", y = "m3", fit = fit)
plot(out_1)
plot(out_1, graph_type = "tumble")
# Numeric moderator
dat <- modmed_x1m3w4y1
mod2 <-
"
m3 ~ m1 + x + w1 + x:w1
y ~ m3 + x
"
fit2 <- sem(mod2, dat, meanstructure = TRUE, fixed.x = FALSE)
out_mm_2 <- mod_levels("w1",
w_method = "percentile",
percentiles = c(.16, .84),
fit = fit2)
out_mm_2
out_2 <- cond_indirect_effects(wlevels = out_mm_2, x = "x", y = "m3", fit = fit2)
plot(out_2)
plot(out_2, graph_type = "tumble")
# Multigroup models
dat <- data_med_mg
mod <-
"
m ~ x + c1 + c2
y ~ m + x + c1 + c2
"
fit <- sem(mod, dat, meanstructure = TRUE, fixed.x = FALSE, se = "none", baseline = FALSE,
group = "group")
# For a multigroup model, group will be used as
# a moderator
out <- cond_indirect_effects(x = "m",
y = "y",
fit = fit)
out
plot(out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.