Generate GAM formula with continuous-by-continuous interaction
gen_gamFormula_contIx.RdGenerates 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.
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. IfTRUE(recommended), the smooth is treated as fixed degrees of freedom. Default isTRUE.- k
Integer or
NULL. Basis dimension passed totifor all three terms (both main effects and the interaction). IfNULL(default), uses the default frommgcv::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)
)
} # }