Error with plot_effects() and plot_coef()

25 views
Skip to first unread message

Magdalena Salas

unread,
Sep 15, 2024, 1:01:16 PM9/15/24
to camtrapR
Hello, I'm having some trouble running these two functions for a comm occu Object. First, thank you for these powerful tools, I'm just starting to explore MOMs. I have been working the last year with single species models with unmarked. To give some context, the data I'm working with comes from camera trapping registers and focuses on mammal species. For now, I'm trying MOMs for felid assemblage (by the way, one may choose and filter species groups or should it be used for entire communities?).

The community model I run is the following:
comu_model <- communityModel(data_list, # la lista de datos
                             occuCovs = list(ranef = "Pje", ranef = "alt2"), 
                             detCovsObservation = list(fixed = "effort"), 
                             intercepts = list(det = "ranef", occu = "ranef"), 
                             modelFile = "modelfile") 
 
where "Pje" means distance to households and alt2 is elevation. I assume random effects for both covariates and intercepts. 
fit.commu <- fit(comu_model,
                 n.iter = 10000,
                 n.burnin = 2000,
                 thin = 2,
                 chains = 3,
                 cores = 3,
                 quiet = T)

Now here comes the error. Everything above runs ok. 
plot_effects(comu_model, # model
             fit.commu, # commu object
             submodel = "state") 
Error in .local(object, ...) : all(cov_info_subset$coef %in% object@params) is not TRUE

plot_coef(comu_model,
          fit.commu,
          submodel = "state")
Error in `$<-.data.frame`(`*tmp*`, "type", value = "mean") : replacement has 1 row, data has 0

And when I run for det state it runs just fine... I've also tried this function for another set of data and a different model and it worked ok. So I don't know if I'm doing something wrong with the modelling? I tried restarting R but I get the same error at this point.

I leave this if it is more informative about my question
sessionInfo() R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22631)
attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] snowfall_1.84-6.3 snow_0.4-4 beepr_1.3 tictoc_1.2.1 SpadeR_0.1.1 [6] bayesplot_1.11.1 nimble_1.2.1 rjags_4-16 coda_0.19-4.1 lubridate_1.9.3 [11] forcats_1.0.0 stringr_1.5.1 dplyr_1.1.3 purrr_1.0.1 readr_2.1.4 [16] tidyr_1.3.0 tibble_3.2.1 ggplot2_3.5.1 tidyverse_2.0.0 camtrapR_2.3.0
I hope you can help me with this or maybe someone else had this issue and knows what may be happening.


Thank you!

Maggie

Juergen Niedballa

unread,
Sep 15, 2024, 1:16:05 PM9/15/24
to camtrapR
Hello,
Please try changing this line in communityModel
occuCovs = list(ranef = "Pje", ranef = "alt2"), 
to
occuCovs = list(ranef = c("Pje", "alt2")), 

And see if that fixes it. Currently you provide two list items with identical names. This may potentially interfere with other code. The correct way to specify multiple covariates of the same type (with random effects in your example) is by combining then with c(). 

Best regards,
Jürgen 
Reply all
Reply to author
Forward
0 new messages