Learn R Programming

robmed (version 0.9.0)

ci_plot: Dot plot with confidence intervals

Description

Produce a dot plot with confidence intervals of selected effects from (robust) mediation analysis. In addition to confidence intervals, p-values of the selected effects can be plotted as well.

Usage

ci_plot(object, ...)

# S3 method for default ci_plot(object, parm = NULL, ...)

# S3 method for boot_test_mediation ci_plot( object, parm = NULL, type = c("boot", "data"), p_value = FALSE, digits = 4L, ... )

# S3 method for sobel_test_mediation ci_plot(object, parm = NULL, level = 0.95, p_value = FALSE, ...)

# S3 method for list ci_plot( object, parm = NULL, type = c("boot", "data"), level = 0.95, p_value = FALSE, digits = 4L, ... )

# S3 method for setup_ci_plot ci_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.

parm

a character string specifying the effects to be included in the plot. The default is to include the direct and the indirect effect(s).

type

a character string specifying which point estiamates and confidence intervals to plot: those based on the bootstrap distribution ("boot"; the default), or those based on the original data ("data"). If "boot", the confidence intervals of effects other than the indirect effect(s) are computed using a normal approximation (i.e., assuming a normal distribution of the corresponding effect with the standard deviation computed from the bootstrap replicates). If "data", the confidence intervals of effects other than the indirect effect(s) are computed via statistical theory based on the original data (e.g., based on a t-distribution if the coefficients are estimated via regression). Note that this is only relevant for mediation analysis via a bootstrap test, where the confidence interval of the indirect effect is always computed via a percentile-based method due to the asymmetry of its distribution.

p_value

a logical indicating whether to include dot plots of the p-values in addition to those with confidence intervals. The default is FALSE.

digits

an integer determining how many digits to compute for bootstrap p-values of the indirect effects (see p_value()). The default is to compute 4 digits after the comma. This is only relevant if p_value = TRUE.

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_ci_plot() to extract all necessary information to produce the plot, then the "setup_ci_plot" method is called to produce the plot.

See Also

test_mediation(), setup_ci_plot()

density_plot(), ellipse_plot(), weight_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
ci_plot(robust_boot)
ci_plot(robust_boot, color = "#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)
ci_plot(tests)

# the plot can be customized in the usual way
ci_plot(tests) +
  geom_hline(yintercept = 0, color = "darkgrey") +
  coord_flip() + theme_bw() +
  labs(title = "Standard vs robust bootstrap test")

# }

Run the code above in your browser using DataLab