Random effects of categorical covariate on another categorical covariate in communityModel

28 views
Skip to first unread message

Jarrad Barnes

unread,
Jul 3, 2024, 3:16:19 AM7/3/24
to camtrapR
Hi Juergen,

I have five landscape covariates (aspect, lithology, landform, ruggedness, plant species richness), three of which are categorical (aspect, lithology, landform), and a dataset of fauna observations over nine sampling periods. What I'd ideally like to attempt to determine is whether there is an effect of sampling period (Survey) on occupancy estimates for each species across all the landscape covariates. I understand the current implementation of communityModel() doesn't allow for random effects of one categorical covariate on another, only on a continuous covariate, but I wonder if you can think of any way to "hack" it, so to speak. Ideally I'd simply implement it as below, but I know that's not an option at present and I can only use Survey as a covariate for ruggedness and plant species richness - any bright ideas, or is it simply not possible?

mod.jags2 <- communityModel(datalist,
                            occuCovs = list(ranef = c("Survey", "aspect|Survey", "lithology|Survey", "landform|Survey","ruggedness|Survey", "spp_richness|Survey")),
                            detCovsObservation = list(fixed = "effort"),
                            intercepts = list(det = "ranef", occu = "ranef"),
                            modelFile = modelfile2)


Thanks,
Jarrad

Jürgen Niedballa

unread,
Jul 3, 2024, 7:51:00 PM7/3/24
to Jarrad Barnes, camtrapR
Hi Jarrad, 
As you said this is not implemented directly, but you could try modifying the input data and combine / cross two categorical covariates pairwise. So instead of two covariates "survey" and "landform" you'd have one "landform-survey" covariate which you could then use in the model with a species-level random effect. Ditto for the other categorical covariates. 

This implementation differs from the nested random effects you have in the continuous covariates though, and thus inconsistency may not be desired.

I can't think of another way to implement this short of modifying the model code manually, which would then also break the rest of the workflow (predict etc).

Best regards,
Jürgen 




--
You received this message because you are subscribed to the Google Groups "camtrapR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camtrapr+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/camtrapr/8247671d-08cf-4237-97ea-d040af9b5e84n%40googlegroups.com.

Jarrad Barnes

unread,
Jul 3, 2024, 9:40:47 PM7/3/24
to camtrapR
Hi Juergen,

Hmm, okay, I'll give that a try and see how it looks, and see if I can work around the continuous covariate issue. Thanks for the suggestion.

Jarrad

Jarrad Barnes

unread,
Jul 3, 2024, 11:49:01 PM7/3/24
to camtrapR
Hi Juergen,

Back so soon ... I've done the suggested, but get the below error once I start to run the communityModel(). 

Error in update.jags(model, n.iter, ...) : Error in node z[2,368] Invalid parent values

Is this just a result of having too many covaraite levels for the model to calculate anything realistic? My siteCovs have respectively 9 (survey), 63 (survey*aspect), 27 (survey*lithology), 72 (survey*landform), 45 (survey*ruggedness[cat]), and 27 (survey*spp_rich[cat]). Or is it something simpler?

Thanks,
Jarrad

Jürgen Niedballa

unread,
Jul 17, 2024, 12:52:59 AM7/17/24
to Jarrad Barnes, camtrapR
Hi,
the error means that for species 2, station 368, z (the binary occupancy state) could not be derived. z in turn is based on occupancy probability psi, which for some reason is not calculated correctly.
Could be NAs in the covariates, or some extreme covariate values (always good to standardize continuous covariates). Also check the detection history and effort matrix for that species/station combination, maybe something is wrong there (e.g. all NA).




Jarrad Barnes

unread,
Jul 17, 2024, 1:16:22 AM7/17/24
to camtrapR
Thanks Juergen, that makes sense. I'll check the detection history and effort matrix and see how I can revise it.
I always pass my continuous covariates through scale() so that shouldn't be the issue.

Jarrad

Reply all
Reply to author
Forward
0 new messages