Nonetheless, as I have started to submit R scripts when I submit papers, I was unsatisfied with having to conduct the mediation analysis separately from the rest of my analyses. As such I started to explore how I might conduct the same mediation analyses without having to leave RStudio. After spending some time not having much success, this Youtube video was incredibly helpful:.
Note that the direct effect highlighted in peach is the same result as the result for the Condition IV highlighted in green.
Both are just the effect of Condition on perceived likelihood of Reoffending, independent of perceived Guilt. Serial mediation is when an IV predicts a mediator M1 which subsequently predicts another mediator M2which then predicts a DV. However, I think it might be possible to do with lavaan by adding one or two short lines of codes. After spending some time not having much success, this Youtube video was incredibly helpful: And boom!
Just like that, I could do mediation analysis in R. Activate mediation package. Create dataframe with the variables you want as part of your analysis, and just the two conditions. Make sure the condition var is not set to a factor in the original data frame.
However, the experimental design is a full factorial design across three variables two continuous, one categorical and I cannot find an explanation of how to implement mediation in R with multiple treatments. I have read the documentation on the mediation package but they do not appear to provide ways of expanding X beyond a single treatment.
I need to implement this in the next couple days for a presentation so I don't have time to get up to speed on another program to do it, I need to implement it in R. Does anyone know if there is an implementation in R that I've missed?
Or if there is a way to implement this approach outside of a package? I realize I could convert my full factorial design into a single treatment by treating each 3-factor combination as a level but such an analysis would not be helpful.
After more exhaustive search, it appears that there is not currently an R package that can handle mediation with multiple treatments ie, predictors. However, it appears that those that handle multiple predictors e.
This is the type of model needed to code full path analyses and is notably more complex than simplified mediation model coding e. Learn more. How do you perform mediation analysis with multiple treatments in R Ask Question. Asked 5 years, 5 months ago. Active 1 year, 11 months ago. Viewed 1k times. DirtStats DirtStats 5 5 silver badges 25 25 bronze badges.
Did you see the function multimed? Also, the function "findFn" from SOS package can be used to locate packages, e. See bmem. Thanks, these were helpful ways to research further, though I didn't find what I was looking for.
Active Oldest Votes. There are a number of Markov model packages. LMest package simulates Markov models for latent categorical data. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.Updated October 18, Code can be downloaded here. In some situations we may consider the indirect effect of some variable on an outcome or result. As an example, poor living conditions at home in childhood may decrease learning outcomes in school, which subsequently have a negative effect on later quality of life, for example, lifetime income earnings.
In another case we might consider a single variable collected at multiple time points, such that there exists an effect of the variable at time 1 on time 2, and time 2 on time 3.
The basic idea is something like:. Mediation analysis is very popular in social science disciplines, though by no means restricted to those, and usually conducted under the guise of structural equation modeling SEMwhich itself is a specific orientation of graphical models more generally 1. The graphical model of a mediation model might look like the following. I should note a few things based on what I see in consulting across dozens of disciplines. To begin, it seems very few people who think they need a mediation model actually do.
While nothing will stop you from doing mediation analysis, without such prerequisites, you will almost certainly have a weak and probably more confusing model than you otherwise would have. In short, mediation works best when there are strongly implied causal connections among the variables.
Even then, such a model should be compared to simpler model of no mediation 2. In any case, there are a few very easy ways to investigate such models in R, and that is the goal here, just to demonstrate how you can get started.
For demonstration of mediation models with the different packages, we will use the jobs data set that comes with the mediation package. Here is the description. JOBS II is a randomized field experiment that investigates the efficacy of a job training intervention on unemployed workers. The program is designed to not only increase reemployment among the unemployed but also enhance the mental health of the job seekers.
In the JOBS II field experiment, 1, unemployed workers received a pre-screening questionnaire and were then randomly assigned to treatment and control groups. Those in the treatment group participated in job-skills workshops. In the workshops, respondents learned job-search skills and coping strategies for dealing with setbacks in the job-search process.
Those in the control condition received a booklet describing job-search tips. In follow-up interviews, the two key outcome variables were a continuous measure of depressive symptoms based on the Hopkins Symptom Checklist, and a binary variable, representing whether the respondent had become employed.
Here is a description of the variables in this demonstration. There are others available you might also want to play around with. Thus we expect the job skills training to have a negative effect on depression i.
We will look at the following packages to demonstrate how one can conduct mediation analysis in R:. We will start with the mediation package, as it basically requires no more programming ability to conduct than one possesses already from running standard regression models in R.
The average causal mediation effect ACME represents the expected difference in the potential outcome when the mediator took the value that would realize under the treatment condition as opposed to the control condition, while the treatment status itself is held constant.
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It only takes a minute to sign up.
Chapter 15: Moderated Mediation
It looks like you have four predictors, one mediator, and one outcome. What is the mediation effect you're interested in? You need to specify a focal predictor. As you have specified it, there is no focal predictor, so there is no single question about mediation you can answer. You can ask a different mediation question for each focal predictor e. There is no single mediation quantity you can validly estimate without choosing a focal predictor. Sign up to join this community.
The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Asked 1 year ago. Active 1 year ago. Viewed 74 times. Mo'men Mohamed Mo'men Mohamed 1 2 2 bronze badges. Active Oldest Votes.Evaluating direct, indirect, and total effects in path analysis in AMOS
Because we have interaction terms in our regression analyses, we need to mean center our IV and Moderator Z. We will first create two regression models, one looking at the effect of our IVs time spent in grad school, time spent with Alex, and their interaction on our mediator number of publicationsand one looking at the effect of our IVs and mediator on our DV number of job offers.
Next, we will examine the influence of our moderating variable time spent with Alex on the mediation effect of time spent in grad school on number of job offers, through number of publications. To do this, we will examine the mediation effect for those who spend a lot of time with Alex versus those who spend little time with Alex. One model specifies the effect of our IV time spent in grad school on our Mediator number of publications [and in our case, our moderator time spent with Alex and the interaction].
The other model specifies the effect of the IV time spent in grad school and Mediator number of publications and possibly moderator as well on our DV number of job offers. In this mediation package we list the moderator as a covariate and set the levels to what we want. For a review on bootstrapping techniques, see Efron, The following code tests whether the difference between indirect effects at each level of the moderator is significantly different from zero. Now we take the specified models and all of the effects we want to estimate and run them through the SEM function.
Hayes, A. Introduction to mediation, moderation, and conditional process analysis: A regression-based approach. New York: The Guilford Press. Michalak, N. Rosseel, Y. Sales, A. Review: Mediation package in R. Journal of Educational and Behavioral Statistics, 421, Tingley, D.I wrote this brief introductory post for my friend Simon.
In the specific case of mediation analysis the transition to R can be very smooth because, thanks to lavaanthe R knowledge required to use the package is minimal. Analysis of mediator effects in lavaan requires only the specification of the model, all the other processes are automated by the package.
So, after reading in the data, running the test is trivial. This time, to keep the focus on the mediation analysis I will skip reading-in the data and generate a synthetic dataset instead.
This is because otherwise I would have to spend the next paragraph explaining the dataset and the variables it contains and I really want to only focus on the analysis. As shown in the lavaan website performing a mediation analysis is as simple as typing in the code below:. For multiple mediators one simply need to extend the model recycling the code of the first mediator variable:.
Note that with multiple mediators we must add the covariance of the two mediators to the model. Covariances are added using the notation below:. There are two ways to test the null hypothesis that the indirect effect are equal to each other. The first is to specify a contrast for the two indirect effects. In the definition of the contrast the two indirect effects are subtracted.
If it is significant the two indirect effects differ. The second option to determine whether the indirect effects differ is to set a constrain in the model specifying the two indirect effect to be equal. Then, with the anova function one can compare the models and determine which one is better. Including the constrain and comparing the models is simple:. In my case the test is not significant so there is no evidence that the indirect effects are different. For these toy models there is no further need of customizing the calls to sem.
However, when performing a proper analysis one might prefer to have bootstrapped confidence intervals. Bootstrap confidence interval can be extracted with the function calls 1 summary, 2 parameterEstimates, or 3 bootstrapLavaan.This post extends this previous one on multiple-mediation with lavaan.
This dataset we used previously for a paper published some time ago. There we investigated whether fear of an imperfect fat self was a stronger mediator than hope of a perfect thin self on dietary restraint in college women. However, I only had access to the demo version of Mplus which allowed to model only two independent variables, but we had three. BMI, which was a control variable, had to be treated as an independent variable, making the demo version of Mplus insufficient to perform the test.
At the time we were rescued by a colleague, who modeled the solution in AMOS. Falling back on AMOS provided an imminent solution, but I was unsatisfied, and I have been looking for an alternative since. I now know lavaan is not only an alternative but it is in my opinion the best option to perform this type of analysis. I display above depicts the model in hope of simplifying its complexity, but I will not explain it any further.
Instead I will get into the R code. To read the data I used the R function read. Moreover, to spare myself some typing during the specification of the model I renamed the variables to shorter acronyms. Specifically attainabilityfear and attainabilityhope, the mediators, are M1 and M2, respectively.
DietTotal, the dependent variable, is Y.
BMI, the control variable, is C. Age I will not use, therefore I left as age. PDiscrepency and Pstandards are independent variables recoded as X1 and X2, respectively. Porder I will not use, therefore I left as Porder. To avoid any sort of confusion I will clarify that the digit I added after the letter identifying each variable type do not index order, the digits only distinguish the variables of the same type from one another.
The model specification is straightforward. First all predictors on Y, the dependent variable, then the same with the two mediators. Then indirect effects to the dependent variable through both mediators for each independent variables.
Note that there are no indirect effects for the control. The subtraction of indirect effects, representing contrasts, determines which path through the indirect effect is stronger than the other. Total effects must be specified for each independent variables and for the control as well.
The full model specification is below:. To make the modelling more robust I ask lavaan to estimate the standard error based on an estimate from bootstrap samples. Beware that drawing bootstrap samples takes a few minutes on my old machine. If you only care to check whether the procedure works, remove or comment out the bootstrap and se lines and leave drawing of the bootstrap samples for a proper analysis.
Mplus also includes the intersects in the model, therefore increasing the number of parameters to estimate. Note that adding parameters does not necessarily improve the model, in my specific case it worsen the model both AIC and BIC were higher for the models with intercepts than for the model without them.
The covariance of the independent variables could also be automatically added to the model setting the parameter fixed. Calling help lavOptions shows all the other options available with lavaan.
While experimenting with the model specifications in lavaan I discovered two points on coding style for which I would have appreciate some word of advice. I found the formulations confusing because I could not see that they were yielding identical results in spite of being expressed differently.