The R Code File: Complete R code for mediation analysis: github.com/TidyPython/Mediation_analysis/blob/main/Method%201%20R%20code.R Slides being used: github.com/TidyPython/Mediation_analysis/blob/main/Mediation%20Analysis%20in%20R_Slides.pdf
Thanks for sharing! In regression, should we add control variables such as confounding variables and covariates into the three regression equations for path a, b and c? If so, should we respectively control for variables that affect 1) both X and M, 2) variables that affect both M and Y, and 3) variables that affect both X and Y? Alternatively, should we just control for covariates that affect M and Y respectively without focusing on the independent variables such as X and M?
Hi, let me just focus on your first part of the question: there are 3 regressions, as mentioned in my video. If there are covariates, you just add them into each regression model. I do not understand your second part of the question. Sorry!
@@tidydata Thanks for your reply. I was wondering if we should control for covariates or confounding variables? These are two different concepts, as covariates just affect the dependent variables such as M or Y, but confounding variables affect both X and M (for a path), or affect M and Y (for the b path), or affect X and Y (for the c' path). Thanks!
@@karen-bu4dk Hi, you are welcome! Just a comment/question: Even if a confounding variable (e.g., Z) impacts both X and M, the linear regression model for a path will be: M = X + Z. Can you write it in another way? Or, do I miss anything here? (Note that, I only know the linear regression approach of medaition analysis and thus I could be wrong here.)
Note that, there are two DVs in mediation analysis, namely mediator (M) and dependent measure (Y). If your control variables are for both M and Y, yes, you need to add them into all the regression models. I am not sure how to do that in the "Mediation" R package. But, if you have SPSS, you can use PROCESS, which has menu to directly do that.
Many thanks for the clear tutorial!! I use plm function to do the a.path & b.path, but the results show "Running nonparametric bootstrap Error in statistic(data, original, ...) : mediator model is not yet implemented" Can you help to solve this issue? thanks
Hi, you are welcome. Why do you use plm rather than just lm? If you look at my tutorial, I used lm in R. I am not sure if the mediation package supports plm. github.com/TidyPython/Mediation_analysis/blob/main/Method%201%20R%20code.R
When testing the effect of mediator on DV, you need to control for IV (i.e., X) at the same time. Thus, it is a multiple linear regression, rather than simple linear regression. You can refer to this page: davidakenny.net/cm/mediate.htm
@@linlizhou760 You are welcome! When M and Y are continuous data (or, numerical data), you use linear regressions for both a path and b path. In this case, the R package "mediation" and SPSS PROCESS are using the same method, just different software! Mediation analysis in social science uses the exact same method that I provided in this tutorial (refer to Baron and Kenny (1986)). Actually, PROCESS also can be used in R, and please refer to my another tutorial: ruclips.net/video/4Aq3RRRu0DI/видео.html
Note that, the a path coefficient should be 0.033 rather than 0.33 shown on the slides. My appologies.
Think the in the final figure showing the ab c paths, it should be 0.033( not 0.33)
Yes, you are correct. I will correct it in slides.
The R Code File:
Complete R code for mediation analysis:
github.com/TidyPython/Mediation_analysis/blob/main/Method%201%20R%20code.R
Slides being used:
github.com/TidyPython/Mediation_analysis/blob/main/Mediation%20Analysis%20in%20R_Slides.pdf
Thanks for sharing! In regression, should we add control variables such as confounding variables and covariates into the three regression equations for path a, b and c? If so, should we respectively control for variables that affect 1) both X and M, 2) variables that affect both M and Y, and 3) variables that affect both X and Y? Alternatively, should we just control for covariates that affect M and Y respectively without focusing on the independent variables such as X and M?
Hi, let me just focus on your first part of the question: there are 3 regressions, as mentioned in my video. If there are covariates, you just add them into each regression model. I do not understand your second part of the question. Sorry!
@@tidydata Thanks for your reply. I was wondering if we should control for covariates or confounding variables? These are two different concepts, as covariates just affect the dependent variables such as M or Y, but confounding variables affect both X and M (for a path), or affect M and Y (for the b path), or affect X and Y (for the c' path). Thanks!
@@karen-bu4dk Hi, you are welcome! Just a comment/question: Even if a confounding variable (e.g., Z) impacts both X and M, the linear regression model for a path will be: M = X + Z. Can you write it in another way? Or, do I miss anything here? (Note that, I only know the linear regression approach of medaition analysis and thus I could be wrong here.)
If I have other control variables, C,D,E, to control the results of regressions. should I include all control variables in all regressions, a b c?
Note that, there are two DVs in mediation analysis, namely mediator (M) and dependent measure (Y). If your control variables are for both M and Y, yes, you need to add them into all the regression models. I am not sure how to do that in the "Mediation" R package. But, if you have SPSS, you can use PROCESS, which has menu to directly do that.
Many thanks for the clear tutorial!! I use plm function to do the a.path & b.path, but the results show "Running nonparametric bootstrap
Error in statistic(data, original, ...) :
mediator model is not yet implemented" Can you help to solve this issue?
thanks
Hi, you are welcome. Why do you use plm rather than just lm? If you look at my tutorial, I used lm in R. I am not sure if the mediation package supports plm. github.com/TidyPython/Mediation_analysis/blob/main/Method%201%20R%20code.R
Why the b effect is based on the model 'Y~aX+bM', instead of 'Y~bM'?
When testing the effect of mediator on DV, you need to control for IV (i.e., X) at the same time. Thus, it is a multiple linear regression, rather than simple linear regression. You can refer to this page: davidakenny.net/cm/mediate.htm
@@tidydata Thanks! Could you please provide 1-3 sample articles that used this method? Most articles I found used PROCESS added in SPSS instead of R.
@@linlizhou760 You are welcome! When M and Y are continuous data (or, numerical data), you use linear regressions for both a path and b path. In this case, the R package "mediation" and SPSS PROCESS are using the same method, just different software! Mediation analysis in social science uses the exact same method that I provided in this tutorial (refer to Baron and Kenny (1986)). Actually, PROCESS also can be used in R, and please refer to my another tutorial: ruclips.net/video/4Aq3RRRu0DI/видео.html