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

adding goodness of fit measures to tbl_regression() #434

Closed
tormodb opened this issue Apr 5, 2020 · 12 comments · Fixed by #640
Closed

adding goodness of fit measures to tbl_regression() #434

tormodb opened this issue Apr 5, 2020 · 12 comments · Fixed by #640
Milestone

Comments

@tormodb
Copy link

tormodb commented Apr 5, 2020

Thanks for developing this great package!

Do you have any plans of adding goodness of fit measures for regressions (like those available from broom::glance), and possibilities of adding a-column for adjusted p-values also for the tbl_regression function?

There another package that provides some of these options, the modelsummary package which is also based on gt, but does not use labels and provide as nice default formatting as gtsummary.

@ddsjoberg
Copy link
Owner

Hello @tormodb !

We have a method for adjusting for multiple testing with the add_q() function. Here's an example of the output:
image
Help file: http://www.danieldsjoberg.com/gtsummary/reference/add_q.tbl_uvregression.html

This will only work on univariate regression models. Are you looking perform a correction to a multivariable regression model? In my field I've only seen it applied to univariate analyses, but if it is something people do in other areas I could extend add_q() quite easily to work with a multivariable model. Someone on twitter posted a work-around for a multivariable model recently (https://twitter.com/healthandstats/status/1241121365647749120).

Regarding the other statistics from tidy::glance()...Our primary goal with {gtsummary} is to create tables that are ready for publication in a journal, and we have not focused on summarizing models for exploratory data analysis. BUT all fields are different and publish results in different formats! Do you routinely publish model summaries with goodness-of-fit measures? Can you point me to some examples, and we can look into adding the functionality

@tormodb
Copy link
Author

tormodb commented Apr 5, 2020 via email

@ddsjoberg
Copy link
Owner

I'll keep this issue open, and will think about how best to incorporate the fit statistics in the output (e.g. rows in tables, as footnotes/source notes for the table).

In the meantime you can use, the code below to print that statistics you're looking for in the summary table.

library(gtsummary)
library(tidyverse)

# building model
mod <- lm(age ~ marker + grade, trial)

# putting fit statistics into a single string
fit_stats <-
  broom::glance(mod) %>%
  select(`R<sup>2</sup>` = r.squared, AIC) %>%
  mutate_all(function(x) style_sigfig(x, digits = 3)) %>%
  {paste(names(.), ., sep = " = ", collapse = "; ")}

# summarize model with gtsummary
tbl_regression(mod) %>%
  # convert to a gt object
  as_gt() %>%
  # add source note with fit statistics
  gt::tab_source_note(gt::html(fit_stats))

image

@tormodb
Copy link
Author

tormodb commented Apr 5, 2020 via email

@ddsjoberg
Copy link
Owner

@tormodb FYI, in the dev version of gtsummary, you can now use add_q() to correct for multiple comparisons on tbl_regression() objects.

Yes, adjusted p-values are also useful when testing several model, as in the example from Twitter. That trick you referred me to will work, but even better would be to show the p as well as the q as you do for univariable regressions so we can see the effect of the adjustment in the table. Hilsen Tormod

@tormodb
Copy link
Author

tormodb commented Apr 6, 2020 via email

@ddsjoberg
Copy link
Owner

Just putting some thoughts here:

  1. This would be easy to add, but with the caveat that that the stats would need to follow the same formatting as the coef. This is likely ok, except when the coefs are exponentiated. I am leaning toward not implementing a sub-optimal version of it.
  2. gtsummary uses the table_header object to store instructions for styling each column. We could add a table_row that would have instructions for styling rows.
table_row <- tibble::tribble(
  ~name, ~type, ~rows, ~value,
  "style_glance", "fmt", "row_type == 'glance'", list(gtsummary::style_sigfig)
)
#> # A tibble: 1 x 4
#>   name         type  rows                 value     
#>   <chr>        <chr> <chr>                <list>    
#> 1 style_glance fmt   row_type == 'glance' <list [1]>

Created on 2020-04-25 by the reprex package (v0.3.0)

@ddsjoberg ddsjoberg changed the title adding godness of fit measures and adjusted p-values to tbl_regression adding goodness of fit measures and adjusted p-values to tbl_regression May 14, 2020
@ddsjoberg ddsjoberg changed the title adding goodness of fit measures and adjusted p-values to tbl_regression adding goodness of fit measures to tbl_regression() May 14, 2020
@ddsjoberg ddsjoberg added this to the 1.3.5 milestone Sep 5, 2020
@storopoli
Copy link
Contributor

Is there a way to add add_glance_source_note() to tbl_merge() for several regression models?
I would like to have them side by side with R2 and Adjusted R2

@ddsjoberg
Copy link
Owner

Is there a way to add add_glance_source_note() to tbl_merge() for several regression models?
I would like to have them side by side with R2 and Adjusted R2

At the moment this is not possible, but it will be in the future. Source notes apply to the entire table, and after a merge it's unclear which model the source is associated with.

@storopoli
Copy link
Contributor

Great! Looking forward to!

@silvia-diaz
Copy link

Hi Daniel, thanks for this amazing package!

I wonder if there is a simple way of adding C-index on a tbl_uvregression?

Thank you!

@ddsjoberg
Copy link
Owner

@silvia-diaz the best place to ask questions about the package use is on stackoverflow.com. Use the gtsummary tag and I'll be notified of your post.

Check out this post for the c-index https://stackoverflow.com/questions/71808925

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

Successfully merging a pull request may close this issue.

4 participants