setup_density_plot {robmed} | R Documentation |
Set up information for a density plot of the indirect effect(s)
Description
Extract the relevant information for a density plot of the indirect effect(s) from results of (robust) mediation analysis.
Usage
setup_density_plot(object, ...)
## S3 method for class 'boot_test_mediation'
setup_density_plot(object, ...)
## S3 method for class 'sobel_test_mediation'
setup_density_plot(object, grid = NULL, level = 0.95, ...)
## S3 method for class 'list'
setup_density_plot(object, ...)
Arguments
object |
an object inheriting from class
|
... |
additional arguments to be passed down. |
grid |
an optional numeric vector containing the values at which to
evaluate the assumed normal density from Sobel's test. The default is to
take 512 equally spaced points between the estimated indirect effect
|
level |
numeric; the confidence level of the confidence intervals
from Sobel's test. The default is to include 95% confidence intervals.
Note that this is not used for bootstrap tests, as those require to specify
the confidence level already in |
Details
This function is used internally by density_plot()
. It may
also be useful for users who want to produce a similar plot, but who want
more control over what information to display or how to display that
information.
Value
An object of class "setup_density_plot"
with the following
components:
density |
a data frame containing the values of the indirect effect
where the density is estimated (column |
ci |
a data frame consisting of column |
test |
a character string indicating whether the object contains
results from a bootstrap test ( |
level |
numeric; the confidence level used for the confidence intervals of the indirect effect(s). |
have_effects |
a logical indicating whether the mediation model
contains multiple indirect effects If |
have_methods |
a logical indicating whether a list of
|
Author(s)
Andreas Alfons
References
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022) Robust Mediation Analysis: The R Package robmed. Journal of Statistical Software, 103(13), 1–45. doi:10.18637/jss.v103.i13.
See Also
test_mediation()
, density_plot()
Examples
data("BSG2014")
# run fast-and-robust bootstrap test
boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict")
# set up information for plot
setup <- setup_density_plot(boot)
# plot only density and confidence interval
ggplot() +
geom_density(aes(x = Indirect, y = Density), data = setup$density,
stat = "identity") +
geom_rect(aes(xmin = Lower, xmax = Upper,
ymin = -Inf, ymax = Inf),
data = setup$ci, color = NA, alpha = 0.2) +
labs(x = "Indirect effect", y = "Bootstrap density")