Closed AugustT closed 5 years ago
First I looked at what the options are, and their sensitivity to boundary values (0 and 1) in the posterior.
lineargrowth
is a binomial glm, so boundary values are expected.difference
is simply first minus last, so again no issue with boundary valuespercentdif
is the difference divided by the first year. So zeros in first year (denominator) are going to cause apparent infinite increases.growthrate
has the first year as the denominator, so Infinite values can emerge when first year = 0.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
.
In the occurrence change function the occupancy estimates are modified so that 0's and 1's are changed to
0.0001
and0.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 is0.00000001
, for example. I don't think there is a good reason why this isn't done.Spotted by @JKSheard