mediation_analysis {exploratory} | R Documentation |
Mediation analysis
Description
Conducts a mediation analysis to estimate an independent variable's indirect effect on dependent variable through a mediator variable. The current version of the package only supports a simple mediation model consisting of one independent variable, one mediator variable, and one dependent variable. Uses the source code from 'mediation' package v4.5.0, Tingley et al. (2019) https://cran.r-project.org/package=mediation
Usage
mediation_analysis(
data = NULL,
iv_name = NULL,
mediator_name = NULL,
dv_name = NULL,
covariates_names = NULL,
robust_se = TRUE,
iterations = 1000,
sigfigs = 3,
output_type = "summary_dt",
silent = FALSE
)
Arguments
data |
a data object (a data frame or a data.table) |
iv_name |
name of the independent variable |
mediator_name |
name of the mediator variable |
dv_name |
name of the dependent variable |
covariates_names |
names of covariates to control for |
robust_se |
if |
iterations |
number of bootstrap samples. The default is set at 1000, but consider increasing the number of samples to 5000, 10000, or an even larger number, if slower handling time is not an issue. |
sigfigs |
number of significant digits to round to |
output_type |
if |
silent |
if |
Value
if output_type = "summary_dt"
, which is the default,
the output will be a data.table showing a summary of mediation
analysis results; if output_type = "mediate_output"
,
the output will be the output from the mediate
function
in the 'mediate' package; if output_type = "indirect_effect_p"
,
the output will be the p-value associated with the indirect effect
estimated in the mediation model (a numeric vector of length one).
Examples
mediation_analysis(
data = mtcars, iv_name = "cyl",
mediator_name = "disp", dv_name = "mpg", iterations = 100
)
mediation_analysis(
data = iris, iv_name = "Sepal.Length",
mediator_name = "Sepal.Width", dv_name = "Petal.Length",
iterations = 100
)