Description Details Note Author(s) References Examples
This package can be used to perform a default Bayesian hypothesis test for mediation, correlation, and partial correlation, either analytically or through the Savage-Dickey method (Dickey & Lientz, 1970). All tests make use of a Jeffreys-Zellner-Siow prior set-up (Liang et al., 2008). This package is based on the paper by Nuijten, Wetzels, Matzke, Dolan, and Wagenmakers (under review).
Package: | BayesMed |
Type: | Package |
Version: | 0.1.0 |
Date: | 2012-07-31 |
License: | GPL-2 |
The main functions jzs_med
and jzs_medSD
can be used to establish and test mediation in a data set. With jzs_cor
and jzs_corSD
you can establish and test correlation, and with jzs_partcor and jzs_partcorSD partial correlation.
This function requires the program "JAGS" (Just Another Gibbs Sampler) to be in the PATH variable. 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. Many thanks to Sacha Epskamp.
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.
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 67 68 69 70 71 | ## Not run:
# simulate mediational data
X <- rnorm(50,0,1)
M <- .5*X + rnorm(50,0,1)
Y <- .3*X + .6*M + rnorm(50,0,1)
###########
# run jzs_med to perform the Bayesian hypothesis test for mediation
result <- jzs_med(independent=X,dependent=Y,mediator=M)
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").
#
#############
# plot results
plot(result$main_result)
# plot posterior samples including credible interval, mean, and median
# of the indirect effect alpha*beta
plot(result$ab_samples)
# inspect separate posterior distributions of alpha, beta, and tau_prime
plot(result$alpha_samples)
plot(result$beta_samples)
plot(result$tau_prime_samples)
# print a traceplot of the chains
# where the first chain (theta[1]) is for tau' and the second chain (theta[2]) for beta
plot(result$jagssamplesA)
plot(result$jagssamplesTB)
###########
# run jzs_medSD to perform the Savage-Dickey (SD) Bayesian hypothesis test for mediation
result_SD <- jzs_medSD(independent=X,dependent=Y,mediator=M)
result_SD
# plot(results)
plot(result_SD$main_result)
# plot posterior samples
# including credible interval, mean, and median of the indirect effect alpha*beta
plot(result_SD$ab_samples)
# inspect separate posterior distributions of alpha, beta, and tau_prime
plot(result_SD$alpha_samples)
plot(result_SD$beta_samples)
plot(result_SD$tau_prime_samples)
# print a traceplot of the chains
# where the first chain (theta[1]) is for tau' and the second chain (theta[2]) for beta
plot(result_SD$jagssamplesA)
plot(result_SD$jagssamplesTB)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.