Mediate | R Documentation |
Mediation Analysis and Bayes Factor Computation
Mediate(Data, Model, Prior, R, burnin)
Data |
list(X, M, Y) for "Simple", list(X, m_star, y_star) for "Cont", list(X, m_tilde, Y) for "MCat", list(X, M, y_tilde) for "YCat", and list(X, m_tilde, y_tilde) for "MYCat" |
Model |
can be either "Simple", "Cont", "MCat", "YCat", "MYCat". In case of Simple, a simple partial mediation is estimated, Baron and Kenny (1986), and Preacher and Hayes (2004) proposed methods are also computed |
Prior |
list(A_M,A_Y) |
R |
number of MCMC iterations, default = 10000 |
burnin |
number of MCMC draws before the posterior is converged |
For Data arguments and Models, see
PartialMed for "Simple"
MeasurementMCat for "MCat"
MeasurementYCat for "YCat"
MeasurementMYCat for "MYCat"
Prior = list(A_M,A_Y)
[optional]
A_M
vector of coefficients' prior variances of eq.1, default = rep(100,2)
A_Y
vector of coefficients' prior variances of eq.2, default = c(100,100,1)
BK = list(eq1, eq2, Indirect_se, FullMed)
(only for "Simple"!)the summary of the eq.1 regression
the summary of the eq.2 regression
the standard error of the indirect effect a la Sobel(1982)
the significance test result for the direct effect
PH = list(Indirect_mean, Indirect_CI, Direct_CI)
the bootstrapped mean of the indirect effect
the bootstrapped 95% confidence interval of the indirect effect
the bootstrapped 95% confidence interval of the direct effect
list(evidence, Indirect_CI, Direct_CI, BF,...)
(For all the models)the interpretation of the BF in terms of evidence in favor of full mediation according to Kass and Raftery (1995)
the Bayesian 95% HDI (confidence interval) of the indirect effect
the Bayesian 95% HDI (confidence interval) of the direct effect
the Bayes factor(BF_01) of the corresponding model (see Laghaie and Otter (2020))
For the rest of the values, see
PartialMed for "Simple"
MeasurementMCat for "MCat"
MeasurementYCat for "YCat"
MeasurementMYCat for "MYCat"
simPartialMed = function(beta_M,beta_Y, sigma_M, sigma_Y,N,X) {
eps_M = rnorm(N)*sigma_M # generate errors for M (independent)
eps_Y = rnorm(N)*sigma_Y # generate errors for Y (independent)
M = beta_M[1] + beta_M[2] * X + eps_M # generate latent mediator M
Y = beta_Y[1] + beta_Y[2] * M + beta_Y[3] * X + eps_Y # generate dependent variable
list(X = X, M = M, Y = Y)
}
# Set up data generating parameters
N = 1000 # number of observations
sigma_M = .2^.5 # error std M
sigma_Y = .2^.5 # error std Y
beta_M = c(1, .3) # beta_0M and beta_1
beta_Y = c(1, .5, 0) # beta_0Y, beta_2, beta_3
X = rnorm(N,mean = 1,sd = 1) # generate random X
# Generate data based on parameters
Data = simPartialMed(beta_M,beta_Y,sigma_M,sigma_Y,N,X)
#Estimation
A_M = c(100,100); # Prior variance for beta_0M, beta_1
A_Y = c(100,100,1) # Prior variance for beta_0Y, beta_2, beta_3
R = 2000
out = Mediate(Data = Data, Model = 'Simple',
Prior = list(A_M = A_M, A_Y = A_Y),R=5000, burnin = 3000)
# Results
out$BK$FullMed
out$PH$Indirect_CI
colMeans(out$Simple$beta_Y)
out$Simple$BF
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.