Continuous detection covariates and Gelman-Rubin model diagnostics

74 views
Skip to first unread message

Sankarshan Chaudhuri

unread,
Jun 15, 2023, 9:14:59 AM6/15/23
to Jürgen Niedballa, camt...@googlegroups.com

Hello all,

I need to incorporate some site-specific covariates, such as photo-capture rate of humans (continuous), terrain ruggedness (continuous), and season (categorical) as detection covariates. I believe these covariates could better influence the detection process, than occupancy. 

In this connection, can you please guide me to include these as detection covariates? So far, I have used camera trap effort as a detection covariate. The way I understand it (please correct me if I am wrong), it requires a matrix of day-specific values, but for all these covariates, I have only an average value for each site/camera trap point.

Secondly, I have used Gelman-Rubin Convergence statistics for model diagnostics. But every time while plotting, it shows a convergence failure (tried up to 50k iterations, 3 chains), mainly due to NaN values for "NSpecies". I am pasting the result and error message for your reference.

Potential scale reduction factors:

                                Point est. Upper C.I.
Bpvalue                               1.03       1.03
Bpvalue_species[1]                    1.00       1.00
Bpvalue_species[2]                    1.00       1.00
Bpvalue_species[3]                    1.00       1.00
Bpvalue_species[4]                    1.00       1.00
Bpvalue_species[5]                    1.00       1.00
Bpvalue_species[6]                    1.00       1.00
Bpvalue_species[7]                    1.00       1.00
Bpvalue_species[8]                    1.00       1.00
Bpvalue_species[9]                    1.00       1.00
Bpvalue_species[10]                   1.00       1.00
Nspecies                               NaN        NaN
R2[1]                                 1.00       1.00
R2[2]                                 1.00       1.00
R2[3]                                 1.00       1.00
R2[4]                                 1.00       1.00
R2[5]                                 1.00       1.00
R2[6]                                 1.00       1.00
R2[7]                                 1.00       1.00
R2[8]                                 1.00       1.00
R2[9]                                 1.00       1.00
R2[10]                                1.00       1.00
R3                                    1.00       1.00
alpha.obs.fixed.cont.effort           1.00       1.00
alpha0[1]                             1.00       1.00
alpha0[2]                             1.00       1.00
alpha0[3]                             1.00       1.00
alpha0[4]                             1.00       1.00
alpha0[5]                             1.00       1.00
alpha0[6]                             1.00       1.00
alpha0[7]                             1.00       1.00
alpha0[8]                             1.00       1.00
alpha0[9]                             1.00       1.00
alpha0[10]                            1.00       1.00
alpha0.mean                           1.00       1.00
alpha0.sigma                          1.00       1.00
beta.ranef.cont.human_mod[1]          1.00       1.00
beta.ranef.cont.human_mod[2]          1.00       1.00
beta.ranef.cont.human_mod[3]          1.00       1.00
beta.ranef.cont.human_mod[4]          1.00       1.00
beta.ranef.cont.human_mod[5]          1.00       1.00
beta.ranef.cont.human_mod[6]          1.00       1.00
beta.ranef.cont.human_mod[7]          1.00       1.00
beta.ranef.cont.human_mod[8]          1.00       1.00
beta.ranef.cont.human_mod[9]          1.00       1.00
beta.ranef.cont.human_mod[10]         1.00       1.00
beta.ranef.cont.human_mod.mean        1.00       1.00
beta.ranef.cont.human_mod.sigma       1.00       1.00
beta0[1]                              1.00       1.00
beta0[2]                              1.00       1.00
beta0[3]                              1.00       1.00
beta0[4]                              1.00       1.00
beta0[5]                              1.00       1.00
beta0[6]                              1.00       1.00
beta0[7]                              1.00       1.00
beta0[8]                              1.00       1.01
beta0[9]                              1.00       1.00
beta0[10]                             1.00       1.00
beta0.mean                            1.00       1.00
beta0.sigma                           1.00       1.00
new.R2[1]                             1.00       1.00
new.R2[2]                             1.00       1.00
new.R2[3]                             1.00       1.00
new.R2[4]                             1.00       1.00
new.R2[5]                             1.00       1.00
new.R2[6]                             1.00       1.00
new.R2[7]                             1.00       1.00
new.R2[8]                             1.00       1.00
new.R2[9]                             1.00       1.00
new.R2[10]                            1.00       1.00
new.R3                                1.00       1.00

> gelman.plot(fit.jags_human_mod,  multivariate = FALSE)

******* Error: *******
Cannot compute Gelman & Rubin's diagnostic for any chain
segments for variables Nspecies
This indicates convergence failure

Would you please explain to me what I am doing wrong?

Thanks in advance!!

Regards
Sankarshan

Jürgen Niedballa

unread,
Jun 18, 2023, 10:46:50 PM6/18/23
to Sankarshan Chaudhuri, camtrapR
Hello, 
You can use site covariates on detection probability. It works exactly the same as site covariates on occupancy probability. Simply supply the covariates in the siteCovs table and then include them via argument detCovs. I would suggest trying it with the example from the AHMbook package in vignette 5 of camtrapr. You can use continuous and categorical covariates.

The error in the convergence statistics is likely due to all values of Nspecies being identical in all chains. Can you please confirm that's the case? Haven't encountered that scenario before, and would have to think about a solution.

Best regards,
Jürgen

Sankarshan Chaudhuri

unread,
Jun 20, 2023, 8:27:57 AM6/20/23
to Jürgen Niedballa, camt...@googlegroups.com

Thank you for your reply. To incorporate the detection probability, I am pasting the exact codes that I have tried. 

data_list_med_withdet <- list(ylist = ylist_med,
                      siteCovs = all_cov_numeric_categ, obsCovs=list(effort = DetHist_list_medbody[[1]]$effort)) 


Now, the "all_cov_numeric_categ" contains both continuous and categorical covariates, out of which I would like to use "LULC_factors" as categorical covariates for detection probability.
 
modelfile_test_med_human_mod_with_det <- tempfile(fileext = ".txt")
mod.jags_test_med_human_mod_with_det <- communityModel(data_list_med,
                                              occuCovs = list(ranef = "human_mod"),
                                              detCovsObservation = list(fixed ="LULC_factors"),
                                              intercepts = list(det = "ranef", occu = "ranef"),
                                              modelFile = modelfile_test_med_human_mod_with_det)

And I found the following error message: 

"Error in communityModel(data_list_med, occuCovs = list(ranef = "human_mod"),  :Detection covariate  LULC_factors is not a factor"

Then I also tried to add a continuous site covariate (TPI_1sqkm) as a detection site covariate.

modelfile_med_human_mod_with_det <- tempfile(fileext = ".txt")
mod.jags_med_human_mod_with_det <- communityModel(data_list_med,
                                              occuCovs = list(ranef = "human_mod"),
                                              detCovs = list(fixed ="TPI_1sqkm"),
                                              intercepts = list(det = "ranef", occu = "ranef"),
                                              modelFile = modelfile_med_human_mod_with_det)

And R gave the following warning message, but the process is running:
"Warning message:
In if (!c("obsCovs", "siteCovs") %in% names(data_list)) { :
  the condition has length > 1 and only the first element will be used"


Would you please help me to understand this?

Sankarshan Chaudhuri

unread,
Jun 29, 2023, 9:16:08 AM6/29/23
to Jürgen Niedballa, camt...@googlegroups.com
Any leads on this?

Jürgen Niedballa

unread,
Jun 29, 2023, 10:30:43 AM6/29/23
to Sankarshan Chaudhuri, camtrapR
Hello, 
The first error is probably because LULC_factors is a site covariate, but you request it to be used as a site-observation covariate (there is no site-observation covariate named LULC_factors). Try putting it in detCovs (= the site covariates on detection probabiu), not detCovsObservation. The error message doesn't seem adequate for that situation and needs to be improved.

The second warning might be a bug, I'll have to check. Are you using the latest GitHub version? If not, please do and check if the warning persists.

Thank you,
Jürgen 

Jürgen Niedballa

unread,
Jul 3, 2023, 11:09:21 PM7/3/23
to Sankarshan Chaudhuri, camtrapR
I checked the second error, it was a bug which was fixed last year:

https://github.com/jniedballa/camtrapR/commit/0ddc14277a2722f0ec447d15c0ef2706c860d1ba

The bug still affects the CRAN version (which by now is relatively old). Just use the GitHub version instead to fix it.
Reply all
Reply to author
Forward
0 new messages