Internal function for creating a design matrix containing polynomial expansions and interaction terms for predictor variables. Supports customizable term generation including polynomial degrees up to quartic terms, interaction types, and selective term exclusion.
Column names take on the form "_v_" for linear terms, "_v_^d" for polynomial powers up to d = 4, and "_v_x_w_" for interactions between variables v and w, where v and w are column indices of the input predictor matrix.
The custom_basis_fxn
argument, if supplied, requires the same arguments
as this function, in the same order, minus the eponymous argument,
"custom_basis_fxn".
get_polynomial_expansions(
predictors,
numerics,
just_linear_with_interactions,
just_linear_without_interactions,
exclude_interactions_for = NULL,
include_quadratic_terms = TRUE,
include_cubic_terms = TRUE,
include_quartic_terms = FALSE,
include_2way_interactions = TRUE,
include_3way_interactions = TRUE,
include_quadratic_interactions = FALSE,
exclude_these_expansions = NULL,
custom_basis_fxn = NULL,
...
)
Matrix with columns for intercept, polynomial terms, and specified interactions
Numeric matrix of predictor variables
Integer vector; column indices for variables to expand as polynomials
Integer vector; column indices for variables to keep linear but allow interactions
Integer vector; column indices for variables to keep linear without interactions
Integer vector; column indices to exclude from all interactions
Logical; whether to include squared terms (default TRUE)
Logical; whether to include cubic terms (default TRUE)
Logical; whether to include 4th degree terms (default FALSE)
Logical; whether to include two-way interactions (default TRUE)
Logical; whether to include three-way interactions (default TRUE)
Logical; whether to include interactions with squared terms (default TRUE)
Character vector; names of specific terms to exclude from final matrix
Function; optional custom basis expansion function that accepts all arguments listed here except itself
Additional arguments passed to custom_basis_fxn