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

print methods for fitted model components #168

Open
stevencarlislewalker opened this issue Feb 2, 2024 · 4 comments
Open

print methods for fitted model components #168

stevencarlislewalker opened this issue Feb 2, 2024 · 4 comments
Assignees

Comments

@stevencarlislewalker
Copy link
Member

Brainstorm

We can do stuff like this on the bc-tour branch.

> mp_fixed_effects(sir_simulator)
  par_id            mat row col default     estimate    std_error
1      0           beta   0   0   4e-01 3.344498e-01 1.948269e-03
2      1              I   0   0   1e+02 1.754268e+04 6.941066e+02
3      2 reporting_prob   0   0   1e-02 3.597714e-03 4.710118e-05

I know there is lots of code out there for making a nicely formatted printout of stuff like this so I don't want to reinvent the wheel. Any suggests @bbolker, @jaganmn?

@stevencarlislewalker stevencarlislewalker self-assigned this Feb 2, 2024
@jaganmn
Copy link
Collaborator

jaganmn commented Feb 3, 2024

Can you be more precise? Are you wanting a print method for the class of sir_simulator or for the class of mp_fixed_effects(sir_simulator)? You may need to reinvent the wheel a bit if you are using bespoke OO/class definitions ...

@stevencarlislewalker
Copy link
Member Author

I would like to get opinions about good examples of R code the does reasonable things with significant figures and number formatting for coefficient and statistical output tables. I could just look at what glm or something is doing but I'm wondering if you guys have opinions. And by reinventing I mean conceptual reinventing, not necessarily code reinventing.

@bbolker
Copy link
Collaborator

bbolker commented Feb 3, 2024

printCoefmat() is the base-R workhorse. The pillar package (tidyverse-foundational) is used for tibble etc etc output; it's pretty but I find it very opinionated. https://tibble.tidyverse.org/articles/numbers.html (part of the frustration may be with the specific problem that there doesn't seem to be a way to change the precision of printing on the fly, and it's hard to even find out how to do it without digging into the pillar documentation ...

dd <- tibble(x = rnorm(5))
print(dd, digits = 8)  ## no effect
options(pillar.sigfig = 8)
print(dd)  ## works, but obscure

Right now what you have is data.frame() printing; from ?print.data.frame, you can control the overall degree of precision (with digits = ) but I think if you want column-by-column printing you have to call format() column-by-column and put the pieces together ... I don't know if this is easy to do with pillar.

If you want to see how ugly this is to do in general you can look at the source code for printCoefmat

(Are there specific aspects of the default data.frame() print method that you find ugly/want to improve? How much time and effort do you want to spend making the print method pretty ... ??)

@stevencarlislewalker
Copy link
Member Author

Thanks Ben! My criteria in order of descending importance are 1. No dependencies, 2. Good enough to make almost all epidemiologists happy enough, and 3. Minimal time/effort.

But that workhouse function has the sound of the kind of thing I'm looking for. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants