简体   繁体   中英

Different outputs using ggpredict for glmer and glmmTMB model

I am trying to predict and graph models with species presence as the response. However I've run into the following problem: the ggpredict outputs are wildly different for the same data in glmer and glmmTMB. However, the estimates and AIC are very similar. These are simplified models only including date (which has been centered and scaled), which seems to be the most problematic to predict.

yntest<- glmer(MYOSOD.P~ jdate.z + I(jdate.z^2) + I(jdate.z^3) +
             (1|area/SiteID), family = binomial,  data = sodpYN)


> summary(yntest)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
 Family: binomial  ( logit )
Formula: MYOSOD.P ~ jdate.z + I(jdate.z^2) + I(jdate.z^3) + (1 | area/SiteID)
   Data: sodpYN

     AIC      BIC   logLik deviance df.resid 
  1260.8   1295.1   -624.4   1248.8     2246 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.0997 -0.3218 -0.2013 -0.1238  9.4445 

Random effects:
 Groups      Name        Variance Std.Dev.
 SiteID:area (Intercept) 1.6452   1.2827  
 area        (Intercept) 0.6242   0.7901  
Number of obs: 2252, groups:  SiteID:area, 27; area, 9

Fixed effects:
             Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -2.96778    0.39190  -7.573 3.65e-14 ***
jdate.z      -0.72258    0.17915  -4.033 5.50e-05 ***
I(jdate.z^2)  0.10091    0.08068   1.251  0.21102    
I(jdate.z^3)  0.25025    0.08506   2.942  0.00326 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) jdat.z I(.^2)
jdate.z      0.078              
I(jdat.z^2) -0.222 -0.154       
I(jdat.z^3) -0.071 -0.910  0.199

The glmmTMB model + summary:

Tyntest<- glmmTMB(MYOSOD.P ~ jdate.z + I(jdate.z^2) + I(jdate.z^3) + 
                (1|area/SiteID), family = binomial("logit"), data = sodpYN)

> summary(Tyntest)
 Family: binomial  ( logit )
Formula:          MYOSOD.P ~ jdate.z + I(jdate.z^2) + I(jdate.z^3) + (1 | area/SiteID)
Data: sodpYN

     AIC      BIC   logLik deviance df.resid 
  1260.8   1295.1   -624.4   1248.8     2246 

Random effects:

Conditional model:
 Groups      Name        Variance Std.Dev.
 SiteID:area (Intercept) 1.6490   1.2841  
 area        (Intercept) 0.6253   0.7908  
Number of obs: 2252, groups:  SiteID:area, 27; area, 9

Conditional model:
             Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -2.96965    0.39638  -7.492 6.78e-14 ***
jdate.z      -0.72285    0.18250  -3.961 7.47e-05 ***
I(jdate.z^2)  0.10096    0.08221   1.228  0.21941    
I(jdate.z^3)  0.25034    0.08662   2.890  0.00385 ** 
---

ggpredict outputs

testg<-ggpredict(yntest, terms ="jdate.z[all]")
> testg

# Predicted probabilities of MYOSOD.P
# x = jdate.z

     x predicted std.error conf.low conf.high
 -1.95     0.046     0.532    0.017     0.120
 -1.51     0.075     0.405    0.036     0.153
 -1.03     0.084     0.391    0.041     0.165
 -0.58     0.072     0.391    0.035     0.142
 -0.14     0.054     0.390    0.026     0.109
  0.35     0.039     0.399    0.018     0.082
  0.79     0.034     0.404    0.016     0.072
  1.72     0.067     0.471    0.028     0.152

Adjusted for:
* SiteID = 0 (population-level)
*   area = 0 (population-level)

Standard errors are on link-scale (untransformed).

testgTMB<- ggpredict(Tyntest, "jdate.z[all]")
> testgTMB

# Predicted probabilities of MYOSOD.P
# x = jdate.z

     x predicted std.error conf.low conf.high
 -1.95     0.444     0.826    0.137     0.801
 -1.51     0.254     0.612    0.093     0.531
 -1.03     0.136     0.464    0.059     0.280
 -0.58     0.081     0.404    0.038     0.163
 -0.14     0.054     0.395    0.026     0.110
  0.35     0.040     0.402    0.019     0.084
  0.79     0.035     0.406    0.016     0.074
  1.72     0.040     0.444    0.017     0.091

Adjusted for:
* SiteID = NA (population-level)
*   area = NA (population-level)

Standard errors are on link-scale (untransformed).

The estimates are completely different and I have no idea why. I did try to use both the ggeffects package from CRAN and the developer version in case that changed anything. It did not. I am using the most up to date version of glmmTMB.

This is my first time asking a question here so please let me know if I should provide more information to help explain the problem.

I checked and the issue is the same when using predict instead of ggpredict, which would imply that it is a glmmTMB issue? GLMER:

 dayplotg<-expand.grid(jdate.z=seq(min(sodp$jdate.z), max(sodp$jdate.z), length=92))
    Dfitg<-predict(yntest, re.form=NA, newdata=dayplotg, type='response')
    dayplotg<-data.frame(dayplotg, Dfitg)
    head(dayplotg)
    > head(dayplotg)
        jdate.z      Dfitg
    1 -1.953206 0.04581691
    2 -1.912873 0.04889584
    3 -1.872540 0.05195598
    4 -1.832207 0.05497553
    5 -1.791875 0.05793307
    6 -1.751542 0.06080781

glmmTMB:

dayplot<-expand.grid(jdate.z=seq(min(sodp$jdate.z), max(sodp$jdate.z), length=92), 
                     SiteID=NA,
                     area=NA) 

Dfit<-predict(Tyntest,  newdata=dayplot, type='response')
head(Dfit)

dayplot<-data.frame(dayplot, Dfit)
head(dayplot)
> head(dayplot)
    jdate.z SiteID area      Dfit
1 -1.953206     NA   NA 0.4458236
2 -1.912873     NA   NA 0.4251926
3 -1.872540     NA   NA 0.4050944
4 -1.832207     NA   NA 0.3855801
5 -1.791875     NA   NA 0.3666922
6 -1.751542     NA   NA 0.3484646

I contacted the ggpredict developer and figured out that if I used poly(jdate.z,3) rather than jdate.z + I(jdate.z^2) + I(jdate.z^3) in the glmmTMB model, the glmer and glmmTMB predictions were the same.

I'll leave this post up even though I was able to answer my own question in case someone else has this question later.

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