Skip to content

bayesian models don't play nice with model_parameters(standardize=) #1192

@mattansb

Description

@mattansb
mod <- rstanarm::stan_glm(mpg ~ hp, data = mtcars, refresh = 0)

parameters::model_parameters(mod)
#> Parameter   | Median |         95% CI |   pd |  Rhat |  ESS |                   Prior
#> -------------------------------------------------------------------------------------
#> (Intercept) |  30.11 | [26.66, 33.54] | 100% | 1.000 | 3594 | Normal (20.09 +- 15.07)
#> hp          |  -0.07 | [-0.09, -0.05] | 100% | 1.000 | 3473 |   Normal (0.00 +- 0.22)
#> 
#> Uncertainty intervals (equal-tailed) computed using a MCMC distribution
#>   approximation.

But… (note different errors)

parameters::model_parameters(mod, standardize = "refit")
#> Warning: Standardizing variables without adjusting priors may lead to bogus
#>   results unless priors are auto-scaled.
#> 
#> Could not extract standard errors of standardized coefficients.
#> Error in `data.frame()`:
#> ! arguments imply differing number of rows: 1, 0

parameters::model_parameters(mod, standardize = "basic")
#> 
#> Could not extract standard errors of standardized coefficients.
#> Error in `data.frame()`:
#> ! arguments imply differing number of rows: 1, 0

Oddly enough, the standardize_parameters() function works just fine:

parameters::standardize_parameters(mod, method = "refit")
#> Warning: Standardizing variables without adjusting priors may lead to bogus
#>   results unless priors are auto-scaled.
#> # Standardization method: refit
#> 
#> Parameter   | Std. Median |         95% CI
#> ------------------------------------------
#> (Intercept) |    2.83e-03 | [-0.23,  0.24]
#> hp          |       -0.77 | [-0.99, -0.55]

parameters::standardize_parameters(mod, method = "basic")
#> # Standardization method: basic
#> 
#> Parameter   | Std. Median |         95% CI
#> ------------------------------------------
#> (Intercept) |        0.00 | [ 0.00,  0.00]
#> hp          |       -0.77 | [-1.03, -0.54]

Created on 2026-02-17 with reprex v2.1.1

Metadata

Metadata

Assignees

Labels

Bug 🐛Something isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions