drizopoulos / GLMMadaptive

GLMMs with adaptive Gaussian quadrature
https://drizopoulos.github.io/GLMMadaptive/
59 stars 14 forks source link

Error in negative.binomial() : 'theta' must be specified #25

Closed caimiao0714 closed 4 years ago

caimiao0714 commented 4 years ago

Hi there,

I was trying to implement the negative binomial model example. However, I got the following error message:

library(GLMMadaptive)
> set.seed(102)
> dd <- expand.grid(f1 = factor(1:3), f2 = LETTERS[1:2], g = 1:30, rep = 1:15,
+                   KEEP.OUT.ATTRS = FALSE)
> mu <- 5 * (-4 + with(dd, as.integer(f1) + 4 * as.numeric(f2)))
> dd$y <- rnbinom(nrow(dd), mu = mu, size = 0.5)
> 
> gm1 <-  mixed_model(fixed = y ~ f1 * f2, random = ~ 1 | g, data = dd,
+                     family = negative.binomial())
Error in negative.binomial() : 'theta' must be specified

here is my session information:

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default
BLAS/LAPACK: /opt/intel/18.0.3/compilers_and_libraries_2018.3.222/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] optimParallel_0.8-1 dplyr_0.8.3         data.table_1.12.8   nloptr_1.2.1        optimx_2018-7.10   
[6] lme4_1.1-21         Matrix_1.2-17       GLMMadaptive_0.6-9 

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5    remotes_2.1.0       purrr_0.3.2         splines_3.6.0       lattice_0.20-38    
 [6] testthat_2.2.1      usethis_1.5.1       rlang_0.4.0         pkgbuild_1.0.5      pillar_1.4.2       
[11] glue_1.3.1          withr_2.1.2         sessioninfo_1.1.1   matrixStats_0.55.0  devtools_2.1.0     
[16] memoise_1.1.0       fst_0.9.0           callr_3.3.1         ps_1.3.0            curl_4.0           
[21] Rcpp_1.0.3          backports_1.1.4     desc_1.2.0          pkgload_1.0.2       fs_1.3.1           
[26] packrat_0.5.0       digest_0.6.20       processx_3.4.1      numDeriv_2016.8-1.1 grid_3.6.0         
[31] rprojroot_1.3-2     cli_1.1.0           tools_3.6.0         magrittr_1.5        tibble_2.1.3       
[36] pacman_0.5.1        crayon_1.3.4        pkgconfig_2.0.2     MASS_7.3-51.4       prettyunits_1.0.2  
[41] assertthat_0.2.1    minqa_1.2.4         rstudioapi_0.10     R6_2.4.0            boot_1.3-22        
[46] nlme_3.1-139        compiler_3.6.0

Thank you, Miao

drizopoulos commented 4 years ago

This logically happens because the negative.binomial() family function from lme4 has overwritten the function with the same name from GLMMadaptive. Try fitting again the model by specifying in mixed_model() the family argument as family = GLMMadaptive:::negative.binomial().

caimiao0714 commented 4 years ago

This logically happens because the negative.binomial() family function from lme4 has overwritten the function with the same name from GLMMadaptive. Try fitting again the model by specifying in mixed_model() the family argument as family = GLMMadaptive:::negative.binomial().

Thank you! Is it possible to specify an offset term in mixed-effect negative binomial models?

drizopoulos commented 4 years ago

Yes, you can include an offset directly into the fixed effects formula.