amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
433 stars 107 forks source link

Error with D3 function when examining the difference between two multinomial regression models #466

Closed truenomad closed 2 years ago

truenomad commented 2 years ago

When I run the likelihood ratio test using the D3 function from the mice package to test the difference between two different multiple imputed multinomial models, I get the following error:

Error: Column `logLik` not found in `.data` Run `rlang::last_error()` to see where the error occurred.

Could anyone suggest what could be going on here?

To reproduce this issue, see the following code. Any help on this would be really appreciated.

# load packages 
pacman::p_load(
  mice,        
  tidyverse)

# set seed
set.seed(2347723) 

# generate a samall sample of the boys dataset
boys <- sample(head(boys,100))

# multiple imputation
boys_mi <- mice(boys, m = 5)

# # Test model (for interaction)  -----------------------------------------

modela <- boys_mi %>%
  with(.,
       multinom(
         relevel(reg, ref = "south") ~ hgt * age)
  )

# null model
modelb <- boys_mi %>%
  with(.,
       multinom(
         relevel(reg, ref = "south") ~ hgt + age)
  )
# likelihood ratio test for interaction
D3(modela, modelb)
gerkovink commented 2 years ago

Hi @truenomad,

Thanks for opening your first mice issue. I don't know why you edited away your issue title and closed it, but perhaps you could share the reason for closing this issue as others may land on the same error message. That would still be very helpful to a much larger user base than you may suspect.

Thanks in advance.

truenomad commented 2 years ago

Hi @truenomad,

Thanks for opening your first mice issue. I don't know why you edited away your issue title and closed it, but perhaps you could share the reason for closing this issue as others may land on the same error message. That would still be very helpful to a much larger user base than you may suspect.

Thanks in advance.

Sorry I was unsure if this was the right place for these questions. New to the process of raising issues.

I am still struggling with the above. The only solution that seems to work is using the D2 function with the type = 'likelihood.' But not sure why that works. So maybe an explanation would be beneficial if that is the correct solutions