Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control the numeric display in tibble #257

Open
avehtari opened this issue Oct 4, 2022 · 0 comments
Open

Control the numeric display in tibble #257

avehtari opened this issue Oct 4, 2022 · 0 comments
Labels
good first issue Good for newcomers interface Interface improvements or changes

Comments

@avehtari
Copy link
Collaborator

avehtari commented Oct 4, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers interface Interface improvements or changes
Projects
None yet
Development

No branches or pull requests

2 participants