run_exwas_mids <- function(input_data, variable_list, sdq, subcohort = NULL, file_name) {
exwas_result <- data.frame()
# Change the 'mids' object imputed dataset to complete, stacked dataset
all_imps <- mids_to_complete(input_data, variable_list)
# select one exposure
for (item in variable_list$Term) {
# change input dataset to dataframe
pool_fit <- all_imps %>%
# perform regression for each imputed dataset (group by
# imputation number)
dplyr::group_by(.imp) %>%
# run simple regression for sdq ~ exposure + covariates
dplyr::do(model = MASS::glm.nb(formula = get(sdq) ~ get(item) +
cohort + smoking + mother_bmi + mother_age +
mother_edu + parity + breastf_cat +
mother_work + child_age + sex, data = .)) %>%
# transform the regression output to a list
as.list() %>%
# pick the list item containing numerical regression output
# (coefficient and other statistics for the intercept,
# confounders and exposure), ignore other results provided by
# the glm.nb function
.[[-1]] %>%
# pool the regression outocomes for each imputed dataset
mice::pool() %>%
# extract the final coefficient with 95% confidence intervals
summary(conf.int = TRUE, exponentiate = TRUE)
# pick the row for an exposure only, ignore coef. for
# intercept and confounders
tidy_res <- tidy_exwas_result(pool_fit)
exwas_result <- rbind(exwas_result, tidy_res)
}
exwas_tidy_result <- tidy_exwas_outcomes(input_data, variable_list, exwas_result, subcohort = NULL, file_name)
return(exwas_tidy_result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.