inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
76 stars 21 forks source link

Automatically detect simple linear predictors #124

Open finnlindgren opened 2 years ago

finnlindgren commented 2 years ago

When specifying a formula explicitly (i.e. with components separately defined), the only way to tell inlabru it's a linear predictor is currently to use response ~ ., and to use include/exclude to specify which components to include or exclude, either in multilikelihood models with like() or in generate()/predict() calls, to avoid attempts to evaluate undefined components. Would be useful to add a method that parses the formula and detects simple nameA + nameB predictors, and also other more complex linear predictors, such as nameA - nameB and nameA + nameB.latent ( with allow_latent=TRUE and/or allow_combine=TRUE). More complex expressions like nameA + Amatrix %*% nameB.latent may also be possible to detect. The verbose output should also state the result (and ideally the reasoning) of this detection.

finnlindgren commented 2 years ago

In addition, a linear = TRUE/FALSE option should be added, to help in more general cases like sum(Amatrix %*% nameA.latent), and also to aid debugging.

finnlindgren commented 2 years ago

Potentially useful: http://adv-r.had.co.nz/Expressions.html#ast-funs