Learn R Programming

robmed (version 0.6.0)

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

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

Value

An object of class "ggplot".

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.

See Also

test_mediation(), setup_density_plot()

ci_plot(), ellipse_plot(), plot()

Examples

Run this code
# NOT RUN {
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 standard bootstrap test
standard_boot <- test_mediation(BSG2014,
                                x = "ValueDiversity",
                                y = "TeamCommitment",
                                m = "TaskConflict",
                                robust = FALSE)

# compare robust and standard tests
tests <- list(Standard = standard_boot, Robust = robust_boot)
density_plot(tests)

# the plot can be customized in the usual way
density_plot(tests) + theme_bw() +
  labs(title = "Standard vs robust bootstrap test")

# }

Run the code above in your browser using DataLab