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

Feature request: making tbl_regression() compatible with svymultinom() / svy_vglm() outputs #1608

Open
alexandrayas opened this issue Feb 28, 2024 · 3 comments

Comments

@alexandrayas
Copy link

I have been using tbl_regression() to produce tables displaying multinom() outputs. However I need to weight my analysis and have been using svymultinom() (from CMAverse: https://github.com/BS1125/CMAverse) to do this. I would love to produce tables for these outputs too, however I don't think think this is supported currently.

Similarly I can produce tables for a vglm() (from VGAM) output, but not svy_vglm (from svyVGAM).

Is there a work around for this?

Thank you

@larmarange
Copy link
Collaborator

There are two things to consider:

  1. Do we have a tidy() method for CMAverse::svymultinom(). I know that svrepmisc::svymultinom() implementation (using the same aproach) does have it.
  2. tbl_regression() needs to bee more generic about multicomponent models, cf. Feature request: Support for multi-components models #1540

@alexandrayas
Copy link
Author

Thanks for your quick reply. I had another query I was about to post on stackoverflow but actually this relates to the same issue.

I've also been using the VGAM::vglm() to fit multinomial logit models as I thought vglm() models were compatible with tbl_regression() but I don't think it works in this case. I'd like an output similar to that produced when using multinom(), as you suggested on the other thread.

> multLogitVGLM <- vglm(cbind(e0, e1, e2, e3) ~ timeInt + sex + ethnicity + hhincome_11 + parent_dailsmk_12, family = multinomial(refLevel = 1), data = dfimpLong)

> multLogitVGLM

Call:
vglm(formula = cbind(e0, e1, e2, e3) ~ timeInt + sex + ethnicity + 
    hhincome_11 + parent_dailsmk_12, family = multinomial(refLevel = 1), 
    data = dfimpLong)


Coefficients:
         (Intercept):1          (Intercept):2          (Intercept):3              timeInt:1              timeInt:2 
           -1.07285969            -4.66330565            -2.44357706            -0.06668069             0.47041720 
             timeInt:3            sexFemale:1            sexFemale:2            sexFemale:3       ethnicityBAME*:1 
            0.23124890             0.17373448             0.80105971            -0.33116889             0.12846803 
      ethnicityBAME*:2       ethnicityBAME*:3   hhincome_11430-559:1   hhincome_11430-559:2   hhincome_11430-559:3 
           -0.71503275            -0.58453115            -0.21189162            -0.16407150            -0.25399205 
  hhincome_11240-429:1   hhincome_11240-429:2   hhincome_11240-429:3      hhincome_11<240:1      hhincome_11<240:2 
            0.12482068            -0.03994199             0.40814847            -0.24953751            -0.92927210 
     hhincome_11<240:3 parent_dailsmk_12Yes:1 parent_dailsmk_12Yes:2 parent_dailsmk_12Yes:3 
           -0.33789652            -0.55539843            -0.44771708             0.16109892 

Degrees of Freedom: 7119 Total; 7095 Residual
Residual deviance: 4173.659 
Log-likelihood: -2086.829 

This is a multinomial logit model with 4 levels

> tbl_regression(multLogitVGLM, tidy_fun = broom.helpers::tidy_parameters)
Error in `tibble::tibble()`:
! Tibble columns must have compatible sizes.
• Size 24: Existing data.
• Size 8: Column `variable`.
ℹ Only values of size one are recycled.
Backtrace:
  1. gtsummary::tbl_regression(multLogitVGLM, tidy_fun = broom.helpers::tidy_parameters)
 10. broom.helpers::tidy_identify_variables(., quiet = quiet)
 12. broom.helpers:::model_identify_variables.default(model)
 20. tibble::tibble(term = colnames(model_matrix), variable = variables[assign])

# below works fine

> multLogitVGLM <- vglm(e0 ~ timeInt + sex + ethnicity + hhincome_11 + parent_dailsmk_12, family = multinomial(refLevel = 1), data = dfimpLong)

> multLogitVGLM

Call:
vglm(formula = e0 ~ timeInt + sex + ethnicity + hhincome_11 + 
    parent_dailsmk_12, family = multinomial(refLevel = 1), data = dfimpLong)


Coefficients:
         (Intercept)              timeInt            sexFemale       ethnicityBAME*   hhincome_11430-559 
          0.90504708          -0.08317794          -0.07338119           0.11953831           0.21457882 
  hhincome_11240-429      hhincome_11<240 parent_dailsmk_12Yes 
         -0.19683651           0.33837123           0.30666168 

Degrees of Freedom: 2373 Total; 2365 Residual
Residual deviance: 2926.447 
Log-likelihood: -1463.224 

This is a multinomial logit model with 2 levels

> tbl_regression(multLogitVGLM, tidy_fun = broom.helpers::tidy_parameters)

@larmarange
Copy link
Collaborator

Once again, for a proper support, we need first to fix #1540 and then to update broom.helpers accordingly

Best regards

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