I am trying to run a mediation analysis with multiple parallel mediators using the mma() package in R. However, every time I try to run my code below, I am getting an error:
library(mma) vcsqi <- as.data.frame(vcsqi.dci) vcsqi <- vcsqi[, c("predmort", "age", "male", "bmi")] vcsqi <- na.omit(vcsqi) x = vcsqi y = vcsqi[,"predmort"] pred = vcsqi[,"bmi"] test <- mma(x, y, pred=pred, mediator=c(2,3))
and this is the error I get:
Error in Anova.III.LR.glm(mod, singular.ok = singular.ok) : there are aliased coefficients in the model
I understand that this error typically suggests multicollinearity or an issue with linearly dependent variables. However, I am not sure how to address this issue in the context of the mma() function or the data I am working with. I've checked for multicollinearity among my variables and didn't find any high correlations that would cause concern.
I am interested in examining the mediation effects of 'age' and 'male' on the relationship between 'bmi' (predictor) and 'predmort' (outcome).
Could anyone provide insight into why I might be receiving this error and how I might resolve it to successfully run my mediation analysis? Your help would be greatly appreciated. Thank you!
Example of how the code should be running:
data("weight_behavior") x=weight_behavior[,c(2,4:14)] pred=weight_behavior[,3] y=weight_behavior[,15] temp.b.b.glm<-mma(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10),binref=c(1,1), catmed=5,catref=1,predref="M",alpha=0.4,alpha2=0.4,n=2,n2=2)
temp.b.b.glm For Categorical Exposure(s):  "pred" MMA Analysis: Estimated Mediation Effects Using GLM $ie y1.all y1.exercises y1.sweat y1.sports pred 0.116 -0.0286 0.0118 0.165 $te y1.pred 0.604 $de y1.pred 0.488