Problem with the functions plot_effects and plot_coeff

39 views
Skip to first unread message

Tregear Louis

unread,
Feb 11, 2025, 6:45:45 AMFeb 11
to camtrapR
Hello,
I had a question about an error I don't seem to understand when using the function plot_effects. I first created my model, by using the communityModelfunction(it's a small model with no intercepts):
mod.jags_cov <- communityModel(model="RN",occuCovs = list(independent=c("foret","vigne")),detCovs=list(independent=c("mindistancetoriver")),detCovsObservation = list(fixed = "effort",ranef="pluie"),data_list=data_listfinale,modelFile = modelfilem)
fit.jags_cov <- fit(mod.jags_cov,n.iter = 5000,n.burnin = 2500,chains = 3)
I had no problems until then,  the calibration fit worked. Its when I tried the effects of occupation covariates on abundance that it showed this error message:
plot_effects(mod.jags_cov,fit.jags_cov,submodel = "state",response="abundance") Erreur dans .local(object, ...) : all(cov_info_subset$coef %in% object@params) n'est pas TRUE
I reckon it's related to the occupancy covariates because the plot worked for the detection covariates. I think that putting 2 covariates as independent is related to the error, but I don't know how to fix it, or to interprete it.
If anyone has a suggestion, fill free to help me, that would be really appreciated
Thanks for reading me,
Louis TREGEAR

Jürgen Niedballa

unread,
Feb 11, 2025, 11:24:53 AMFeb 11
to Tregear Louis, camtrapR
Hello, 
This may be a bug related to the independent covariate effects, which I haven't tested extensively tbh. To confirm please try with the covariate set to fixed a
or random and see if the plots work then.

Just out of curiosity, is there an important reason to use independent effects instead of random effects? 

The general recommendation would be to use random effects unless you have specific reasons not to. Independent effects essentially fit separate models for each species, which can lead to:
1. Less stable parameter estimates 
2. Reduced power
3. Potential convergence issues
4. No sharing of information between species

If you're interested in community-level inference or have rare species in your dataset, random effects are likely the better choice, unless you include too few species to use random effects.

I notice you mentioned "no intercepts" but occupancy models require intercepts, and they're being included by default as fixed (same across all species) since you didn't specify them. In community occupancy models, it usually makes more ecological sense to allow species-specific intercepts via random effects, since we expect different species to have different baseline occupancy and detection probabilities.

Here's how I would modify your model:


mod.jags_cov <- communityModel(
  model = "RN",
  occuCovs = list(independent = c("foret", "vigne")),
  detCovs = list(independent = c("mindistancetoriver")),
  detCovsObservation = list(fixed = "effort", ranef = "pluie"),
  intercepts = list(det = "ranef", occu = "ranef"), # explicitly using random effects for intercepts
  data_list = data_listfinale,
  modelFile = modelfilem
)


The intercepts = list(det = "ranef", occu = "ranef") argument lets each species have its own intercept drawn from a community distribution, which better reflects ecological reality where species vary in their baseline occupancy and detection probabilities.

Perhaps the communityModel function with benefit from changing the default to using random effects on the intercepts. I'll make a note to address that.

Best,
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, visit https://groups.google.com/d/msgid/camtrapr/0b5b15cb-41e5-41fb-8cd4-d1ffb7b1fbebn%40googlegroups.com.

Tregear Louis

unread,
Feb 21, 2025, 9:56:13 PMFeb 21
to Jürgen Niedballa, camtrapR
Hi, Jurgen,
Thank you for your response!
In fact in our team we though that using  random effects of covariates was only for categorical covariates and not continous, but maybe not after all. 
I had no problem having the plot_effects curves for more than 2 covariates as ranef, or as fixed, which is why I was a bit confused it not working with independent effects too. 
I felt that with using independent effects, you could see a much more effect of each covariate on different species than with random effects, on statistical parameters. 
But, like you said, maybe it's more appropriate to use random effects in a community level study.
Thanks,
Louis TREGEAR

Jürgen Niedballa

unread,
Feb 21, 2025, 10:12:52 PMFeb 21
to Tregear Louis, camtrapR
Thank you for your follow-up. Let me clarify a few points:

1. Random effects can be used for both continuous and categorical covariates in community models. They allow species-specific responses while sharing information across the community. See vignette 5 for details on the implementation

2. The plotting issue with independent effects is likely a technical bug, not a limitation of the approach itself. I will look into it.

3. Regarding effect visibility: Random effects can indeed mask differences between species through shrinkage, especially in certain scenarios:
  1. When true species differences exist but:
    • Sample sizes are small
    • Species effects are far from the community mean
    • Community variance is estimated to be small
  2. When rare species have very different responses from common ones:
    • Their estimates will be strongly pulled toward the community mean
    • Their true distinctive responses could be masked

So while random effects have advantages in terms of:

  • Stability of estimates (through partial pooling of data)
  • Power through information sharing
  • Handling limited data

They do come with the trade-off of potentially masking real species differences through shrinkage. This is particularly important to consider when species are expected to have truly distinct responses or when rare species might respond very differently from common ones. On the other hand parameter estimation is difficult and may indeed fail for rare species when using independent effects.


The choice between random and independent effects should primarily depend on:
  • Number of species in your community
  • Amount of data per species
  • Whether you expect species responses to be related
Generally speaking I found random effects to be the appropriate choice in most scenarios though.

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