stan-dev / stan-dev/posterior

Control the numeric display in tibble

Open
#257 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue interface
Dominant language
R
Stars
171
Forks
26
Avg merge
2d 18h
Merged PRs (30d)
3

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the fit$summary() entry point and compare the requested output with tibble's num() documentation linked in the issue. Done means summary output supports a documented numeric-display choice such as significant figures and decimal notation, with the behavior agreed for per-column formatting or a summary-level sigfig argument.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.