BiologicalRecordsCentre / sparta

Species Presence/Absence R Trends Analyses
http://biologicalrecordscentre.github.io/sparta/index.html
MIT License
21 stars 24 forks source link

OccurrenceChange - 0.0001 and 0.99999 #98

Closed AugustT closed 5 years ago

AugustT commented 5 years ago

In the occurrence change function the occupancy estimates are modified so that 0's and 1's are changed to 0.0001 and 0.9999

https://github.com/BiologicalRecordsCentre/sparta/blob/e1a6443dc9e8e859422b0ec129e05b67f1c9fbe3/R/occurrenceChange.r#L108

This almost certainly isn't needed for all of the change metrics used, for example the raw change in occupancy. I suggest these extreme value truncation are done INSIDE the different methods, and only where needed. I don't think the change of 1's is always needed as I think percentage change issues only arise from 0's.

I also suggest that the precision of these conversions it increased, so that instead of 0.0001 it is 0.00000001, for example. I don't think there is a good reason why this isn't done.

Spotted by @JKSheard

drnickisaac commented 5 years ago

First I looked at what the options are, and their sensitivity to boundary values (0 and 1) in the posterior.

In summary, the problems arise when dividing by zero. So the issue is restricted to:

My solution is therefore to: 1) delete occ_it[occ_it == 1] <- 0.9999 2) replace occ_it[occ_it == 0] <- 0.0001 with res_tab[,1][res_tab[,1] == 0] <- 0.0000001 inside the loop for percentdif and growthrate.