I am estimating multilevel models using 80 multiply imputed data sets with the package mitml
. I can use the testModels()
command to compare nested models, but I want to view model fit components (specifically, deviance) for each of the 80 individual imputation models and calculate an overall averaged deviance value.
My model estimates are saved in a mitml.result
list called modelt1
.
I can extract the deviance value for the first model (of 80) using indexing:
> modelt1[[1]]@devcomp[["cmp"]][["dev"]]
[1] 22637.1
However, I am not sure how to efficiently extract and average all 80 of these values. I know I need to use a loop, but I'm not sure how to combine a loop with indexing like this.
My attempt was something like:
> for(i in modelt1){print(modelt1[[1]]@devcomp[["cmp"]][["dev"]])}
[1] 22637.1
This, unsurprisingly, returns only the deviance for the first model within modelt1
.
I tried replacing [[1]]
with [[i]]
, and got an error.
I also attempted to loop through all models like this:
> for(i in modelt1){print(modelt1)}
But this of course provides the full summary output for all 80 models, when I just want the deviance values.
How can I write a loop that will print all 80 deviance values?