This function automates running a series of association models, iterating through
a list of predictors and outcomes for a given dataset. It can run both
cross-sectional (lm
) and longitudinal (lmer
) models.
run_association_analysis(
data,
predictors,
outcomes,
covariates,
dataset_name,
analysis_type = "Cross-Sectional",
use_delta_outcome = TRUE,
random_effects = "(1 | PTID)",
interaction_variable = NULL
)
The data frame containing all necessary variables.
A character vector of predictor variable names.
A character vector of outcome variable names.
A character string of covariates to include in all models (e.g., "Age + Sex").
A character string to label the results (e.g., "ADNI").
A character string, either "Cross-Sectional" (default) or "Longitudinal".
A logical. If TRUE and analysis_type
is "Longitudinal",
it will look for outcome variables with a _delta
suffix.
An optional character string for the lmer
random effects
(e.g., "(1 | PTID)"
). Only used when analysis_type
is "Longitudinal".
An optional character string specifying the variable to interact with the predictor in longitudinal models (e.g., "yearsbl"). This is required for longitudinal analyses.
A single tibble (data frame) containing the summarized results from all successful model fits.
if (FALSE) { # \dontrun{
# Example for a cross-sectional analysis
cs_results <- run_association_analysis(
data = my_cross_sectional_data,
predictors = c("PredictorA", "PredictorB"),
outcomes = c("MMSE", "ADAS13"),
covariates = "Age + Sex + Education",
dataset_name = "MyStudy_CS"
)
# Example for a longitudinal analysis with an interaction
long_results <- run_association_analysis(
data = my_longitudinal_data,
predictors = c("Biomarker1", "Biomarker2"),
outcomes = c("CognitionScore"),
covariates = "Age_at_baseline + Sex + Education + yearsbl",
dataset_name = "MyStudy_Long",
analysis_type = "Longitudinal",
use_delta_outcome = FALSE, # Use the raw score over time
random_effects = "(1 | SubjectID)",
interaction_variable = "yearsbl" # Specify the interaction term
)
} # }