strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
608 stars 93 forks source link

tab_model problem merging two multinomial models #558

Open Crismoc opened 5 years ago

Crismoc commented 5 years ago

There seems to be a problem when using tab_model() with multinomial models fitted with nnet. This was working before, but I am not sure if it was an update in sjPlot or a change in another package. Here is a reprex of the issue

mod <- nnet::multinom(cyl ~ am + hp, data=mtcars, Hess=TRUE)
#> # weights:  12 (6 variable)
#> initial  value 35.155593 
#> iter  10 value 8.146111
#> iter  20 value 4.460766
#> iter  30 value 4.037448
#> iter  40 value 3.959319
#> iter  50 value 3.905404
#> iter  60 value 3.893052
#> iter  70 value 3.875662
#> iter  80 value 3.860592
#> iter  90 value 3.851425
#> final  value 3.851368 
#> converged
sjPlot::tab_model(mod)
#> Error in UseMethod("model_parameters"): no applicable method for 'model_parameters' applied to an object of class "c('multinom', 'nnet')"

Created on 2019-10-21 by the reprex package (v0.3.0)

strengejacke commented 5 years ago

Should be fixed now (bug was in other packages), but requires the other packages to be updated on CRAN (and this package as well) - so either wait for the next updated, or install following packages from GitHub:

https://github.com/easystats/insight, https://github.com/easystats/parameters and https://github.com/easystats/effectsize.

nbreznau commented 4 years ago

I am running nnet::multinom and have installed the above three packages. I still get tab_model output that lists each parameter 2 times.

Here is a reproducible example using these data:

# I'm running 4.0.2 and these packages are loaded
pacman::p_load("ggplot2","dplyr","readr","plotscale","lattice","tidyr","readxl","mlogit","jtools","sjPlot","sjmisc","sjlabelled","knitr","kableExtra","lavaan","reshape2","semPlot","lavaanPlot","leaps","lme4","multilevelTools","rvest","nnet","parameters","insight","effectsize","foreign")
ml <- read.dta("https://stats.idre.ucla.edu/stat/data/hsbdemo.dta")
ml$prog2 <- relevel(ml$prog, ref = "academic")
test <- multinom(prog2 ~ ses + write, data = ml)
test2 <- multinom(prog2 ~ ses + write + math, data = ml)
tab_model(test,test2, file = "results/test.htm")
Crismoc commented 4 years ago

The code works for me, this reprex produces the html desired table:

ml <- foreign::read.dta("https://stats.idre.ucla.edu/stat/data/hsbdemo.dta")
ml$prog2 <- relevel(ml$prog, ref = "academic")
test <- nnet::multinom(prog2 ~ ses + write, data = ml)
#> # weights:  15 (8 variable)
#> initial  value 219.722458 
#> iter  10 value 179.982880
#> final  value 179.981726 
#> converged
test2 <- nnet::multinom(prog2 ~ ses + write + math, data = ml)
#> # weights:  18 (10 variable)
#> initial  value 219.722458 
#> iter  10 value 171.704109
#> final  value 170.861739 
#> converged
sjPlot::tab_model(test,test2)

image

nbreznau commented 4 years ago

Interesting. Here's mine. test

nbreznau commented 4 years ago

BTW: thanks in general for such great packages!

strengejacke commented 4 years ago

Yes, I can reproduce your error. While the initial issue was only about a single multinomial model, your issue concerns merging two multinomial models. Will re-open and see how to address this...

kuenze commented 3 months ago

Hi guys,

I know that this issue was already discussed a while ago but I now wanted to merge two multinomial models and use tab_models() and I still get the same error. Has this problem been solved by one of you?

Thank you in advance!

Interesting. Here's mine. test