density_plot {robmed} | R Documentation |
Density plot of the indirect effect(s)
Description
Produce a density plot of the indirect effect(s) from (robust) mediation analysis. In addition to the density, a vertical line representing the point estimate and a shaded area representing the confidence interval are drawn.
Usage
density_plot(object, ...)
## Default S3 method:
density_plot(object, ...)
## S3 method for class 'sobel_test_mediation'
density_plot(object, grid = NULL, level = 0.95, ...)
## S3 method for class 'list'
density_plot(object, grid = NULL, level = 0.95, ...)
## S3 method for class 'setup_density_plot'
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
Methods first call setup_density_plot()
to extract all
necessary information to produce the plot, then the
"setup_density_plot"
method is called to produce the plot.
Value
An object of class "ggplot"
.
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()
, setup_density_plot()
ci_plot()
, ellipse_plot()
,
weight_plot()
, plot()
Examples
data("BSG2014")
# run fast-and-robust bootstrap test
robust_boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict",
robust = TRUE)
# create plot for robust bootstrap test
density_plot(robust_boot)
density_plot(robust_boot, color = "#00BFC4", fill = "#00BFC4")
# run OLS bootstrap test
ols_boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict",
robust = FALSE)
# compare robust and OLS bootstrap tests
boot_list <- list("OLS bootstrap" = ols_boot,
"ROBMED" = robust_boot)
density_plot(boot_list)
# the plot can be customized in the usual way
density_plot(boot_list) + theme_bw() +
labs(title = "OLS bootstrap vs ROBMED")