strengejacke / sjstats

Effect size measures and significance tests
https://strengejacke.github.io/sjstats
189 stars 21 forks source link

HDI % rounds up in tidy_stan() #77

Closed jmgirard closed 5 years ago

jmgirard commented 5 years ago

The variable name in the output table was "HDI(100%)" but I think it should display as "HDI(99.5%)". I assume this is an issue with the conversion of prob from numeric to string.

library(sjstats)
library(brms)
## example from brms documentation
prior <- c(set_prior("normal(0,2)", class = "b"),
           set_prior("student_t(10,0,1)", class = "sigma"),
           set_prior("student_t(10,0,1)", class = "sd"))
## fit a linear mixed effects models
fit <- brm(time ~ age + sex + disease + (1 + age|patient),
           data = kidney, family = lognormal(),
           prior = prior, sample_prior = TRUE, 
           control = list(adapt_delta = 0.95))
## offending call
tidy_stan(fit, prob = 0.995)
#> # Summary Statistics of Stan-Model
#>
#>            estimate std.error    HDI(100%) ratio rhat mcse
#> Intercept      3.38      0.56 [ 1.78 5.06]  1.00    1 0.01
#> age           -0.01      0.01 [-0.04 0.03]  0.59    1 0.00
#> sexfemale      1.09      0.38 [ 0.01 2.20]  0.96    1 0.01
#> diseaseGN     -0.26      0.45 [-1.54 1.06]  0.65    1 0.01
#> diseaseAN     -0.28      0.46 [-1.52 1.01]  0.56    1 0.01
#> diseasePKD     0.41      0.63 [-1.21 2.28]  0.63    1 0.01
#> sigma          1.24      0.12 [ 0.94 1.62]  0.79    1 0.00
strengejacke commented 5 years ago

This is an issue in the print() method, which rounds those values and treats them as integer: https://github.com/strengejacke/sjstats/blob/master/R/S3-methods.R#L971

I can probably check for fractional parts...