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

Bug Report: warning with tbl_regression for glm with subset #2111

Closed
richardjtelford opened this issue Dec 23, 2024 · 2 comments
Closed

Bug Report: warning with tbl_regression for glm with subset #2111

richardjtelford opened this issue Dec 23, 2024 · 2 comments

Comments

@richardjtelford
Copy link

I am using tbl_regression() to report the result of a glm. The glm uses the subset argument to remove some unneeded data.

tbl_regression() is giving a warning. The results appear to be correct.

With an lm model, no warning is given.

set.seed(23)
df <- data.frame(
  resp = rnorm(n = 60),
  pred = rep(c("A", "B"), 30), 
  n = 1:60
)

mod1 <- glm(resp ~ pred, data = df[1:50, ]) # without subset argument
mod2 <- glm(resp ~ pred, data = df, subset = n <= 50) # with subset

# models should be the same
identical(coef(mod1), coef(mod2))
#> [1] TRUE


gtsummary::tbl_regression(mod1)
Characteristic Beta 95% CI1 p-value
pred


    A
    B 0.03 -0.46, 0.52 >0.9
1 CI = Confidence Interval
gtsummary::tbl_regression(mod2)
#> Warning in tcm * w: longer object length is not a multiple of shorter object
#> length
Characteristic Beta 95% CI1 p-value
pred


    A
    B 0.03 -0.46, 0.52 >0.9
1 CI = Confidence Interval

Created on 2024-12-23 with reprex v2.1.1

@ddsjoberg
Copy link
Owner

Thanks for the post @richardjtelford !

This warning arises from the broom.helpers::tidy_plus_plus(). Do you mind posting the issue there, please? https://github.com/larmarange/broom.helpers

glm(mpg ~ gear, data = mtcars, subset = mpg < 30) |> 
  broom.helpers::tidy_plus_plus()
#> Warning in tcm * w: longer object length is not a multiple of shorter object
#> length
#> # A tibble: 1 × 17
#>   term  variable var_label var_class var_type   var_nlevels contrasts
#>   <chr> <chr>    <chr>     <chr>     <chr>            <int> <chr>    
#> 1 gear  gear     gear      numeric   continuous          NA <NA>     
#> # ℹ 10 more variables: contrasts_type <chr>, reference_row <lgl>, label <chr>,
#> #   n_obs <dbl>, estimate <dbl>, std.error <dbl>, statistic <dbl>,
#> #   p.value <dbl>, conf.low <dbl>, conf.high <dbl>

Created on 2024-12-23 with reprex v2.1.1

@ddsjoberg
Copy link
Owner

Thanks @richardjtelford !

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

No branches or pull requests

2 participants