## 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)
Run the code above in your browser using DataLab