ci_plot: Dot plot with confidence intervals

View source: R/ci_plot.R

ci_plotR Documentation

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

## Default S3 method:
ci_plot(object, parm = c("direct", "indirect"), ...)

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

## S3 method for class 'sobel_test_mediation'
ci_plot(
  object,
  parm = c("direct", "indirect"),
  level = 0.95,
  p_value = FALSE,
  ...
)

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

## S3 method for class '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

an integer, character or logical vector specifying which effects to include in the plot. In case of a character vector, possible values are "a", "b", "d" (only serial multiple mediator models), "total", "direct", and "indirect". The default is to include the direct and the indirect effect(s).

type

a character string specifying which point estimates 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().

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.

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

density_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
ci_plot(robust_boot)
ci_plot(robust_boot, color = "#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)
ci_plot(boot_list)

# the plot can be customized in the usual way
ci_plot(boot_list) +
  geom_hline(yintercept = 0, color = "darkgrey") +
  coord_flip() + theme_bw() +
  labs(title = "OLS bootstrap vs ROBMED")


aalfons/robmed documentation built on July 4, 2023, 7:48 a.m.