Learn R Programming

SCoRES (version 0.1.2)

check_and_align_vars: Validate and align types/levels between training data and prediction grid

Description

Ensures that variables in grid_df are type-compatible with df_fit and that factor (including ordered factor) levels are aligned to those used during model fitting. Character columns in df_fit are first coerced to factors. For any factor/ordered variable, grid_df is coerced to the same type and levels; any unseen levels in grid_df will trigger an error.

Usage

check_and_align_vars(df_fit, grid_df, model_vars = NULL, grid_boot = FALSE)

Value

grid_df

The prediction grid with variables aligned to df_fit.

Arguments

df_fit

A data frame used for model fitting. Character columns will be coerced to factors before alignment.

grid_df

A data frame of covariate settings (newdata) at which predictions/SCBs are to be evaluated.

model_vars

A vector contained all the interested columns that appear in df_fit. Only those variables are aligned in grid_df; other columns are left unchanged. Default is NULL.

grid_boot

A logic value for whether the function is for constructing grid_df_boot or not.

Examples

Run this code
# Used internally by SCB_linear_outcome, SCB_logistic_outcome

Run the code above in your browser using DataLab