I am trying to do FDR correction for some region of interest neuroimaging data. I have run 18 linear mixed effects models overall and I have made sure that the order of the coefficients in the output would be the same in each model.
I have saved the output from each model in the following:
tidy_model1 <-tidy(model1)
tidy_model2 <-tidy(model2)
....
tidy_model18 <-tidy(model18)
I am now trying to make my life easier and create a loop which goes over a list with the names of the above model objects and creates a vector of p-values for each coefficient which I will then enter in the p.adjust function to retrieve the adjusted p-values.
so I create a list:
model_list <- list(tidy_model1,
tidy_model2,... tidy_model18)
I have tried the following loops:
for (i in 1:18) {
model_list[i] %>%
variable1_pval <- p.value[1]
}
and
for (i in 1:18) {
variable1_pval <- model_list[i]$p.value[1]
}
So the above should give me a vector of p-values for coefficient 1 of the model.
However, I get a null vector in both cases.
I know I am not providing my data but any suggestion as to why these loops might not be working are welcome!
Thank you
I made up a list of models:
In these models, the useful coefficient is the second:
You can obtain the p-values in a vector like this, for your example use p.value1:
A better way to keep track of your models, and not populate the environment with variables, is to use purrr, dplyr (see more here) :