Skip to content

Conversation

@kenkellner
Copy link
Collaborator

@kenkellner kenkellner commented Jan 15, 2025

This PR adds general capability to handle functions in R formulas with LINPRED. For example offset() or scale().

During formula processing, these types of "function terms" are identified as functions and the corresponding formula component object is tagged as class formulaComponentFunction.

Since every function will be different, we have to handle them individually.

In order to process a formulaComponentFunction object further, we need a matching processing function. This function must have a particular name and a particular class. For example to handle offset, the environment must contain a function called offsetFormulaFunction which has class formulaFunction. This processing function then takes the input formula component and creates the linear predictor terms and priors as needed.

If there is no such matching processing function, an error is returned instead.

The upside of this approach is that we can add support for a given function in formulas in a modular way, without modifying LINPRED, as can users. In this PR I've added offsetFormulaFunction to the package exports as an example of this (and also because we definitely need offset support).

There is no requirement that the function to be supported in formulas already exists as an R function. So this feature will also allow for arbitrary new function support, such as for ICAR() for a spatial random effect.

Fixes #32

@kenkellner kenkellner merged commit db330c4 into master Jan 24, 2025
1 check passed
@kenkellner kenkellner deleted the formulaFunctions branch January 24, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support offset() in formulas

1 participant