I would like to perform a multilevel mediation analysis in R with the mlma package. My code is based on the example for these analyses here: https://rdrr.io/cran/mlma/f/vignettes/MLMAvignette.Rmd.
Overall, I am very unsure whether my code is correct, but from the explanations I have read through I am not much smarter and I seem to produce only code that does not work.
Currently I get the error
Error in grep(temp.mnames[i], mnames) : invalid 'pattern' argument`
I've already googled this, but only found this error code in other versions.
I also have the suspicion that there might be some basic errors in the code or in my procedure, which would cause errors in the following steps.
Generell informations: My variables are: Emotional Exhaustion (EE) is x, Sexual desire (SV) is m (mediator), Relationship satisfaction (BZ) is y, (subjects (VPN) is group variable).
I´ve asked my subjects about their EE, SV, and BZ at different time points. My group variable has the format integer. All other variables are continuous (numeric). I want to make the analyses at level 1 of all variables.
Data and code: Since I already have a ready-made dataset with the variables of interest, I skipped the "A simulated dataset" part.
Now we still need to do the "Data Transformation and Organization".
Here you can see the sample code from the link above.
example1<-data.org(x=cbind(x1=x1,x2=x2), m=cbind(m1=m1,m2=m2),
f01y=list(2,c("x","ifelse(x>0,log(x+1),0)")),
level=level,
f01km2=list(matrix(c(2,2),1,2),"x^2"))
From the explanation of the code, here are my thoughts:
- I need to insert additional y because $levely$ was not predefined.
- "$level$ is a vector that records the group number for each observation." -> I need to insert VPN for this.
- "If nothing is specified in $f01y$ or $f10y$, the predictors keep their original format without transformation." -> Would leave f01y empty.
- For f01km2, I am unsure what to do. I would guess that I can handle it like f01y and just leave it blank.
Under "The function $mlma$ for multilevel mediation analysis", this code is added.
mlma.e1<-mlma(y=y,data1=example1,intercept=F)
mlma.e1
My code resulting from these two blocks looks like this:
medi<-data.org(x=EE, m=SV, y=BZ,
level=VPN)
mlma.e2<-mlma(y=BZ, data=medi,intercept=F)
mlma.e2
summary(mlma.e2)
The problem: Unfortunately, already when running the first line, the following error appears
Error in grep(temp.mnames[i], mnames) : invalid 'pattern' argument
I don't know exactly why this error message appears and I'm not sure if the code is correct or if there are also other mistakes.
I would be very grateful for any hints and suggestions.