Build a GLMM log-posterior (and gradient) from a model-data bundle.
Source:R/glmm_logpost.R
build_glmm_logpost.RdBuild a GLMM log-posterior (and gradient) from a model-data bundle.
Usage
build_glmm_logpost(
bundle,
family,
sigma_re = NULL,
n_trials = NULL,
phi = 1,
beta_prior = .tulpa_default_beta_prior("glmm_logpost"),
weights = NULL,
phi2 = NULL
)Arguments
- bundle
Output of
tulpa_build_model_data()(needsy,X,offset,re_terms,n_obs,n_fixed).- family
Character family name (see
family_names()).- sigma_re
Numeric vector of random-effect SDs, one per RE term. Length must equal
length(bundle$re_terms). Ignored when there are no RE terms.- n_trials
Binomial denominators (or
NULL).- phi
Dispersion passed to the family, held fixed. One convention at every door: for
gaussian/lognormalthis is the residual VARIANCE (the SD issqrt(phi)), forneg_binomial_2the size,gammathe shape,betathe precision,tthe scale;binomialandpoissonignore it. The compiled kernels parameterize the two variance families by the residual SD and are handedsqrt(phi)at the boundary.- beta_prior
list(mean, sd)Gaussian prior on the fixed effects (scalars, recycled). Defaults to the engine default,prior_normal(0, 2.5).- weights
Optional per-observation likelihood weights (length
n_obs): each row's log-likelihood and score contribution is scaled by its weight.- phi2
Optional second dispersion (Student-t degrees of freedom).
Value
A list with:
log_posterior(theta)– scalar log-posterior (up to a constant).grad_log_posterior(theta)– gradient vector.dim– length oftheta.init– a zero starting vector of lengthdim.unpack(theta)– list(beta,u= list of n_groups x n_coefs matrices).param_names– character labels aligned withtheta.