Open MaBKo opened 3 days ago
Thanks for reporting, and the reproducible example! Will look into this.
Seems to work now, but not sure if the output is sensible?
data(Salamanders, package = "glmmTMB")
mod_trunc_error <- glmmTMB::glmmTMB(
count ~ spp + mined + (1 | site),
data = Salamanders[Salamanders$count > 0, , drop = FALSE],
family = glmmTMB::truncated_nbinom2(),
ziformula = ~ 0,
dispformula = ~ 1
)
performance::check_collinearity(mod_trunc_error)
#> # Check for Multicollinearity
#>
#> * conditional component:
#>
#> Low Correlation
#>
#> Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
#> spp 1.03 [1.00, 2.32] 1.02 0.97 [0.43, 1.00]
#> mined 1.03 [1.00, 2.32] 1.02 0.97 [0.43, 1.00]
Created on 2024-11-26 with reprex v2.1.1
Important:
In my initial post, I forgot to filter the dataset for zeros in the mod_whole
part:
It should be
mod_whole<-glmmTMB(count~spp+mined+(1|site)+(1|spp),
data=Salamanders%>%filter(count>0), family="truncated_nbinom2",
ziformula = ~1, dispformula = ~1)
Instead of
mod_whole<-glmmTMB(count~spp+mined+(1|site)+(1|spp),
data=Salamanders, family="truncated_nbinom2",
ziformula = ~1, dispformula = ~1)
Whats the best practice here? Leaving it in this comment or editing the original post?
To @strengejacke's solution:
As stated before I'm not a person with solid statistical knowledge, but I guess that did the trick.
My understanding is that the vif results of the post-hurdle only model should be the same as the conditional component of the whole hurdle model, which seems to be the case, comparing the output of the corrected mod_whole
with the ouput from @strengejacke's model
library(glmmTMB)
library(easystats)
library(tidyverse)
library(reprex)
#> Warning: package 'reprex' was built under R version 4.4.2
mod_whole<-glmmTMB(count~spp+mined+(1|site)+(1|spp),
data=Salamanders%>%filter(count>0), family="truncated_nbinom2",
ziformula = ~1, dispformula = ~1)
check_collinearity(mod_whole)
#> # Check for Multicollinearity
#>
#> * conditional component:
#>
#> Low Correlation
#>
#> Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
#> spp 1.03 [1.00, 2.30] 1.02 0.97 [0.43, 1.00]
#> mined 1.03 [1.00, 2.30] 1.02 0.97 [0.43, 1.00]
check_model(mod_whole, panel=F)
#> `check_outliers()` does not yet support models of class `glmmTMB`.
Created on 2024-11-27 with reprex v2.1.1
But maybe someone with a deeper understanding of the glmmTMB
package or general statistical knowledge could weigh in.
P.S: I also want to say a big thank you to all contributors of this awesome package; the package and its documentation helped me a lot.
Whats the best practice here? Leaving it in this comment or editing the original post?
Doesn't matter, I have a reproducible example and added a test, so no need to edit the posts.
My understanding is that the vif results of the post-hurdle only model should be the same as the conditional component of the whole hurdle model, which seems to be the case, comparing the output of the corrected mod_whole with the ouput from @strengejacke's model
Great! I'll merge the PR once all tests pass.
(First time opening an issue on github, please bear with me) Foreword: I'm a trained entomologist, with statistical and R-knowledge gathered through "learning by doing", so if this is just user error, I want to apologise in advance.
Stumbled upon this error, using a
glmmTMB
model with only the truncated "post hurdle" part (lacking a better descriptor):Error: check_model() returned following error: 'data' must be of a vector type, was 'NULL'
As far as I understand it, the usage of the
truncated_nbinom2
family argument leads to this error, if thezi-component
is deactivated.Creating the model which produces the error:
Created on 2024-11-26 with reprex v2.1.1
Creating a whole hurdle model working fine (plotting deactivated; works as intended):
Created on 2024-11-26 with reprex v2.1.1
Creating a post-hurdle model but with "normal" negbin2-family instead of the truncated version working fine (plotting deactivated; works as intended):
Created on 2024-11-26 with reprex v2.1.1
Session info
Created on 2024-11-26 with reprex v2.1.1