Created
January 29, 2023 23:07
-
-
Save danieltomasz/5964de9c15ef918ad505d8f43c1131de to your computer and use it in GitHub Desktop.
Iterating over variables in glm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_models <- function(datame_name, cog_vars, eeg_components) { | |
list_models <- list() | |
for (cogvar in cog_vars) { # ,eeg_components | |
for (eegvar in eeg_components) { # ,eeg_components | |
models <- glue("model1.{cogvar}.{eegvar} <- glm({cogvar} ~ GM_Normalised + {eegvar}, {datame_name}, family = gaussian) | |
list_models[['model.{cogvar}.{eegvar}']] <- model5.{cogvar}.{eegvar}") # nolint | |
eval(str2expression(models)) | |
} | |
} | |
return(list_models) | |
} | |
list_models <- create_models("dataset", cog_vars, eeg_components) | |
df_models <- purrr::map_df(list_models, broom::tidy, .id = "model") | |
print.data.frame(df_models, scientific = FALSE, digits = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment