daijiang / phyr

Functions for phylogenetic analyses
https://daijiang.github.io/phyr/
GNU General Public License v3.0
30 stars 10 forks source link

DHARMa simulate residuals issue #77

Closed hhollandmoritz closed 2 years ago

hhollandmoritz commented 2 years ago

Hi!

I'm currently interested in starting to use phyr on a dataset and while working through the pglmm example, I got this error at the DHARMa simulate residuals step:

> ## Check model assumptions
> resids <- DHARMa::simulateResiduals(mod_bayes, plot = FALSE)
Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  : 
  'data' must be of a vector type, was 'NULL'
In addition: Warning message:
In checkModel(fittedModel) :
  DHARMa: fittedModel not in class of supported models. Absolutely no guarantee that this will work!

The maximum likelihood variant works fine.

Based on discussions in issue 73, I tried to update to the most recent version of phyr with remotes::install_github("daijiang/phyr")

But that didn't solve the problem.

Any thoughts about what might be going on?

Here's my session info:

R version 4.1.3 (2022-03-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora Linux 35 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libflexiblas.so.3.2

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] 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   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] ape_5.6-2       phyr_1.1.0      forcats_0.5.1   stringr_1.4.0  
 [5] dplyr_1.0.9     purrr_0.3.4     readr_2.1.2     tidyr_1.2.0    
 [9] tibble_3.1.8    ggplot2_3.3.6   tidyverse_1.3.2 INLA_22.05.07  

loaded via a namespace (and not attached):
 [1] nlme_3.1-158            fs_1.5.2               
 [3] lubridate_1.8.0         RColorBrewer_1.1-3     
 [5] httr_1.4.3              rprojroot_2.0.3        
 [7] numDeriv_2016.8-1.1     Deriv_4.1.3            
 [9] tools_4.1.3             backports_1.4.1        
[11] utf8_1.2.2              R6_2.5.1               
[13] vegan_2.6-2             DBI_1.1.3              
[15] mgcv_1.8-40             colorspace_2.0-3       
[17] permute_0.9-7           withr_2.5.0            
[19] sp_1.5-0                tidyselect_1.1.2       
[21] GGally_2.1.2            mnormt_2.1.0           
[23] phangorn_2.9.0          compiler_4.1.3         
[25] rvest_1.0.2             cli_3.3.0              
[27] expm_0.999-6            xml2_1.3.3             
[29] labeling_0.4.2          scales_1.2.0           
[31] quadprog_1.5-8          ggridges_0.5.3         
[33] digest_0.6.29           minqa_1.2.4            
[35] DHARMa_0.4.5            pkgconfig_2.0.3        
[37] lme4_1.1-30             plotrix_3.8-2          
[39] dbplyr_2.2.1            maps_3.4.0             
[41] rlang_1.0.4             readxl_1.4.0           
[43] rstudioapi_0.13         farver_2.1.1           
[45] generics_0.1.3          combinat_0.0-8         
[47] jsonlite_1.8.0          googlesheets4_1.0.0    
[49] magrittr_2.0.3          CoprManager_0.3.10     
[51] Matrix_1.4-1            Rcpp_1.0.9             
[53] munsell_0.5.0           fansi_1.0.3            
[55] lifecycle_1.0.1         scatterplot3d_0.3-41   
[57] stringi_1.7.8           snakecase_0.11.0       
[59] clusterGeneration_1.3.7 MASS_7.3-58.1          
[61] plyr_1.8.7              grid_4.1.3             
[63] parallel_4.1.3          crayon_1.5.1           
[65] lattice_0.20-45         haven_2.5.0            
[67] stargazer_5.2.3         splines_4.1.3          
[69] hms_1.1.1               pillar_1.8.0           
[71] igraph_1.3.4            boot_1.3-28            
[73] codetools_0.2-18        fastmatch_1.1-3        
[75] reprex_2.0.1            picante_1.8.2          
[77] glue_1.6.2              modelr_0.1.8           
[79] vctrs_0.4.1             nloptr_2.0.3           
[81] tzdb_0.3.0              MatrixModels_0.5-0     
[83] cellranger_1.1.0        gtable_0.3.0           
[85] reshape_0.8.9           assertthat_0.2.1       
[87] janitor_2.1.0           gap.datasets_0.0.5     
[89] broom_1.0.0             phytools_1.0-3         
[91] coda_0.19-4             googledrive_2.0.0      
[93] gargle_1.2.0            cluster_2.1.3          
[95] ellipsis_0.3.2          gap_1.2.3-6            
[97] here_1.0.1

Thanks! Hannah

P.S. In case it's helpful, here's the result of traceback() after the DHARMa function.

> traceback()
7: array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), 
       NULL) else NULL)
6: as.matrix.default(frame)
5: as.matrix(frame)
4: data.matrix(out)
3: getSimulations.default(fittedModel, nsim = n, type = "normal", 
       ...)
2: getSimulations(fittedModel, nsim = n, type = "normal", ...)
1: DHARMa::simulateResiduals(mod_bayes, plot = FALSE)
rdinnager commented 2 years ago

This is due to phyr's simulate function being broken for Bayesian models because of an update to the INLA package. I already have a fix under way. I'll let you know when the changes are up.

hhollandmoritz commented 2 years ago

Excellent, thank you so much! I'm very excited to start working with this package. :)