ddsjoberg / gtsummary

Presentation-Ready Data Summary and Analytic Result Tables
http://www.danieldsjoberg.com/gtsummary
Other
1.04k stars 114 forks source link

Compatibility with VGAM #1684

Open giovannitinervia9 opened 3 months ago

giovannitinervia9 commented 3 months ago

Are you going to work for getting gtsummary compatible with VGAM models? It would be great!

larmarange commented 3 months ago

It seems that some vglm() models are already covered.

To be noted, I did not find any officiel tidier for VGAM models, although some are covered by the parameter package.

Do you have any specific example of model not covered?

library(VGAM)
#> Le chargement a nécessité le package : stats4
#> Le chargement a nécessité le package : splines
library(gtsummary)

(d.AD <- data.frame(treatment = gl(3, 3),
                    outcome = gl(3, 1, 9),
                    counts = c(18,17,15,20,10,20,25,13,12)))
#>   treatment outcome counts
#> 1         1       1     18
#> 2         1       2     17
#> 3         1       3     15
#> 4         2       1     20
#> 5         2       2     10
#> 6         2       3     20
#> 7         3       1     25
#> 8         3       2     13
#> 9         3       3     12
mod <- vglm(counts ~ outcome + treatment, poissonff,
                 data = d.AD, trace = TRUE)
#> VGLM    linear loop  1 :  deviance = 5.181115
#> VGLM    linear loop  2 :  deviance = 5.129147
#> VGLM    linear loop  3 :  deviance = 5.129141
#> VGLM    linear loop  4 :  deviance = 5.129141

mod |> 
  tbl_regression() |> 
  as_kable()
#> ! `broom::tidy()` failed to tidy the model.
#> ✔ `tidy_parameters()` used instead.
#> ℹ Add `tidy_fun = broom.helpers::tidy_parameters` to quiet these messages.
Characteristic Beta 95% CI p-value
outcome
1
2 -0.45 -0.85, -0.06 0.025
3 -0.29 -0.67, 0.08 0.13
treatment
1
2 0.00 -0.39, 0.39 >0.9
3 0.00 -0.39, 0.39 >0.9

Created on 2024-05-21 with reprex v2.1.0

giovannitinervia9 commented 3 months ago

Thank you for your answer.

I've had problems with multinomial models.

library(VGAM)
library(gtsummary)

n = 99 # sample size

k = 3 # number of possible value of y

#three explicative variables
x1 = factor(sample(c("x1a", "x1b"), n, replace = T))
x2 = factor(sample(c("x2a", "x2b", "x2c"), n, replace = T))
x3 = rnorm(n)

# response variable, nominal and ordered
y.nom = factor(sample(c("y1a", "y1b", "y1c"), n, replace = T))
y.ord = factor(y.nom, ordered = T)

# some models
mod1 = VGAM::vglm(y.nom ~ x1 + x2 + x3, family = multinomial(parallel = F))
mod2 = VGAM::vglm(y.nom ~ x1 + x2 + x3, family = multinomial(parallel = T))

mod3 = VGAM::vglm(y.ord ~ x1 + x2 + x3, family = cumulative(parallel = F))
mod4 = VGAM::vglm(y.ord ~ x1 + x2 + x3, family = cumulative(parallel = T))

mod5 = VGAM::vglm(y.ord ~ x1 + x2 + x3, family = acat(parallel = F))
mod6 = VGAM::vglm(y.ord ~ x1 + x2 + x3, family = acat(parallel = T))

mod1 |> tbl_regression() |> as_kable()
mod2 |> tbl_regression() |> as_kable()
mod3 |> tbl_regression() |> as_kable()
mod4 |> tbl_regression() |> as_kable()
mod5 |> tbl_regression() |> as_kable()
mod6 |> tbl_regression() |> as_kable()
larmarange commented 3 months ago

It is related #1540 about a more general support of multi-component models.

There is also another issue regarding the lack of a proper tidier for such models and returning a standardized tibble with a term column and an y.level column. Did you ask VGAM developers' team if they plan to implement such feature? or to develop a broom.vgam package? It would be the best to ensure that tidiers are properly implemented.

The main challenge is to identify the schema of terms naming which is not consistent with other types of models. And it does not seems documented (at least I did not identify where it is).