简体   繁体   中英

How do you calculate the expected number of zeros in a Poisson distributed mixed-effects model in R?

I am working on a dataset and fit a poisson distributed mixed effects model. I would like to calculate the expected number of zeros that my model predicts and compare that to the observed number of zeros in the actual dataset. Although I have seen many posts discussing the underlying mathematics of this, the code to implement such mathematics is unclear to me and I cannot seem to find any clear answers.

As far as I am aware, I am looking for a way to compute P(Yi=0|xi)=e−λ for a mixed-effects model in R.

A little background on my dataset. The response variable is a count (number of individual butterflies) and my predictor variables are mostly proportions (eg proportion of habitat covered by flowers). I also have a random variable: PatchID. I fitted a poisson distributed mixed-effects model in the package lme4.

Model Output:

Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson  ( log )
Formula: spp_icarus ~ BareGround + Shrub + Grass + AllFlowers + CowsVetch +  
CanopyCover + avg.bft + season.bft + (1 | PatchID)
Data: icarusdata2

 AIC      BIC   logLik deviance df.resid 
804.8    835.2   -392.4    784.8      144 

Scaled residuals: 
Min     1Q Median     3Q    Max 
-4.819 -0.844 -0.350  0.443 77.147 

Random effects:
Groups  Name        Variance Std.Dev.
PatchID (Intercept) 2.69     1.64    
Number of obs: 154, groups:  PatchID, 39

Fixed effects:
        Estimate Std. Error z value Pr(>|z|)    
(Intercept)   0.3069     0.5750   0.534 0.593512    
BareGround   -5.7246     0.8096  -7.071 1.54e-12 ***
Shrub       -50.1908     5.8837  -8.530  < 2e-16 ***
Grass        -1.3167     0.5608  -2.348 0.018875 *  
AllFlowers   11.2299     1.5986   7.025 2.14e-12 ***
CowsVetch   -51.2781     8.0523  -6.368 1.91e-10 ***
CanopyCover   0.1029     2.3806   0.043 0.965537    
avg.bft     -48.1492     7.0559  -6.824 8.86e-12 ***
season.bft1   2.0350     0.6045   3.367 0.000761 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Ok, my interpretation of this post can be translated into R code as follows. With your fitted model model you can predict the expected response for each observation:

lambda_hat <- predict(model, type = "response")

For a Poisson distribution the expected value corresponds to the lambda parameter. And we know that the probability of zeros is exp(-lambda) . So we can calculate the probability of zero for each observation and sum them up to get the expected number of zeros:

expected_zeros <- sum(exp(-lambda_hat))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM