setup_ci_plot: Set up information for a dot plot with confidence intervals

View source: R/setup_ci_plot.R

setup_ci_plotR Documentation

Set up information for a dot plot with confidence intervals

Description

Extract the relevant information for a dot plot with confidence intervals of selected effects from (robust) mediation analysis. Information on p-values of the selected effects can be included in addition to confidence intervals.

Usage

setup_ci_plot(object, ...)

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

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

## S3 method for class 'list'
setup_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 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 information on the p-values in addition to the 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

This function is used internally by ci_plot(). It may also be useful for users who want to produce a similar plot, but who want more control over what information to display or how to display that information.

Value

An object of class "setup_ci_plot" with the following components:

ci

a data frame consisting of column Effect indicating the different effects, column Estimate containing the point estimates, column Lower for the lower confidence limit, and column Upper for the upper confidence limit. If argument p_value = TRUE, there is an additional column Label which gives the default facet label for the confidence intervals. If a list of "test_mediation" objects has been supplied, there is also a column Method, which takes the names or indices of the list elements to indicate the different methods.

p_value

a data frame consisting of column Label which gives the default facet label for the p-values, column Effect indicating the different effects, and column Value containing the p-values. If a list of "test_mediation" objects has been supplied, there is also a column Method, which takes the names or indices of the list elements to indicate the different methods. This is only returned if argument p_value = TRUE.

level

numeric; the confidence level used for the confidence intervals of the indirect effect(s).

have_methods

a logical indicating whether a list of "test_mediation" objects has been supplied. If TRUE, the data frame in the ci component contains a column Method.

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(), ci_plot()

Examples

data("BSG2014")

# run fast-and-robust bootstrap test
boot <- test_mediation(BSG2014,
                       x = "ValueDiversity",
                       y = "TeamCommitment",
                       m = "TaskConflict")

# set up information for plot
setup <- setup_ci_plot(boot, parm = "Indirect")

# plot only density and confidence interval
ggplot() +
  geom_hline(yintercept = 0, color = "darkgrey") +
  geom_pointrange(aes(x = "Robust bootstrap", y = Estimate,
                      ymin = Lower, ymax = Upper),
                  data = setup$ci) +
  labs(x = NULL, y = "Indirect effect")


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