stan-dev/posterior

Control the numeric display in tibble

Ouverte

#257 ouverte le 4 oct. 2022

 (0 commentaire) (0 réaction) (0 personne assignée)R (26 forks)github user discovery
good first issueinterface

Métriques du dépôt

Stars
 (171 étoiles)
Métriques de merge PR
 (Merge moyen 8j 3h) (1 PR mergée en 30 j)

Description

Related to #255 but different

Recent tibble versions have num() for controlling the display of the numbers. For example, given fit from CmdStanR by default

fit_bin2$summary()
# A tibble: 4 × 10
  variable       mean    median      sd     mad        q5      q95  rhat ess_b…¹
  <chr>         <dbl>     <dbl>   <dbl>   <dbl>     <dbl>    <dbl> <dbl>   <dbl>
1 lp__      -253.     -253.     1.00    0.737   -255.     -2.53e+2 1.00    1751.
2 theta1       0.0592    0.0587 0.00927 0.00931    0.0448  7.49e-2 0.999   3189.
3 theta2       0.0336    0.0331 0.00690 0.00675    0.0232  4.57e-2 1.00    3229.
4 oddsratio    0.569     0.546  0.158   0.147      0.347   8.66e-1 1.00    2998.
# … with 1 more variable: ess_tail <dbl>, and abbreviated variable name
#   ¹​ess_bulk
# ℹ Use `colnames()` to see all variable names

but we can instead to choose to show 2 significant digits and no scientific notation

fit$summary() %>% mutate(across(-variable, num, sigfig=2, notation="dec"))
# A tibble: 4 × 10
  variable      mean   median      sd     mad       q5      q95    rhat ess_bulk
  <chr>      <dec:2>  <dec:2> <dec:2> <dec:2>  <dec:2>  <dec:2> <dec:2>  <dec:2>
1 lp__      -253.    -253.     1.0     0.74   -255.    -253.        1.0    1751.
2 theta1       0.059    0.059  0.0093  0.0093    0.045    0.075     1.0    3189.
3 theta2       0.034    0.033  0.0069  0.0067    0.023    0.046     1.0    3229.
4 oddsratio    0.57     0.55   0.16    0.15      0.35     0.87      1.0    2998.
# … with 1 more variable: ess_tail <dec:2>
# ℹ Use `colnames()` to see all variable names

It would be possible to use more refined different formats for different columns, or give user cobtrol, e.g.

fit$summary(sigfig=2)

See more in https://tibble.tidyverse.org/articles/numbers.html and https://tibble.tidyverse.org/reference/num.html

Guide contributeur