latent: Mark an expression as a latent block in a tulpa formula

View source: R/tgmrf.R

latentR Documentation

Mark an expression as a latent block in a tulpa formula

Description

Wraps a user-defined latent block (currently a tgmrf() object) so the formula parser can recognise and route it to the inference layer. The call is structural – it is never executed at fit time. The parser evaluates the inner expression in the formula's environment, removes the latent(...) term from the fixed-effects formula, and attaches the resulting object to parsed$latent_blocks.

Usage

latent(block)

Arguments

block

A tgmrf (or, in the future, tgeneric) object.

Value

Returns block invisibly. Outside a formula context the call is a no-op pass-through.

Examples

n <- 8
blk <- tgmrf(
  Q = function(theta) Matrix::Diagonal(n, exp(-2 * theta[1])),
  prior = function(theta) stats::dnorm(theta[1], 0, 1, log = TRUE),
  init = c(log_sigma = 0))
parsed <- tulpa_parse_formula(y ~ x + latent(blk))
parsed$n_latent_blocks

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