This function creates a lm stat object which can be passed as input
to the set_stats()
function when building an aba model. This stat performs
a traditional linear regression analysis using the lm
function.
Coefficients will be presented as beta coefficients. Default metrics include
adjusted R2.
Arguments
- std.beta
logical. Whether to standardize model predictors and covariates prior to analysis.
- complete.cases
logical. Whether to only include the subset of data with no missing data for any of the outcomes, predictors, or covariates. Note that complete cases are considering within each group - outcome combination but across all predictor sets.
- poly
numeric or list. Whether to use polynomial regression. Supplying a single number will call poly(..., #NUMBER#, raw=TRUE) on every covariate and predictor. Supplying a list allows you to perform a polynomial expansion on specific variables. NULL means no polynomials.
Examples
data <- adnimerge %>% dplyr::filter(VISCODE == 'bl')
# fit lm model with continuous outcome variables
model <- data %>% aba_model() %>%
set_groups(
everyone(),
DX_bl %in% c('MCI', 'AD')
) %>%
set_outcomes(CDRSB_bl, MMSE_bl) %>%
set_predictors(
PLASMA_ABETA_bl, PLASMA_PTAU181_bl, PLASMA_NFL_bl,
c(PLASMA_ABETA_bl, PLASMA_PTAU181_bl, PLASMA_NFL_bl)
) %>%
set_covariates(AGE, GENDER, EDUCATION) %>%
set_stats(
stat_lm(std.beta = TRUE)
) %>%
fit()
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_PTAU181_bl"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_NFL_bl"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl + PLASMA_PTAU181_bl + PLASMA_NFL_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_PTAU181_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_NFL_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl + PLASMA_PTAU181_bl + PLASMA_NFL_bl"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_PTAU181_bl"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_NFL_bl"
#> [1] "CDRSB_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl + PLASMA_PTAU181_bl + PLASMA_NFL_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_PTAU181_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_NFL_bl"
#> [1] "MMSE_bl ~ AGE + GENDER + EDUCATION + PLASMA_ABETA_bl + PLASMA_PTAU181_bl + PLASMA_NFL_bl"
# summarise model
model_summary <- model %>% summary()
# plot results
fig1 <- model_summary %>% aba_plot_coef()
fig2 <- model_summary %>% aba_plot_metric()
## polynomial regression ##
model <- data %>%
aba_model() %>%
set_outcomes(MRI_HIPP_bl) %>%
set_covariates(
c('AGE', 'EDUCATION')
) %>%
set_stats(
stat_lm(),
stat_lm(poly = list(AGE=1)),
stat_lm(poly = 2),
stat_lm(poly = list(AGE = 2))
) %>%
fit()
#> [1] "MRI_HIPP_bl ~ AGE + EDUCATION"
#> [1] "MRI_HIPP_bl ~ stats::poly(AGE, 1, raw = TRUE) + EDUCATION"
#> [1] "MRI_HIPP_bl ~ stats::poly(AGE, 2, raw = TRUE) + stats::poly(EDUCATION, 2, raw = TRUE)"
#> [1] "MRI_HIPP_bl ~ stats::poly(AGE, 2, raw = TRUE) + EDUCATION"
model_summary <- model %>% summary()