Learn R Programming

robmed (version 1.2.1)

density_plot: 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, ...)

# S3 method for default density_plot(object, ...)

# S3 method for sobel_test_mediation density_plot(object, grid = NULL, level = 0.95, ...)

# S3 method for list density_plot(object, grid = NULL, level = 0.95, ...)

# S3 method for setup_density_plot density_plot(object, ...)

Value

An object of class "ggplot".

Arguments

object

an object inheriting from class "test_mediation" containing results from (robust) mediation analysis, or a list of such objects.

...

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 \(\pm\) three times the standard error according to Sobel's formula.

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 test_mediation().

Author

Andreas Alfons

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.

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

Run this code
data("BSG2014")

# run fast-and-robust bootstrap test
robust_boot <- test_mediation(BSG2014,
                              x = "ValueDiversity",
                              y = "TeamCommitment",
                              m = "TaskConflict",
                              level = 0.9,
                              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",
                           level = 0.9,
                           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")

Run the code above in your browser using DataLab