Skip to contents

Generates a formula in the format y ~ ti(x) + ti(z) + ti(x, z), where y is response.var, x is cont1.var, and z is cont2.var. The formula generated can be further modified, e.g. by adding covariates.

Usage

gen_gamFormula_contIx(response.var, cont1.var, cont2.var, fx = TRUE, k = NULL)

Arguments

response.var

Character. The variable name for the response (dependent variable), typically a scalar name like "FD".

cont1.var

Character. The name of the first continuous variable.

cont2.var

Character. The name of the second continuous variable.

fx

Logical. Passed to ti. If TRUE (recommended), the smooth is treated as fixed degrees of freedom. Default is TRUE.

k

Integer or NULL. Basis dimension passed to ti for all three terms (both main effects and the interaction). If NULL (default), uses the default from mgcv::ti().

Value

A formula object.

Details

This helper uses ti (tensor product interaction) terms so that the interaction ti(x, z) captures only the interaction effect, separate from the main effects ti(x) and ti(z). This decomposition is important for interpretability and for requesting changed.rsq.term.index in ModelArray.gam.

See also

gen_gamFormula_fxSmooth for factor-smooth interactions, ModelArray.gam which accepts the generated formula.

Examples

if (FALSE) { # \dontrun{
formula <- gen_gamFormula_contIx(
  response.var = "FD",
  cont1.var = "age",
  cont2.var = "cognition"
)
formula

# Use in ModelArray.gam with changed R-squared for the interaction
results <- ModelArray.gam(
  formula,
  data = ma,
  phenotypes = phenotypes,
  scalar = "FD",
  changed.rsq.term.index = list(3)
)
} # }