florianhartig / DHARMa

Diagnostics for HierArchical Regession Models
http://florianhartig.github.io/DHARMa/
200 stars 21 forks source link

testZeroInflation returns ratioObsSim = Inf #381

Closed EIvimeyCook closed 1 year ago

EIvimeyCook commented 1 year ago

Hi,

I'm having a bit of an issue understanding the output from the testZeroInflation function.

If i run a very simple model such as this (this is just an example but the result from this and more complex models are the same).

m1 <- glmmTMB(lrs ~ 1, data = repro, family = "poisson")

s1a <- simulateResiduals(m1)
testZeroInflation(s1a)

The output i get it:

DHARMa zero-inflation test via comparison to expected zeros with simulation under H0 = fitted model
data:  simulationOutput
ratioObsSim = Inf, p-value < 2.2e-16
alternative hypothesis: two.sided

In this particular dataset, there are 6 zero values.

I'm not entirely sure what to make of this output and ratioObsSim = Inf

Using glmmTMB v 1.1.5 and DHARMa v 0.4.6.

Any advice would be great!

florianhartig commented 1 year ago

I assume it is inf because in the simulations, the mean number of simulated zeros is 0, so the ratio obs/sim is 6/0. Can you

florianhartig commented 1 year ago

Also, have you tried to switch on the ZIP term in glmmTMB - does that suggest zero-inflation?

EIvimeyCook commented 1 year ago

Hi,

See below! That makes complete sense, as you said, i think it's because the high predictions make zeros impossible.

ZI_plot

The ZIP term definitely suggests zero-inflation.

Zero-inflation model:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -4.3694     0.4108  -10.64   <2e-16 ***

I had just been concerned about the Inf RatioObsSim: but it makes complete sense as to why! Just thought i had misspecified something....

florianhartig commented 1 year ago

yeah, not sure about the zero-inflation though, note that the ZIP model in glmmTMB has, afaik, a logit link, so you should read -4 as an extremely low probability of zeros. For seeing if you have zero-inf, look at AIC or DHARMa simulateLRT.

Have you checked for overdispersion? You are fitting a Poisson model - it would be very rare that you don’t have overdispersion in real data. In this case, change to neg bin.

EIvimeyCook commented 1 year ago

Aaah ok -

So in this case:

DHARMa simulated LRT

data:  m0: m1 m1: m2
LogL(M1/M0) = 37.09, p-value < 2.2e-16
alternative hypothesis: M1 describes the data better than M0

m1 is a zinb model, and m0 is a nb model.

florianhartig commented 1 year ago

Yes that is in favor of ZIP but I would still check for overdispersion.

OK, but I think there’s nothing wrong with the DHARMa output, so I will close this.