-
-
Notifications
You must be signed in to change notification settings - Fork 67
Description
Describe the bug
cmdstanr 0.9.0.9000 deprecated metadata$model_params (now NULL). brms' read_csv_as_stanfit() depends on this field to compute parameter dimensions for the internal stanfit object. With model_params = NULL, brms silently drops population-level coefficients — verified to lose 1–3 parameters in models with 3–8 predictors. No warnings or errors are raised.
CmdStan and cmdstanr are working correctly — all draws are present in the CSV output and in cmdstanr's draws objects. The issue is that the deprecation removed a field that brms relies on, without a compatibility shim or deprecation warning to downstream packages.
Per the NEWS.md entry for 0.9.0.9000, the deprecated field is:
model_paramselement offit$metadata()list (variableselement)
The replacement fields metadata$stan_variables and metadata$stan_variable_sizes are present and correct, but brms does not yet use them for dimension computation.
To Reproduce
library(brms)
set.seed(42)
n <- 200
dat <- data.frame(
y = rnorm(n),
x1 = rnorm(n), x2 = rnorm(n), x3 = rnorm(n)
)
fit <- brm(y ~ x1 + x2 + x3,
data = dat, family = gaussian(),
chains = 1, iter = 500,
backend = "cmdstanr")
nrow(fixef(fit))
# Returns 3, expected 4 (Intercept is missing)The mechanism: brms greps csfit$metadata$model_params to determine vector dimensions. When NULL, grepl(pattern, NULL) returns logical(0), dimensions are never assigned, and rename_pars() silently drops parameters.
Expected behavior
fixef(fit) should return 4 rows (Intercept + x1 + x2 + x3), matching the backend = "rstan" result. Either:
model_paramsshould remain populated alongside the new fields during the deprecation period, or- brms should be notified of the breaking change so it can migrate to
stan_variable_sizes
Operating system
macOS (Apple Silicon, Darwin 25.3.0)
CmdStanR version number
cmdstanr 0.9.0.9000 (dev, SHA a8adbb1), CmdStan 2.38.0
Additional context
- Filed companion issue on brms:
rename_pars()silently drops population-level coefficients with cmdstanr 0.9.0.9000 whenmetadata$model_paramsis NULL paul-buerkner/brms#1864 - brms version: 2.23.1
- R version: 4.5.3
- The bug affects any brms user on cmdstanr dev (0.9.0.9000) with 3+ population-level predictors
- Models with 1–2 non-intercept predictors have the latent bug (incorrect
dims_oi) but no visible parameter loss - The set of dropped parameters is deterministic for a given formula and scales with model size (1 lost at K=3, 3 lost at K=8)