paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.27k stars 183 forks source link

Setting 'decomp = QR' in an intercept-only model generates Stan code with unused variables #1680

Closed wzbillings closed 3 days ago

wzbillings commented 3 weeks ago

I noticed this while generating some model formulas automatically inside of a loop. If one specifies an intercept-only model, several parameters are not expected as input in the stan code (because they are unnecessary). However, the stan code that gets added for decomp = "QR" depends on the predictor matrix and the number of predictors, so the Stan code doesn't compile.

This is easy to fix, but maybe worth implementing a check/error message for users who do this on accident.

Reprex:

brm(
    formula = bf(
        mpg ~ 1,
        decomp = 'QR'
    ),
    data = mtcars
)
paul-buerkner commented 2 weeks ago

Thanks! Will fix it in the next release.

paul-buerkner commented 3 days ago

It now errors with: "QR decomposition requires non-intercept predictors."