'Q: R how to loop moderation analysis
I want to perform several moderation analyis on the relationship between my independent variable (x) and the dependent variable (y). I have a dataset (myData) with the variables x, y and numerous moderators (a, b, c, d, e). Here the code:
for(i in 2:ncol(QBSData)){
mod_name <- colnames(MyData)[i]
mod_summaries[[i-1]]<-summary(
lm(y ~ x + MyData[, c(mod_name)] + x * MyData[, c(mod_name)], data = MyData))
}
mod_summaries
The code is working, but I would like to have the name of the moderator (e.g. a, b, c...) as name of the model when displaying the results.
Any suggestions on how can I implement this feature and improve the code to loop the moderation analysis?
Thank you in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
