setup_density_plot: Set up information for a density plot of the indirect...

View source: R/setup_density_plot.R

setup_density_plotR Documentation

Set up information for a density plot of the indirect effect(s)

Description

Extract the relevant information for a density plot of the indirect effect(s) from results of (robust) mediation analysis.

Usage

setup_density_plot(object, ...)

## S3 method for class 'boot_test_mediation'
setup_density_plot(object, ...)

## S3 method for class 'sobel_test_mediation'
setup_density_plot(object, grid = NULL, level = 0.95, ...)

## S3 method for class 'list'
setup_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().

Details

This function is used internally by density_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_density_plot" with the following components:

density

a data frame containing the values of the indirect effect where the density is estimated (column Indirect), and the estimated density values (column Density). In case of a model with multiple indirect effects, there is a column Effect that indicates the different indirect effects. 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.

ci

a data frame consisting of column Estimate containing the point estimates, column Lower for the lower confidence limit, and column Upper for the upper confidence limit. In case of a model with multiple indirect effects, there is a column Effect that indicates the different indirect effects. 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.

test

a character string indicating whether the object contains results from a bootstrap test ("boot") or a Sobel test ("sobel"), or a vector of such character strings if a list of "test_mediation" objects has been supplied.

level

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

have_effects

a logical indicating whether the mediation model contains multiple indirect effects If TRUE, the data frames in the density and ci components contain a column Effect.

have_methods

a logical indicating whether a list of "test_mediation" objects has been supplied. If TRUE, the data frames in the density and ci components contain 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(), density_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_density_plot(boot)

# plot only density and confidence interval
ggplot() +
  geom_density(aes(x = Indirect, y = Density), data = setup$density,
               stat = "identity") +
  geom_rect(aes(xmin = Lower, xmax = Upper,
                ymin = -Inf, ymax = Inf),
            data = setup$ci, color = NA, alpha = 0.2) +
  labs(x = "Indirect effect", y = "Bootstrap density")


robmed documentation built on July 9, 2023, 6:29 p.m.