This function calculates a reference grid for each fitted result in an
aba model based on specified parameters (see emmeans::ref_grid for examples).
The predictions and standard errors from the fitted result are also included
in the grid by default
Arguments
- model
aba model. The fitted aba model on which to compute a reference grid.
- at
named list of vectors. A named list where the name is a variable in the model and the value is a vector of values which should be included in the list.
- expand
character vector. Variables in the model for which all observed values of the variable should be included in the grid.
- reduce_fn
function. Any variables not in
atand not inexpandwill will be reduced based on this function. The default ismean, where only the mean value of these variables will be included in the grid. However, the reduce function can just as well return multiple values from a custom fn: e.g.function(x) { seq(min(x), max(x), length.out=10) }will include 10 values in the grid spaced around the min and max.
Examples
# get data
data <- aba::adnimerge %>%
filter(
AGE > 20,
YEARS_bl <= 3.5,
DX_bl == 'MCI'
)
#> Error: object 'YEARS_bl' not found
data_bl <- data %>% filter(VISCODE == 'bl')
#> Error in attr(data, "tsp") <- c(start, end, frequency): object is not a matrix
model <- data_bl %>%
aba_model() %>%
set_outcomes(ADAS13_bl, CDRSB_bl) %>%
set_predictors(
c(AGE, EDUCATION),
AGE
) %>%
set_stats('lm') %>%
fit()
#> Error in eval(expr, envir, enclos): object 'data_bl' not found
model_grid <- model %>% aba_grid(at = list('AGE' = c(70, 80, 90)))
#> Error in eval(expr, envir, enclos): object 'model' not found
# All observed values of 'EDUCATION' will be included in the grid
# For all other vars ('AGE'), a 4-val seq spaced from min-max will be included
model_grid <- model %>% aba_grid(
expand = c('EDUCATION'),
reduce_fn = function(x) { seq(min(x), max(x), length.out=4) }
)
#> Error in eval(expr, envir, enclos): object 'model' not found