View source: R/q_mediation_plot.R
| plot.q_mediation | R Documentation |
Plot the path model fitted by the family of 'q_mediation' functions.
## S3 method for class 'q_mediation'
plot(
x,
standardized = FALSE,
size_variables = NULL,
size_path_labels = NULL,
nchar_variables = NULL,
nchar_path_labels = NULL,
digits = 2,
rsquares = TRUE,
sigs = TRUE,
margins = c(5, 5, 5, 5),
v_pos = c("middle", "lower", "upper"),
v_preference = c("upper", "lower"),
print_indirect = TRUE,
indirect_standardized = c("none", "stdx", "stdy", "stdxy"),
size_indirect = 1,
plot_now = TRUE,
...
)
indirect_on_plot(
q_mediation_output = NULL,
digits = 2,
size_indirect = 1,
indirect_standardized = c("none", "stdx", "stdy", "stdxy"),
margins = c(5, 5, 5, 5),
original_plot = NULL
)
x |
The output of
|
standardized |
Logical. If
|
size_variables |
The size of
the observed variables (the
"rectangles"), to be passed
to |
size_path_labels |
The size of
the edge labels (parameter
estimates), to be passed to
|
nchar_variables |
The number of
characters to be displayed for each
variable. To be passed to
|
nchar_path_labels |
The number
of characters to be displayed for
each label for a path. To be passed
to |
digits |
The number
of digits to be printed after the
decimals. To be passed
to |
rsquares |
Logical. If |
sigs |
Logical. If |
margins |
The margins of the plot.
A numeric vector of four values:
bottom, left, top, and right. Passed
to the |
v_pos |
How the mediators are to
be positioned vertically. If set to
|
v_preference |
The preference in
shifting the mediators upward
( |
print_indirect |
Logical.
Whether the indirect effect(s), and
total indirect effect if applicable,
will be printed on the plot. Default
is |
indirect_standardized |
If
|
size_indirect |
The size used
when printing the indirect effects.
The final size is determined by
multiplying the final
value |
plot_now |
If |
... |
For the |
q_mediation_output |
The original
object used to generate the plot
(the output of the |
original_plot |
The plot
generated by the |
This method requires the
semptools and semPlot packages.
They are not installed by default.
Install them first before using the
plot method.
This method draws the path models
fitted by q_mediation(),
q_simple_mediation(),
q_serial_mediation(), and
q_parallel_mediation(), with
path coefficients and R-squares.
It will try to set positions of the
variables automatically, following
the left-to-right convention: x
variables on the left, y variables
on the right, mediators between them,
and arrows (paths) flow from left to
right. The figure should usually be
usable. If not, it can be further
modified by helper functions such as
those in semptools that can
manipulate a qgraph object. For
example, semptools::move_node()
can be used to adjust the position
of a variable in the plot.
The helper function indirect_on_plot()
adds the indirect effect
estimates (as well as confidence
intervals and p-values, if
available) to a plot. The plot method
will add these effects by default,
and so users usually do not need to
use this function.
However, if the plot needs to be modified
before being drawn, this function
can be used to add the effects
after drawing the modified plot.
The plot method returns a qgraph
object generated
by semPlot::semPaths(), which is
plotted by default unless plot_now
is set to FALSE. It can be further
modified by other functions that
work on a qgraph object, such as
those from semptools.
The function indirect_on_plot()
returns the object set to
q_mediation_output
invisibly. It is called for its
side-effect.
# These examples require the package
# semptools (version 0.3.2 or above).
# CI disabled in these examples.
# Please see the help page of these functions on forming
# confidence intervals for the indirect effects.
# ===== Simple mediation
out <- q_simple_mediation(x = "x",
y = "y",
m = "m",
cov = c("c2", "c1"),
boot_ci = FALSE,
data = data_med)
plot(out)
# ===== Serial mediation
out <- q_serial_mediation(x = "x",
y = "y",
m = c("m1", "m2"),
cov = c("c2", "c1"),
boot_ci = FALSE,
data = data_serial)
plot(out)
# Standardized effects
plot(out,
standardized = TRUE,
indirect_standardized = "stdxy")
# ==== Parallel mediation
out <- q_parallel_mediation(x = "x",
y = "y",
m = c("m1", "m2"),
cov = c("c2", "c1"),
boot_ci = FALSE,
data = data_parallel)
plot(out)
plot(out,
v_pos = "lower")
plot(out,
v_pos = "upper")
# ===== A user-specified mediation model
out <- q_mediation(x = "x1",
y = "y1",
model = c("x1 -> m11 -> m2 -> y1",
"x1 -> m12 -> m2 -> y1"),
cov = c("c2", "c1"),
boot_ci = FALSE,
data = data_med_complicated)
plot(out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.