[R-sig-ME] Correlations among random variables
Avraham Kluger
@v|k @end|ng |rom @@v|on@huj|@@c@||
Thu Jan 24 20:24:26 CET 2019
Dear Wolfgang,
Your metafor solution beautifully replicates, to the dot, results from SPSS and lavann. Can you obtain CI around the estimates, rho, and phi?
Avi
--------------------------------------------------
For the data Avi is working with, the default optimizer (nlminb) fails. Switching to 'optim' (with method 'BFGS') works. Here is the fully reproducible code:
df <- read.csv("https://raw.githubusercontent.com/avi-kluger/RCompanion4DDABook/master/Chapter%2010/Chapter10_df.csv")
library(nlme)
df$focalcode <- 1 - df$focalcode
df$partcode <- 1 - df$partcode
### overparamterized model
res1 <- lme(outcome ~ 0 + focalcode + partcode, random = ~ 0 + focalcode + partcode | focalid/dyadid, data = df)
summary(res1)
### contrain sigma to a very small value
res2 <- lme(outcome ~ 0 + focalcode + partcode, random = ~ 0 + focalcode + partcode | focalid/dyadid, data = df, control=list(sigma=1e-8, opt="optim"))
summary(res2)
Just for fun, I also fitted the same model using 'metafor'. While it was not really made for analyzing raw data like this, it can be used to fit the same model (with the devel version) and then sigma can be constrained exactly to 0:
devtools::install_github("wviechtb/metafor")
library(metafor)
df$dyadid.in.focalid <- interaction(df$focalid, df$dyadid)
res3 <- rma.mv(outcome ~ 0 + focalcode + partcode, V=0, random = list(~ 0 + focalcode + partcode | focalid, ~ 0 + focalcode + partcode | dyadid.in.focalid), struct="GEN", data = df, sparse=TRUE)
res3
(note that 'focalid/dyadid' doesn't work at the moment, so you have to create the nested factor manually first; also, model fitting can be slow with rma.mv(), so you might have to wait a bit for it to converge)
The results for res2 and res3 are quite close.
Best,
Wolfgang
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list