############################################################################### # Model specifications. This project uses one analysis script per model # (see -.R), so there is no shared brms formula # registry here. What does live at session start is the custom log-normal # family in its natural-scale (mean–sd) parameterization: its custom_family() # object and companion Stan block. custom_family() comes from brms, so this # file must be sourced after packages.R (init.R guarantees the order). The # matching log_lik / posterior_predict / posterior_epred helpers are in # functions.R. ############################################################################### lognormal_natural <- custom_family( name = "lognormal_natural", dpars = c("mu", "sigma"), links = c("log", "log"), lb = c(0, 0), type = "real" ) stan_lognormal_natural <- " real lognormal_natural_lpdf(real y, real mu, real sigma) { real common_term = log(1+sigma^2/mu^2); return lognormal_lpdf(y | log(mu)-common_term/2, sqrt(common_term)); } real lognormal_natural_rng(real mu, real sigma) { real common_term = log(1+sigma^2/mu^2); return lognormal_rng(log(mu)-common_term/2, sqrt(common_term)); } "