Description Usage Arguments Details Value Visible Output Invisible Output Warning Note Author(s) References See Also Examples
This function can be used to perform a default Bayesian hypothesis test for mediation, using the Savage-Dickey method (Dickey & Lientz, 1970). The test uses a Jeffreys-Zellner-Siow prior set-up (Liang et al., 2008).
1 2 3 4 5 6 7 |
independent |
a vector containing values for the independent variable. |
dependent |
a vector containing values for the dependent variable. |
mediator |
a vector containing values for the mediating variable. |
SDmethod |
specify the precise method with which the density of the posterior distribution will be estimated in order to compute the Savage-Dickey ratio. |
alternativeA |
specify the alternative hypothesis for path alpha: |
alternativeB |
specify the alternative hypothesis for path beta: |
alternativeT |
specify the alternative hypothesis for path tau_accent: |
n.iter |
number of total iterations per chain (see the package |
n.burnin |
length of burn in, i.e. number of iterations to discard at the beginning(see the package |
standardize |
logical. Should the variables be standardized? Defaults to TRUE. |
The test consists of four steps. Firstly, it computes the posterior probability for the existence of the path between the independent and the mediating variable (path alpha) through the Savage-Dickey density ratio method.
Secondly, it computes the posterior probability for the existence of the path between the mediating and the dependent variable, controlled for the influence of the independent variable (path beta), again with the Savage-Dickey density ratio method.
Thirdly, the evidence for mediation is computed by multiplying the posterior probabilities for the paths alpha and beta.
Fourthly, the evidence for full mediation is computed by multiplying the evidence for mediation with one minus the posterior probability for the existence of path tau', the path between the independent and dependent variable, controlled for the mediator.
jzs_mdSD returns a list containing visible (printed) and invisible components. The visible components are a data frame with the main results and the 95% credible interval of the mediated effect (see next section). The invisible components contain additional information on the parameters, and can be used for plot functions etc.
The visible output, the output that is printed to the screen, is a list containing a data frame and a credible interval.
The mean of the posterior samples of alpha.
The mean of the posterior samples of beta.
The mean of the posterior samples of tau_prime.
The mean of the posterior samples of the indirect effect alpha*beta.
The Bayes factor for the existence of path alpha. A value greater than one indicates evidence that alpha exists, a value smaller than one indicates evidence that alpha does not exist.
The Bayes factor for the existence of path beta. A value greater than one indicates evidence that beta exists, a value smaller than one indicates evidence that beta does not exist.
The Bayes factor for the existence of path tau_prime. A value greater than one indicates evidence that tau_prime exists, a value smaller than one indicates evidence that tau_prime does not exist.
The Bayes factor for mediation compared to no mediation. A value greater than one indicates evidence in favor of mediation, a value smaller than one indicates evidence against mediation.
The posterior probability that the path alpha (the relation between the independent and the mediating variable) is not zero.
The posterior probability that the path beta (the relation between the mediating and the dependent variable after controlling for the independent variable) is not zero.
The posterior probability that the path tau_prime (the relation between the independent and the dependent variable after controlling for the mediator) is not zero.
The posterior probability that the relation between the independent and the dependent variable is mediated by the specified mediator.
The 95% credible interval of the indirect effect "ab".
jzs_medSD also returns output that is not printed to the screen. This invisible output contains the following elements:
The posterior samples of alpha.
The posterior samples of beta.
The posterior samples of tau_accent.
The posterior distribution of alpha multiplied by the posterior distribution of beta. This is equivalent to the posterior distribution of the indirect effect "ab".
The JAGS output for the MCMC estimation of path alpha. This object can be used to construct a traceplot.
The JAGS output for the MCMC estimation of path tau' and beta. This object can be used to construct a traceplot.
In some cases the SDmethod fit.st
will fail to converge. If so, jzs_medSD automatically switches to another optimization method (optim stats) with different starting values (mean and sd of the posterior sample). If the other optimization method does not converge either, you could either try to run the same code again (sometimes it will converge a second time), or you could try one of the other SDmethod options or try the analytical mediation test instead (see jzs_med
).
This function requires the program "JAGS" (Just Another Gibbs Sampler). This program can be obtained from http://mcmc-jags.sourceforge.net.
Michele B. Nuijten <m.b.nuijten@uvt.nl>, Ruud Wetzels, Dora Matzke, Conor V. Dolan, and Eric-Jan Wagenmakers.
Dickey, J. M., & Lientz, B. P. (1970). The weighted likelihood ratio, sharp hypotheses about chances, the order of a Markov chain. The Annals of Mathematical Statistics, 214-226.
Liang, F., Paulo, R., Molina, G., Clyde, M. A., & Berger, J. O. (2008). Mixtures of g priors for Bayesian variable selection. Journal of the American Statistical Association, 103(481), 410-423.
Nuijten, M. B., Wetzels, R., Matzke, D., Dolan, C. V., & Wagenmakers, E.-J. (2014). A default Bayesian hypothesis test for mediation. Behavior Research Methods. doi: 10.3758/s13428-014-0470-2
Wetzels, R., & Wagenmakers, E.-J. (2012). A Default Bayesian Hypothesis Test for Correlations and Partial Correlations. Psychonomic Bulletin & Review, 19, 1057-1064.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | ## Not run:
# simulated mediational data
a <- .5
b <- .6
t_prime <- .3
X <- rnorm(50,0,1)
M <- a*X + rnorm(50,0,1)
Y <- t_prime*X + b*M + rnorm(50,0,1)
# run jzs_medSD
result <- jzs_medSD(independent=X,dependent=Y,mediator=M)
# print result
result
### NOTE ###
#Sometimes this error will pop up:
#
#Error in solve.default(nItheta) :
# system is computationally singular: reciprocal condition number = *some small number*
#Error in mydt2(0, mT, sT, dfT) : unused arguments (mT, sT, dfT)
#In addition: Warning message:
#In jzs_medSD(X, Y, M) :
# fit.st did not converge. Alternative optimization method was used.
#
#If this happens, just run jzs_medSD() again.
#This usually solves the convergence problem. If it does not,
#try a different SD method. For instance: jzs_medSD(X,Y,M,SDmethod="dnorm").
#
#############
#------------------------------------------
# load Firefighter data
data(Firefighters)
X <- Firefighters$x
M <- Firefighters$m
Y <- Firefighters$y
# run jzs_medSD
result <- jzs_medSD(independent=X,dependent=Y,mediator=M)
# plot the result in a mediation diagram
plot(result$main_result)
# inspect posterior distribution of the coefficients
plot(result$alpha_samples)
plot(result$beta_samples)
plot(result$tau_prime_samples)
# print a traceplot of the chains
plot(result$jagssamplesA)
plot(result$jagssamplesTB)
# where the first chain (theta[1]) is for tau' and the second chain (theta[2]) for beta
# calculate and plot a 95% credible interval for the
# posterior mean of the indirect effect
result$CI_ab
plot(result$ab_samples)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.