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

tidy marginal predictions of multinomial and ordinal logistic models #215

Closed
tguerra opened this issue Feb 16, 2023 · 3 comments · Fixed by #219
Closed

tidy marginal predictions of multinomial and ordinal logistic models #215

tguerra opened this issue Feb 16, 2023 · 3 comments · Fixed by #219

Comments

@tguerra
Copy link

tguerra commented Feb 16, 2023

Hi !

I've tried to use broom.helpers and ggstats to generate marginal predictions from a multinomial model (using nnet package) and graph it (similarly to what is done with logistic regression on this webpage).

Any idea what's going on? I don't understand if the problem is located in broom.helpers, ggstats or elsewhere.

library(nnet)

mod <- multinom(Species ~ ., data = iris)
#> # weights:  18 (10 variable)
#> initial  value 164.791843 
#> iter  10 value 16.177348
#> iter  20 value 7.111438
#> iter  30 value 6.182999
#> iter  40 value 5.984028
#> iter  50 value 5.961278
#> iter  60 value 5.954900
#> iter  70 value 5.951851
#> iter  80 value 5.950343
#> iter  90 value 5.949904
#> iter 100 value 5.949867
#> final  value 5.949867 
#> stopped after 100 iterations

ggstats::ggcoef_multinom(
  model = mod,
  tidy_fun = broom.helpers::tidy_marginal_predictions,
  show_p_values = FALSE,
  signif_stars = FALSE,
  significance = NULL,
  vline = FALSE)
#> Error in `dplyr::left_join()`:
#> ! Join columns in `x` must be present in the data.
#> ✖ Problem with `y.level`.

mod |>
  broom.helpers::tidy_marginal_predictions()
#> 
#>  Term Estimate Std. Error   z   Pr(>|z|) CI low CI high
#>   4.3   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   5.1   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   5.8   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   6.4   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   7.9   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>     2   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   2.8   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>     3   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   3.3   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   4.4   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>     1   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   1.6   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>  4.35   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   5.1   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   6.9   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   0.1   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   0.3   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   1.3   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   1.8   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#>   2.5   0.3333          0 Inf < 2.22e-16 0.3333  0.3333
#> 
#> Prediction type:  
#> Columns: variable, term, type, estimate, std.error, statistic, p.value, conf.low, conf.high
@larmarange
Copy link
Owner

Hi

some adaptation of the code will be required for compatibility with multinomial model.

I will try to work on it next week.

@larmarange larmarange changed the title tidy marginal predictions of multinomial models tidy marginal predictions of multinomial and ordinal logistic models Feb 23, 2023
@larmarange
Copy link
Owner

Hi @tguerra

you could try this dev version #219 that could be installed with remotes::install_github("larmarange/broom.helpers#219")

@tguerra
Copy link
Author

tguerra commented Mar 4, 2023

It works very well with multinomials, thank you!

@tguerra tguerra closed this as completed Mar 4, 2023
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.

2 participants