tulpa_parse_formula: Parse a mixed-model formula

View source: R/formula.R

tulpa_parse_formulaR Documentation

Parse a mixed-model formula

Description

Decomposes a formula into fixed effects and random effects by walking the formula's abstract syntax tree. This is structural recursion with pattern matching on bar terms – no string manipulation.

Usage

tulpa_parse_formula(formula)

## S3 method for class 'tulpa_parsed_formula'
print(x, ...)

Arguments

formula

A formula object (e.g., y ~ x + (1 | group))

x

A tulpa_parsed_formula object.

...

Ignored.

Value

A list with:

  • response: character, the response variable label (NULL if none)

  • response_expr: language object, the LHS of ~ (NULL if none)

  • fixed_formula: formula, the fixed-effects-only formula

  • random_effects: list of parsed RE specifications

  • n_re_terms: integer, number of RE terms

  • latent_blocks: list of evaluated user-defined latent block objects (typically tgmrf S3 objects), one per latent(...) term in the original formula. Empty list when no latent(...) terms are present.

  • n_latent_blocks: integer, number of latent(...) terms

  • original: the original formula

Examples

pf <- tulpa_parse_formula(y ~ x1 + x2 + (1 | group) + (x1 || site))
pf$response        # "y"
pf$fixed_formula   # y ~ x1 + x2


tulpa documentation built on Oct. 19, 2026, 5:09 p.m.