Page 1 of 1

unique (fitted) in RPresence

PostPosted: Wed Oct 19, 2022 3:13 pm
by pshashank
Hi there,
I am doing a Hines correlated detection model and when using unique(fitted) argument in PResence to get the estimates of detection probability from my top detection model why do I get for 4 unique values (pasted below), shouldn't I be getting one unique estimate (detection probability) same happens with the top psi models for getting the psi estimates. I don't know maybe I am using the argument in an incorrect way. I would really appreciate if I could get some help on how do I check my psi and p values from my top models (or any models).
Thanks
Shashank

> unique(fitted(p.forest.lvst, "p"))
est se lower_0.95 upper_0.95
p(1)_unit1 0.2517222 0.1069606 0.09953267 0.5058827
p(1)_unit2 0.6457426 0.1312252 0.37193249 0.8487319
p(1)_unit3 0.5161404 0.1165403 0.29942687 0.7269488
p(1)_unit4 0.8525080 0.1414109 0.38939456 0.9812692

Re: unique (fitted) in RPresence

PostPosted: Wed Oct 19, 2022 4:16 pm
by jhines
The fitted function returns a data-frame. The unique function works on vectors or matrices, but not data-frames. I suggest:

Code: Select all
pfit=fitted(p.forest.lvst,"p")
i=!duplicated(pfit$est)
print(fit[i,])


or create a new unique function...

Code: Select all
unique_df <- function(df) df[!duplicated(df[,1]),]


then you can call the new function when the argument is a data-frame:

Code: Select all
unique_df(fitted(CDmod1,"p"))

Re: unique (fitted) in RPresence

PostPosted: Wed Oct 19, 2022 4:40 pm
by pshashank
Thanks, Jim. I tried the first option and then got this message first -

Error in print(fit[i, ]) : object 'fit' not found

Then I thought maybe it is print(pfit[i,]), I tried with that correction and got the same output as I did with the unique (fitted) syntax earlier
> print(fit[i,])
Error in print(fit[i, ]) : object 'fit' not found
> print(pfit[i,])
est se lower_0.95 upper_0.95
p(1)_unit1 0.2517222 0.1069606 0.09953267 0.5058827
p(1)_unit2 0.6457426 0.1312252 0.37193249 0.8487319
p(1)_unit3 0.5161404 0.1165403 0.29942687 0.7269488
p(1)_unit4 0.8525080 0.1414109 0.38939456 0.9812692

Re: unique (fitted) in RPresence

PostPosted: Wed Oct 19, 2022 4:42 pm
by jhines
Sorry, the last command should have been:

Code: Select all
print(pfit[i,])

Re: unique (fitted) in RPresence

PostPosted: Wed Oct 19, 2022 4:47 pm
by pshashank
Yes, that's what I speculated and tried but got the same output as I got for the unique (fitted) syntax. I have pasted it below.
[color=#0040FF]pfit=fitted(p.forest.lvst,"p")
> i=!duplicated(pfit$est)
> print(pfit[i,])
est se lower_0.95 upper_0.95
p(1)_unit1 0.2517222 0.1069606 0.09953267 0.5058827
p(1)_unit2 0.6457426 0.1312252 0.37193249 0.8487319
p(1)_unit3 0.5161404 0.1165403 0.29942687 0.7269488
p(1)_unit4 0.8525080 0.1414109 0.38939456 0.9812692

In the second option it has a message -
> unique_df(fitted(CDmod1,"p"))
Error in fitted(CDmod1, "p") : object 'CDmod1' not found

Re: unique (fitted) in RPresence

PostPosted: Thu Oct 20, 2022 9:15 am
by jhines
Thanks for sending the script and data. The model you specified has detection (p) as a function of the covariates, t_forest and lvst. Both of those covariates are binary categorical covariates taking the values 0 or 1. There are 4 possible combinations of those covariates which produce the 4 unique estimates of p that you see in the output. Specifically, for survey 1,

site1 has t_forest=0 and lvst=0, giving p(site1) = .2517
site2 has t_forest=1 and lvst=0, giving p(site1) = .6457
site3 has t_forest=0 and lvst=1, giving p(site1) = .5161
site4 has t_forest=1 and lvst=1, giving p(site1) = .8525

The other sites and surveys will have one of those 4 possible combinations of covariate values, resulting in one of those 4 estimates of p. If you want to see the other p's, don't use the unique function. Just print:

Code: Select all
print(fitted(p.forest.lvst,"p"))


If your model was p~1 (constant detection), then the unique function would only produce 1 estimate. If your model was p~forest (continuous site covariate forest), then the unique function would produce a different estimate for each site.

Re: unique (fitted) in RPresence

PostPosted: Thu Oct 20, 2022 9:48 am
by pshashank
Thanks, Jim. So if I have to report detection probability "p" for this study then I average these four values?

Shashank

Re: unique (fitted) in RPresence

PostPosted: Thu Oct 20, 2022 10:16 am
by jhines
You could report the average of those values, but if you only want to report a single value, the estimate from the constant-detection (p~1) model would be better, since it gives more weight to estimates with better precision. The average of the 4 estimates gives equal weight to each of the 4 estimates.

Since you went through the trouble of collecting the covariate data and analyzing with models allowing different detection probabilities, you might want to report all 4 p's. So, instead of saying the average detection probability was 0.5665, you could say that according to the top AIC model, detection probabilities for forest sites were 0.25 with no livestock, and 0.52 with livestock. Detection probabilities for non-forest sites were 0.65 and 0.85 without/with livestock.

Alternatively, you could produce model-averaged estimates of p, which take into account model uncertainty, and report the mean model-averaged p with the lowest and highest values.

The choice of what to report depends on the message you're trying to convey in your report/paper.

Re: unique (fitted) in RPresence

PostPosted: Thu Oct 20, 2022 4:11 pm
by pshashank
Thanks a lot, Jim. I will discuss this with the team and decide appropriately. I appreciate your help very much.
Shashank