gtsummary
gtsummary copied to clipboard
Feature request: making tbl_regression() compatible with svymultinom() / svy_vglm() outputs
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
There are two things to consider:
- Do we have a tidy() method for
CMAverse::svymultinom(). I know thatsvrepmisc::svymultinom()implementation (using the same aproach) does have it. tbl_regression()needs to bee more generic about multicomponent models, cf. #1540
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)
Once again, for a proper support, we need first to fix #1540 and then to update broom.helpers accordingly
Best regards