eco-stats / ecostats

0 stars 1 forks source link

glmmTMB errors for anovaPB #5

Open mmcgillycuddy opened 1 month ago

mmcgillycuddy commented 1 month ago

Hi David, I am getting some errors when using glmmTMB objects for anovaPB.

library(ecostats)
library(glmmTMB)
fm1 <- glmmTMB(count~mined+(1|spp),
               data=Salamanders,
               family=nbinom2)
fm0 <- update(fm1, ~ . - mined)
anovaPB(fm0, fm1, n.sim = 100)
Error in checkForRemoteErrors(val) : 
  100 nodes produced errors; first error: object 'nbinom2' not found
In addition: Warning message:
In Ops.factor(1, spp) : ‘|’ not meaningful for factors
dwarton commented 1 month ago

drats... it seems that the nbinom2 family is not getting passed to the nodes when using multiple processors. You can beat this issue for the moment by using the argument ncpus=1 in your anovaPB call.

mmcgillycuddy commented 1 month ago

Ok, thanks.

Meanwhile I came across another problem where I seem to get very different results if I run a bootstrap myself. For a LR = 545 and df =1 I would expect a small p-value but I get 0.941.

library(ecostats)
library(glmmTMB)
fm1 <- glmmTMB(count ~ mined + (1|spp), data = Salamanders, family=poisson())
fm0 <- update(fm1, ~ . - mined)
LRobs <- anova(fm1, fm0)[2, 6]
LRobs
LRstat <- rep(NA, 100)
for(i in 1:100){
  simy <- simulate(fm0)[[1]]
  ft_sim1 <- glmmTMB(simy~mined+(1|spp),
                     data=Salamanders,
                     family=poisson() )
  ft_sim0 <-  update(ft_sim1, ~ . - mined)
  LRstat[i] <- anova(ft_sim1, ft_sim0)[2, 6]
}
(sum(LRstat >= LRobs, na.rm = T) + 1)/(100+1)
anovaPB(fm0, fm1, n.sim = 1000)
dwarton commented 1 month ago

OK, the issue there is that you need to set colRef=6, I'll change the default next update so that it does that

mmcgillycuddy commented 1 month ago

Oh nice! That's easy. Thanks David!