Title: | Mediation Analysis Using Joint Significance |
---|---|
Description: | A set of helper functions to conduct joint-significance tests for mediation analysis, as recommended by Yzerbyt, Muller, Batailler, & Judd. (2018) <doi:10.1037/pspa0000132>. |
Authors: | Cédric Batailler [aut, cre] |
Maintainer: | Cédric Batailler <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.3 |
Built: | 2025-02-25 05:48:08 UTC |
Source: | https://github.com/cedricbatailler/jsmediation |
add_index
is a generic function that adds a
(moderated) indirect effect index to an object created with an mdt_*
family function. This index is computed using Monte Carlo methods. This
function invokes particular methods depending of the class of the mediation
model. For example, with a model fitted with mdt_simple
,
add_index
will invoke
add_index.simple_mediation
.
add_index(mediation_model, times = 5000, level = 0.05, ...)
add_index(mediation_model, times = 5000, level = 0.05, ...)
mediation_model |
A mediation model fitted with an |
times |
Number of simulations to use to compute the Monte Carlo index's confidence interval. |
level |
Alpha threshold to use for the confidence interval. |
... |
Further arguments to be passed to specific methods. |
An object of the same class as mediation_model
, but with index
added for later use.
Adds the confidence interval for the index of moderated
mediation to a model fitted with mdt_moderated
.
## S3 method for class 'moderated_mediation' add_index(mediation_model, times = 5000, level = 0.05, stage = NULL, ...)
## S3 method for class 'moderated_mediation' add_index(mediation_model, times = 5000, level = 0.05, stage = NULL, ...)
mediation_model |
A mediation model of class
|
times |
Number of simulations to use to compute the Monte Carlo indirect effect confidence interval. |
level |
Alpha threshold to use for the confidence interval. |
stage |
Moderated indirect effect's stage for which to compute the
confidence interval. Can be either |
... |
Further arguments passed to or from other methods. |
Indirect effect moderation index for moderated mediation uses
,
,
, and
estimates and their standard errors to compute the appropriate index
product distribution using Monte Carlo methods (see Muller, Judd, &
Yzerbyt, 2005).
JSmediation supports different types of mediated indirect effect index:
Stage 1: computes the product between and
.
Stage 2: computes the product between and
.
Total: computes the sum of Stage 1 and Stage 2 distribution.
Muller, D., Judd, C. M., & Yzerbyt, V. Y. (2005). When moderation is mediated and mediation is moderated. Journal of Personality and Social Psychology, 89(6), 852-863. doi: 10.1037/0022-3514.89.6.852
## getting a stage 1 moderated indirect effect index ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") ho_et_al <- standardize_variable(ho_et_al, c(linkedfate, sdo), suffix ="c") moderated_model <- mdt_moderated(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate_c, Mod = sdo_c) add_index(moderated_model, stage = 1)
## getting a stage 1 moderated indirect effect index ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") ho_et_al <- standardize_variable(ho_et_al, c(linkedfate, sdo), suffix ="c") moderated_model <- mdt_moderated(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate_c, Mod = sdo_c) add_index(moderated_model, stage = 1)
Adds confidence interval for the index of mediation to a model
fitted with mdt_simple
.
## S3 method for class 'simple_mediation' add_index(mediation_model, times = 5000, level = 0.05, ...)
## S3 method for class 'simple_mediation' add_index(mediation_model, times = 5000, level = 0.05, ...)
mediation_model |
A mediation model of class |
times |
Number of simulations to use to compute the Monte Carlo indirect effect confidence interval. |
level |
Alpha threshold to use for the confidence interval. |
... |
Further arguments passed to or from other methods. |
Indirect effect index for simple mediation uses and
estimates and their standard errors to compute the
product
distribution using Monte Carlo methods (see MacKinnon, Lockwood, &
Williams, 2004).
MacKinnon, D. P., Lockwood, C. M., & Williams, J. (2004). Confidence Limits for the Indirect Effect: Distribution of the Product and Resampling Methods. Multivariate Behavioral Research, 39(1), 99-128. doi: 10.1207/s15327906mbr3901_4
## getting an indirect effect index ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") simple_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) add_index(simple_model)
## getting an indirect effect index ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") simple_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) add_index(simple_model)
Adds the confidence interval for the index of
within-participant mediation to a model fitted with
mdt_within
or mdt_within_wide
.
## S3 method for class 'within_participant_mediation' add_index(mediation_model, times = 5000, level = 0.05, ...)
## S3 method for class 'within_participant_mediation' add_index(mediation_model, times = 5000, level = 0.05, ...)
mediation_model |
A mediation model of class
|
times |
Number of simulations to use to compute the Monte Carlo indirect effect confidence interval. |
level |
Alpha threshold to use for the confidence interval. |
... |
Further arguments passed to or from other methods. |
Indirect effect index for within-participant mediation uses
and
estimates and their standard error to compute the
product distribution using Monte Carlo methods (see MacKinnon, Lockwood, &
Williams, 2004).
MacKinnon, D. P., Lockwood, C. M., & Williams, J. (2004). Confidence Limits for the Indirect Effect: Distribution of the Product and Resampling Methods. Multivariate Behavioral Research, 39(1), 99-128. doi: 10.1207/s15327906mbr3901_4
## getting an indirect effect index within_model <- mdt_within(data = dohle_siegrist, IV = name, DV = willingness, M = hazardousness, grouping = participant) add_index(within_model)
## getting an indirect effect index within_model <- mdt_within(data = dohle_siegrist, IV = name, DV = willingness, M = hazardousness, grouping = participant) add_index(within_model)
Create an APA formatted report from the test of a specific term in a linear model.
apastylr(model, term)
apastylr(model, term)
model |
A linear model created using |
term |
A character string representing a term in the linear model. |
An APA formatted character string.
data(ho_et_al) test <- lm(hypodescent ~ linkedfate, ho_et_al) apastylr(test, "linkedfate")
data(ho_et_al) test <- lm(hypodescent ~ linkedfate, ho_et_al) apastylr(test, "linkedfate")
This function constructs a contrast code from a character variable. It is useful when one needs to recode a two-category character variable to a numeric one.
build_contrast(vector, cond_a, cond_b)
build_contrast(vector, cond_a, cond_b)
vector |
A character vector. |
cond_a |
A character string to be coded -0.5. |
cond_b |
A character string to be coded 0.5. |
The lm
method supports factor and character variables by dummy
coding them. Dummy coding can make the interpretation of regression
coefficient difficult or at least more difficult than contrast coding.
Contrast-coded-variable coefficients interpretation is particularly useful
when conducting a joint-significance test.
A numeric vector.
scale
for centering continuous numeric variable.
data(ho_et_al) ho_et_al$condition_contrast <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") head(ho_et_al)
data(ho_et_al) ho_et_al$condition_contrast <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") head(ho_et_al)
When conducting a joint-significant test, different models are
fitted to the data. This function tests assumptions regarding these models
using the performance
package.
The assumptions test are performed using
check_normality
,
check_heteroscedasticity
, and
check_outliers
.
Note that check_assumptions
returns a mediation_model
object.
check_assumptions( mediation_model, tests = c("normality", "heteroscedasticity") )
check_assumptions( mediation_model, tests = c("normality", "heteroscedasticity") )
mediation_model |
An object of class |
tests |
A character vector indicating which test to run. Supported test
includes |
Invisibly returns an object of class mediation_model
.
Other assumption checks:
plot_assumptions()
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) check_assumptions(my_model)
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) check_assumptions(my_model)
When computing a moderated mediation, one assesses whether an indirect
effect changes according a moderator value (Muller et al., 2005).
mdt_moderated
makes it easy to assess moderated mediation, but it does
not allow accessing the indirect effect for a specific moderator values.
compute_indirect_effect_for
fills this gap.
compute_indirect_effect_for( mediation_model, Mod = 0, times = 5000, level = 0.05 )
compute_indirect_effect_for( mediation_model, Mod = 0, times = 5000, level = 0.05 )
mediation_model |
A moderated mediation model fitted with
|
Mod |
The moderator value for which to compute the indirect effect. Must
be a numeric value, defaults to |
times |
Number of simulations to use to compute the Monte Carlo indirect
effect confidence interval. Must be numeric, defaults to |
level |
Alpha threshold to use for the indirect effect's confidence
interval. Defaults to |
The approach used by compute_indirect_effect_for
is similar to the
approach used for simple slope analyses. Specifically, it will fit a new
moderated mediation model, but with a data set with a different variable
coding. Behind the scenes, compute_indirect_effect_for
adjusts the
moderator variable coding, so that the value we want to compute the
indirect effect for is now 0
.
Once done, a new moderated mediation model is applied using the new data
set. Because of the new coding, and because of how one interprets
coefficients in a linear regression, is now the
indirect effect we wanted to compute (see the Models section).
Thanks to the returned values of and
(
and
, see the Models section), it is now
easy to compute
.
compute_indirect_effect_for
uses
the same approach than the add_index
function. A Monte Carlo simulation
is used to compute the indirect effect index (MacKinnon et al., 2004).
In a moderated mediation model, three models are used.
compute_indirect_effect_for
uses the same model specification as
mdt_moderated
:
with , the outcome value for the ith observation,
, the predictor value for the ith observation,
, the moderator value for the ith observation, and
, the mediator value for the ith observation.
Coefficients associated with ,
,
,
,
,
,
, and
, paths are respectively
,
,
,
,
,
,
, and
(see Muller et al., 2005).
MacKinnon, D. P., Lockwood, C. M., & Williams, J. (2004). Confidence Limits for the Indirect Effect: Distribution of the Product and Resampling Methods. Multivariate Behavioral Research, 39(1), 99-128. doi: 10.1207/s15327906mbr3901_4
Muller, D., Judd, C. M., & Yzerbyt, V. Y. (2005). When moderation is mediated and mediation is moderated. Journal of Personality and Social Psychology, 89(6), 852-863. doi: 10.1037/0022-3514.89.6.852
# compute an indirect effect index for a specific value in a moderated # mediation. data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") ho_et_al <- standardize_variable(ho_et_al, c(linkedfate, sdo)) moderated_mediation_model <- mdt_moderated(data = ho_et_al, DV = hypodescent, IV = condition_c, M = linkedfate, Mod = sdo) compute_indirect_effect_for(moderated_mediation_model, Mod = 0)
# compute an indirect effect index for a specific value in a moderated # mediation. data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") ho_et_al <- standardize_variable(ho_et_al, c(linkedfate, sdo)) moderated_mediation_model <- mdt_moderated(data = ho_et_al, DV = hypodescent, IV = condition_c, M = linkedfate, Mod = sdo) compute_indirect_effect_for(moderated_mediation_model, Mod = 0)
When conducting a joint-significance test, different models are
fitted to the data. This function helps you see a summary of the models that
have been used in an object of class mediation_model
.
display_models(mediation_model)
display_models(mediation_model)
mediation_model |
An object of class |
A list of summary.lm
objects.
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) display_models(my_model)
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) display_models(my_model)
A data set containing data from Dohle and Siegrist (2014)'s Experiment 1 that can be used to conduct within-subject joint-significance test. In this experiment, researchers are interested in the effect of name complexity on willingness to buy a drug. The specific hypothesis is that complex drug names are perceived as more hazardous, which makes someone less likely to buy the drug. Researchers used a within-subject design.
This data set is in a long-format, see mdt_within
to conduct
a within-participant mediation analysis with this data set.
data("dohle_siegrist")
data("dohle_siegrist")
A data frame with 44 rows and 4 variables:
Participant number.
Name of the drugs ("simple" vs. "complex").
Mean estimated hazardousness.
Mean willingness to buy.
Dohle, S., & Siegrist, M. (2014). Fluency of pharmaceutical drug names predicts perceived hazardousness, assumed side effects and willingness to buy. Journal of Health Psychology, 19(10), 1241-1249. doi: 10.1177/1359105313488974
A data set containing data from Dohle and Siegrist (2014)'s Experiment 1 that can be used to conduct within-subject joint-significance test. In this experiment, researchers are interested in the effect of name complexity on willingness to buy a drug. The specific hypothesis is that complex drug names are perceived as more hazardous, which makes someone less likely to buy the drug. Researchers used a within-subject design.
This data set is in a wide format, see mdt_within_wide
to
conduct a within-participant mediation analysis with this dataset.
data("dohle_siegrist_wide")
data("dohle_siegrist_wide")
A data frame with 22 rows and 5 variables:
Participant number.
Hazardousness for complex drug name.
Hazardousness for simple drug name.
Willingness to buy for complex drug name.
Willingness to buy for simple drug name.
Dohle, S., & Siegrist, M. (2014). Fluency of pharmaceutical drug names predicts perceived hazardousness, assumed side effects and willingness to buy. Journal of Health Psychology, 19(10), 1241-1249. doi: 10.1177/1359105313488974
When conducting a joint-significant test, different models are
fitted to the data. This function helps you access the models used in an
object of class mediation_model
.
extract_model(mediation_model, step = NULL)
extract_model(mediation_model, step = NULL)
mediation_model |
An object of class |
step |
An integer or a string corresponding to the model to extract. |
An lm
object.
extract_models
to access a list of every model
relevant to joint-significance testing.
Other extract functions:
extract_models()
,
extract_tidy_models()
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) extract_model(my_model, step = "X -> M")
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) extract_model(my_model, step = "X -> M")
When conducting a joint-significant test, different models are
fitted to the data. This function helps accessing the models used in an
object of class mediation_model
.
extract_models(mediation_model)
extract_models(mediation_model)
mediation_model |
An object of class |
A list of lm
objects.
Other extract functions:
extract_model()
,
extract_tidy_models()
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) extract_models(my_model)
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) extract_models(my_model)
When conducting a joint significant test, different models are
fitted to the data. This function helps you access the models used in an
object of class mediation_model
.
extract_tidy_models(mediation_model)
extract_tidy_models(mediation_model)
mediation_model |
An object of class |
A data frame.
Other extract functions:
extract_model()
,
extract_models()
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) extract_tidy_models(my_model)
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) extract_tidy_models(my_model)
A data set containing data from Experiment 3 from Ho, Kteiley, and Chen (2017). In this experiment, the authors hypothesized that presenting a text stating that Black-White biracials were discriminated against would lead Black participants to associate Black-White biracials more with their lower status parent group than their higher status parent group, according to the rule of hypodescent. In this experiment, the authors tested if this effect was mediated by the sense of linked fate between discriminated Black-White biracials and Black participants.
Note that this data set does not include the participants who were in the discrimination control condition in the study conducted by Ho, Kteiley and Chen (2017).
See mdt_simple
and mdt_moderated
to conduct a
simple mediation or a moderated mediation analysis with this dataset.
data("ho_et_al")
data("ho_et_al")
A data frame with 824 rows and 5 variables:
An incremental index.
Experimental condition (High discrimination vs. Low discrimination).
Score at an SDO scale.
Score at an 8-item linked fate measure.
Score at a 3-item measure of hypodescent.
Ho, A. K., Kteily, N. S., & Chen, J. M. (2017). “You’re one of us”: Black Americans’ use of hypodescent and its association with egalitarianism. Journal of Personality and Social Psychology, 113(5), 753-768. doi: 10.1037/pspi0000107
Given a data frame, a predictor (IV
), an outcome (DV
), a
mediator (M
), and a moderator (Mod
) conducts a joint-significant test
for moderated mediation (see Yzerbyt, Muller, Batailler, & Judd, 2018).You
can learn about moderated mediation in vignette("moderated-mediation")
add_index.moderated_mediation
computes the moderated mediation index.
compute_indirect_effect_for
is used to compute the indirect effect
index for a specific value of the moderator.
mdt_moderated(data, IV, DV, M, Mod)
mdt_moderated(data, IV, DV, M, Mod)
data |
A data frame containing the variables in the model. |
IV |
An unquoted variable in the data frame which will be used as the independent variable. |
DV |
An unquoted variable in the data frame which will be used as the dependent variable. |
M |
An unquoted variable in the data frame which will be used as the mediator. |
Mod |
An unquoted variable in the data frame which will be used as the moderator. |
With moderated mediation analysis, one tests whether the
indirect effect of on
through
is moderated by
. The hypothesis behind this test is that
has an effect on
(
) which has an effect on
(
), meaning that
has an indirect effect on
through
.
Total moderation of the indirect effect of on
can be
described as follows:
with the total moderation of the indirect effect,
the moderation of the direct effect,
, the
moderation of the indirect effect passing by the moderation of
, and
, the moderation of the indirect effect passing by the
moderation of
(see Models section; Muller et al., 2005).
Either both and
or both
and
need to be simultaneously significant for a moderation of the indirect
effect to be claimed (Muller et al., 2005).
Returns an object of class "mediation_model
".
An object of class "mediation_model
" is a list containing at least
the components:
type |
A character string containing the type of model that has been
conducted (e.g., |
method |
A character string containing the approach that has been
used to conduct the mediation analysis (usually
|
params |
A named list of character strings describing the variables used in the model. |
paths |
A named list containing information on each relevant path of the mediation model. |
indirect_index |
A boolean indicating whether an indirect effect index
has been computed or not. Defaults to |
indirect_index_infos |
(Optional) An object of class
|
js_models |
A list of objects of class |
data |
The original data frame that has been passed through
|
In a moderated mediation model, three models will be used:
with , the outcome value for the ith observation,
, the predictor value for the ith observation,
, the moderator value for the ith observation, and
, the mediator value for the ith observation.
Coefficients associated with ,
,
,
,
,
,
, and
, paths are respectively
,
,
,
,
,
,
, and
(see Muller et al., 2005).
Because joint-significance tests use linear models
behind the scenes, variables involved in the model have to be numeric.
mdt_simple
will give an error if non-numeric variables are
specified in the model.
If you need to convert a dichotomous categorical variable to a numeric one,
please refer to the build_contrast
function.
Note that variable coding is especially important in models with multiple
predictors as is the case in the model used to conduct a joint-significance
test of moderated mediation. Muller et al. (2005) recommend using variables
that are either contrast-coded or centered. Using mdt_moderated
with
a DV, a mediator, or a moderator that is neither contrast-coded nor
centered will give a warning message.
Muller, D., Judd, C. M., & Yzerbyt, V. Y. (2005). When moderation is mediated and mediation is moderated. Journal of Personality and Social Psychology, 89(6), 852-863. doi: 10.1037/0022-3514.89.6.852
Yzerbyt, V., Muller, D., Batailler, C., & Judd, C. M. (2018). New recommendations for testing indirect effects in mediational models: The need to report and test component paths. Journal of Personality and Social Psychology, 115(6), 929–943. doi: 10.1037/pspa0000132
Other mediation models:
mdt_simple()
,
mdt_within()
Given a data frame, a predictor (IV
), an outcome
(DV
), and a mediator (M
), conducts a joint-significant test
for simple mediation (see Yzerbyt, Muller, Batailler, & Judd, 2018).
mdt_simple(data, IV, DV, M)
mdt_simple(data, IV, DV, M)
data |
A data frame containing the variables to be used in the model. |
IV |
An unquoted numeric variable in the data frame which will be used as independent variable. |
DV |
An unquoted numeric variable in the data frame which will be used as dependent variable. |
M |
An unquoted numeric variable in the data frame which will be used as mediator. |
With simple mediation analysis, one is interested in finding if the
effect of on
goes through a third variable
. The
hypothesis behind this test is that
has an effect on
(
) that has an effect on
(
), meaning that
has an indirect effect on
through
.
The total effect of on
can be described as follows:
with the total effect of
on
,
the direct of
on
, and
the indirect effect of
on
through
(see Models section).
To assess whether the indirect effect is different from the null, one has
to assess the significance against the null for both (the effect of
on
) and
(effect of
on
controlling for the effect of
). Both
and
need to
be simultaneously significant for an indirect effect to be claimed (Cohen &
Cohen, 1983; Yzerbyt, Muller, Batailler, & Judd, 2018).
Returns an object of class "mediation_model
".
An object of class "mediation_model
" is a list containing at least
the components:
type |
A character string containing the type of model that has been
conducted (e.g., |
method |
A character string containing the approach that has been
used to conduct the mediation analysis (usually
|
params |
A named list of character strings describing the variables used in the model. |
paths |
A named list containing information on each relevant path of the mediation model. |
indirect_index |
A boolean indicating whether an indirect effect index
has been computed or not. Defaults to |
indirect_index_infos |
(Optional) An object of class
|
js_models |
A list of objects of class |
data |
The original data frame that has been passed through
|
In a simple mediation model, three models will be fitted:
with , the outcome value for the ith observation,
, the predictor value for the ith observation, and
, the mediator value for the ith observation (Cohen &
Cohen, 1983; Yzerbyt, Muller, Batailler, & Judd, 2018).
Coefficients associated with ,
,
, and
paths
are respectively
,
,
, and
.
Because joint-significance tests uses linear models
behind the scenes, variables involved in the model have to be numeric.
mdt_simple
will give an error if non-numeric variables are
specified in the model.
To convert a dichotomous categorical variable to a numeric one, please
refer to the build_contrast
function.
Cohen, J., & Cohen, P. (1983). Applied multiple regression/correlation analysis for the behavioral sciences (2nd ed). Hillsdale, N.J: L. Erlbaum Associates.
Yzerbyt, V., Muller, D., Batailler, C., & Judd, C. M. (2018). New recommendations for testing indirect effects in mediational models: The need to report and test component paths. Journal of Personality and Social Psychology, 115(6), 929–943. doi: 10.1037/pspa0000132
Other mediation models:
mdt_moderated()
,
mdt_within()
## fit a simple mediation model data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate)
## fit a simple mediation model data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate)
Given a data frame, a predictor (IV
), an outcome
(DV
), a mediator (M
), and a grouping variable (group
)
conducts a joint-significant test for within-participant mediation (see
Yzerbyt, Muller, Batailler, & Judd, 2018).
mdt_within(data, IV, DV, M, grouping, default_coding = TRUE)
mdt_within(data, IV, DV, M, grouping, default_coding = TRUE)
data |
a data frame containing the variables in the model. |
IV |
an unquoted variable in the data frame which will be used as the independent variable. |
DV |
an unquoted variable in the data frame which will be used as the dependent variable. |
M |
an unquoted variable in the data frame which will be used as the mediator. |
grouping |
an unquoted variable in the data frame which will be used as the grouping variable. |
default_coding |
should the variable coding be the default? Defaults to
|
With within-participant mediation analysis, one tests whether the
effect of on
goes through a third variable
. The
specificity of within-participant mediation analysis lies in the repeated
measures design it relies on. With such a design, each sampled unit (e.g.,
participant) is measured on the dependent variable
and the mediator
in the two conditions of
. The hypothesis behind this test
is that
has an effect on
(
) which has an effect on
(
), meaning that
has an indirect effect on
through
.
As with simple mediation, the total effect of on
can be
conceptually described as follows:
with the total effect of
on
,
the direct of
on
, and
the indirect effect of
on
through
(see Models section).
To assess whether the indirect effect is different from the null, one has
to assess the significance against the null for both (the effect of
on
) and
(effect of
on
controlling
for the effect of
). Both
and
need to be
simultaneously significant for an indirect effect to be claimed (Judd,
Kenny, & McClelland, 2001; Montoya & Hayes, 2011).
Returns an object of class "mediation_model
".
An object of class "mediation_model
" is a list containing at least
the components:
type |
A character string containing the type of model that has been
conducted (e.g., |
method |
A character string containing the approach that has been
used to conduct the mediation analysis (usually
|
params |
A named list of character strings describing the variables used in the model. |
paths |
A named list containing information on each relevant path of the mediation model. |
indirect_index |
A boolean indicating whether an indirect effect index
has been computed or not. Defaults to |
indirect_index_infos |
(Optional) An object of class
|
js_models |
A list of objects of class |
data |
The original data frame that has been passed through
|
For within-participant mediation, three models will be fitted:
with the difference score between DV
conditions for the outcome variable for the ith observation,
the difference score between DV conditions
for the mediator variable for the ith observation,
the sum of mediator variables values for DV conditions
for the ith observation, and
the mean sum of mediator variables values for DV conditions across
observations (see Montoya & Hayes, 2011).
Coefficients associated with ,
,
, and
paths
are respectively
,
,
,
and
.
To be consistent with other mdt_*
family
functions, mdt_within
takes a long-format data frame as data
argument. With this kind of format, each sampled unit has two rows, one for
the first within-participant condition and one for the second
within-participant condition. In addition, each row has one observation for
the outcome and one observation for the mediator (see
dohle_siegrist
for an example.
Because such formatting is not the most common among social scientists
interested in within-participant mediation, JSmediation contains the
mdt_within_wide
function which handles wide-formatted data
input (but is syntax-inconsistent with other mdt_*
family
functions).
Models underlying within-participant mediation use
difference scores as DV (see Models section). Because the function input
does not allow the user to specify how the difference scores should be
computed, mdt_within
has a default coding.
mdt_within
's default behavior is to compute the difference score so
the total effect (the effect of on
) will be positive and
compute the other difference scores accordingly. That is, if
mdt_within
has to use (instead of
) so that
is positive, it will use
(instead of
in the other models.
User can choose to have a negative total effect by using the
default_coding
argument.
Note that DV
and M
have to be numeric.
Judd, C. M., Kenny, D. A., & McClelland, G. H. (2001). Estimating and testing mediation and moderation in within-subject designs. Psychological Methods, 6(2), 115-134. doi: 10.1037//1082-989X.6.2.115
Montoya, A. K., & Hayes, A. F. (2017). Two-condition within-participant statistical mediation analysis: A path-analytic framework. Psychological Methods, 22(1), 6-27. doi: 10.1037/met0000086
Yzerbyt, V., Muller, D., Batailler, C., & Judd, C. M. (2018). New recommendations for testing indirect effects in mediational models: The need to report and test component paths. Journal of Personality and Social Psychology, 115(6), 929–943. doi: 10.1037/pspa0000132
Other mediation models:
mdt_moderated()
,
mdt_simple()
Given a data frame, a predictor (IV
), an outcome
(DV
), a mediator (M
), and a grouping variable (group
)
conducts a joint-significant test for within-participant mediation (see
Yzerbyt, Muller, Batailler, & Judd, 2018).
mdt_within_wide(data, DV_A, DV_B, M_A, M_B)
mdt_within_wide(data, DV_A, DV_B, M_A, M_B)
data |
a data frame containing the variables in the model. |
DV_A |
an unquoted numeric variable in the data frame which will be used as the dependent variable value for the "A" independent variable condition. |
DV_B |
an unquoted numeric variable in the data frame which will be used as the dependent variable value for the "B" independent variable condition. |
M_A |
an unquoted numeric variable in the data frame which will be used as the mediatior variable value for the "A" independent variable condition. |
M_B |
an unquoted numeric variable in the data frame which will be used as the mediatior variable value for the "b" independent variable condition. |
With within-participant mediation analysis, one tests whether the
effect of on
goes through a third variable
. The
specificity of within-participant mediation analysis lies in the repeated
measures design it relies on. With such a design, each sampled unit (e.g.,
participant) is measured on the dependent variable
and the mediator
in the two conditions of
. The hypothesis behind this test
is that
has an effect on
(
) which has an effect on
(
), meaning that
has an indirect effect on
through
.
As with simple mediation, the total effect of on
can be
conceptually described as follows:
with the total effect of
on
,
the direct of
on
, and
the indirect effect of
on
through
(see Models section).
To assess whether the indirect effect is different from the null, one has
to assess the significance against the null for both (the effect of
on
) and
(effect of
on
controlling
for the effect of
). Both
and
need to be
simultaneously significant for an indirect effect to be claimed (Judd,
Kenny, & McClelland, 2001; Montoya & Hayes, 2011).
Returns an object of class "mediation_model
".
An object of class "mediation_model
" is a list containing at least
the components:
type |
A character string containing the type of model that has been
conducted (e.g., |
method |
A character string containing the approach that has been
used to conduct the mediation analysis (usually
|
params |
A named list of character strings describing the variables used in the model. |
paths |
A named list containing information on each relevant path of the mediation model. |
indirect_index |
A boolean indicating whether an indirect effect index
has been computed or not. Defaults to |
indirect_index_infos |
(Optional) An object of class
|
js_models |
A list of objects of class |
data |
The original data frame that has been passed through
|
To be consistent with other mdt_*
family
functions, mdt_within
takes a long-format data frame as data
argument. With this kind of format, each sampled unit has two rows, one for
the first within-participant condition and one for the second
within-participant condition. In addition, each row has one observation for
the outcome and one observation for the mediator (see
dohle_siegrist
for an example.
Because such formatting is not the most common among social scientists
interested in within-participant mediation, JSmediation contains the
mdt_within_wide
function which handles wide-formatted data
input (but is syntax-inconsistent with other mdt_*
family
functions).
Models underlying within-participant mediation use
difference scores as DV (see Models section). mdt_within_wide
uses
M_A
M_B
and DV_A
DV_B
in these
models.
For within-participant mediation, three models will be fitted:
with the difference score between DV
conditions for the outcome variable for the ith observation,
the difference score between DV conditions
for the mediator variable for the ith observation,
the sum of mediator variables values for DV conditions
for the ith observation, and
the mean sum of mediator variables values for DV conditions across
observations (see Montoya & Hayes, 2011).
Coefficients associated with ,
,
, and
paths
are respectively
,
,
,
and
.
Judd, C. M., Kenny, D. A., & McClelland, G. H. (2001). Estimating and testing mediation and moderation in within-subject designs. Psychological Methods, 6(2), 115-134. doi: 10.1037//1082-989X.6.2.115
Montoya, A. K., & Hayes, A. F. (2017). Two-condition within-participant statistical mediation analysis: A path-analytic framework. Psychological Methods, 22(1), 6-27. doi: 10.1037/met0000086
Yzerbyt, V., Muller, D., Batailler, C., & Judd, C. M. (2018). New recommendations for testing indirect effects in mediational models: The need to report and test component paths. Journal of Personality and Social Psychology, 115(6), 929–943. doi: 10.1037/pspa0000132
When conducting a joint-significant test, different models are
fitted to the data. This function returns diagnostic plots for each of the
model used in the mediation model. check_assumptions_plot
uses the
performance
and see
packages behind the scenes to provide the different
plots.
This function is best used in an interactive context.
plot_assumptions( mediation_model, tests = c("normality", "heteroscedasticity", "outliers") )
plot_assumptions( mediation_model, tests = c("normality", "heteroscedasticity", "outliers") )
mediation_model |
An object of class |
tests |
A character vector indicating which test to run. Supported test
includes |
Invisibly returns an object of class mediation_model
.
Other assumption checks:
check_assumptions()
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) plot_assumptions(my_model)
data(ho_et_al) ho_et_al$condition_c <- build_contrast(ho_et_al$condition, "Low discrimination", "High discrimination") my_model <- mdt_simple(data = ho_et_al, IV = condition_c, DV = hypodescent, M = linkedfate) plot_assumptions(my_model)
mediation_model
Print a summary for a mediation model represented by a
mediation_model
object.
## S3 method for class 'mediation_model' print(x, digits = 3, ...)
## S3 method for class 'mediation_model' print(x, digits = 3, ...)
x |
An object of class |
digits |
How many significant digits are to be used for numerics. |
... |
Further arguments. |
standardize_variable()
standardizes the selected columns in a
data.frame using base::scale()
. By default, this function
overwrites the column to be scaled. Use the suffix
argument to avoid this
behavior.
standardize_variable()
and standardise_variable()
are synonyms.
standardize_variable(data, cols = dplyr::everything(), suffix = NULL) standardise_variable(data, cols = dplyr::everything(), suffix = NULL)
standardize_variable(data, cols = dplyr::everything(), suffix = NULL) standardise_variable(data, cols = dplyr::everything(), suffix = NULL)
data |
A data frame containing the variables to standardize. |
cols |
< |
suffix |
A character suffix to be added to the scaled variables names.
When suffix is set to |
A data frame with the standardized columns.
standardize_variable
and grouped_df
Note that standardize_variable
ignores grouping. Meaning that if you
call this function on a grouped data frame (see dplyr::grouped_df), the
overall variables' mean and standard deviation will be used for the
standardization.
ho_et_al %>% standardize_variable(sdo) ho_et_al %>% standardize_variable(c(sdo, linkedfate), suffix = "scaled")
ho_et_al %>% standardize_variable(sdo) ho_et_al %>% standardize_variable(c(sdo, linkedfate), suffix = "scaled")