stan-dev/posterior

Control the numeric display in tibble

Open

#257 geöffnet am 4. Okt. 2022

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)R (24 Forks)github user discovery
good first issueinterface

Repository-Metriken

Stars
 (171 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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

Contributor Guide