pbs-assess / sdmTMB

:earth_americas: An R package for spatial and spatiotemporal GLMMs with TMB
https://pbs-assess.github.io/sdmTMB/
183 stars 26 forks source link

Models with smooth terms no longer run - "object of type 'symbol' is not subsettable" #261

Closed seananderson closed 10 months ago

seananderson commented 11 months ago

Discussed in https://github.com/pbs-assess/sdmTMB/discussions/260

Originally posted by **nilescbn** October 10, 2023 ### The Error I'm a very new user of sdmTMB but have successfully run a number of models on fisheries data. In going back to some models I was running successfully last week. I'm getting this error and have traced it to the inclusion of smooth terms: > Error in x[[3]] : object of type 'symbol' is not subsettable I came back to the models because I was having convergence problems. I saw the note about the nlminb_loops. Increasing the number of loops to 2 worked on models without smooth terms. I tried installing the development version of sdmTMB but that didn't solve it. I tried running the same model with smooth terms using gam() from mgcv and it runs. Same for brm() from brms. ### Simulated Example In terms of reproducible example, using this simulated data I get the same errror. `sim_data <- data.frame(X = runif(1000, 164.5, 415), Y = runif(1000, 4560, 5366), depth = runif(1000, 100, 300), haul_hours = runif(1000, 0.5, 5), catch = rnorm(1000, mean = 50, sd = 24) ) ` `sim_mesh <- make_mesh(sim_data, xy_cols = c("X", "Y"), cutoff = 10)` This runs: ` m1 <- sdmTMB(catch ~ depth + haul_hours, data = sim_data, mesh = sim_mesh, anisotropy = FALSE, spatial = "on") ` This produces the error: `m1s <- sdmTMB(catch ~ s(depth) + s(haul_hours), data = sim_data, mesh = sim_mesh, anisotropy = FALSE, spatial = "on")` ### Traceback This is from RStudio's Traceback feature. 7. deparse(x, 500L) 6. paste(deparse(x, 500L), collapse = collapse) 5. safe_deparse(x[[3]]) 4. FUN(X[[i]], ...) 3. vapply(bars, function(x) safe_deparse(x[[3]]), "") 2. barnames(split_formula[[ii]]$reTrmFormulas) 1. sdmTMB(catch ~ s(depth) + s(haul_hours), data = sim_data, mesh = sim_mesh, anisotropy = FALSE, spatial = "on") ### Package Updates I updated a number of R packages since running the models successfully before, I wasn't paying close attention to which ones updated. I was getting a warning about a mismatch in versions of the Matrix package, but that was back when the models ran fine. ### Session Info Here is the session info from running the model on the simple, simulate data. > R version 4.2.3 (2023-03-15 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044) Matrix products: default locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 [3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C [5] LC_TIME=English_United States.utf8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] sdmTMB_0.3.1.9000 loaded via a namespace (and not attached): [1] Rcpp_1.0.11 INLA_23.04.24 nloptr_2.0.3 TMB_1.9.6 [5] glmmTMB_1.1.8 compiler_4.2.3 pillar_1.9.0 class_7.3-21 [9] tools_4.2.3 boot_1.3-28.1 lme4_1.1-34 tibble_3.2.1 [13] lifecycle_1.0.3 nlme_3.1-162 lattice_0.20-45 mgcv_1.8-42 [17] pkgconfig_2.0.3 rlang_1.1.1 Matrix_1.6-1.1 DBI_1.1.3 [21] cli_3.6.1 rstudioapi_0.15.0 parallel_4.2.3 mvtnorm_1.2-3 [25] xfun_0.40 e1071_1.7-13 coda_0.19-4 fmesher_0.1.2 [29] dplyr_1.1.3 knitr_1.44 generics_0.1.3 vctrs_0.6.3 [33] tidyselect_1.2.0 classInt_0.4-10 grid_4.2.3 glue_1.6.2 [37] sf_1.0-14 R6_2.5.1 fansi_1.0.5 sp_2.1-0 [41] minqa_1.2.6 magrittr_2.0.3 MASS_7.3-58.2 emmeans_1.8.8 [45] splines_4.2.3 units_0.8-4 assertthat_0.2.1 xtable_1.8-4 [49] numDeriv_2016.8-1.1 KernSmooth_2.23-20 utf8_1.2.3 estimability_1.4.1 [53] proxy_0.4-27
seananderson commented 11 months ago

I have fixed this temporarily, but it involved copying over a bunch of glmmTMB code from reformulas.R in version 1.1.7. I'm not sure we need all that complexity or want to deal with all the license issues.

seananderson commented 10 months ago

This has been resolved here and on CRAN.