DistanceDevelopment / Distance

Simple distance sampling analysis
GNU General Public License v3.0
9 stars 8 forks source link

ds produces density estimates of zero #165

Open erex opened 1 year ago

erex commented 1 year ago

Question from the list about output for density and abundance being zero.

Seems this is caused by the object field being a character string rather than a number. Perhaps code could be more robust to this.

minimum reproducible example

library(Distance)
data(wren_lt)
wren_lt$object <- paste0(wren_lt$Region.Label, wren_lt$object)
tst <- ds(wren_lt)
summary(tst)
Summary for distance analysis 
Number of observations :  156 
Distance range         :  0  -  100 

Model : Half-normal key function with cosine adjustment term of order 2 

Strict monotonicity constraints were enforced.
AIC   : 1417.611 

Detection function parameters
Scale coefficient(s):  
            estimate        se
(Intercept) 4.072296 0.1247543

Adjustment term coefficient(s):  
                estimate        se
cos, order 2 -0.06852801 0.1282726

                       Estimate         SE        CV
Average p             0.7210344  0.1120697 0.1554291
N in covered region 216.3558470 34.8503833 0.1610790

Summary statistics:
    Region Area CoveredArea Effort n  k ER se.ER cv.ER
1 Montrave 33.2        1932   9.66 0 19  0     0     0

Abundance:
  Label Estimate se cv lcl ucl df
1 Total        0  0  0   0   0 18

Density:
  Label Estimate se cv lcl ucl df
1 Total        0  0  0   0   0 18

Remedy:

Check if the object field is.numeric otherwise, fail gracefully.

LHMarshall commented 1 year ago

Also an issue in mrds... but only an issue at the dht stage - model can be fitted ok. Will need to fail gracefully in mrds and catch it in Distance and only return the ddf part.

data(book.tee.data)
region <- book.tee.data$book.tee.region
egdata <- book.tee.data$book.tee.dataframe
egdata$object <- paste0("A", egdata$object)
samples <- book.tee.data$book.tee.samples
obs <- book.tee.data$book.tee.obs
obs$object <- paste0("A", obs$object)

result <- ddf(dsmodel=~mcds(key="hn", formula=~1), data=egdata, method="ds",
              meta.data=list(width=4))

dht(result,
    region,
    samples,
    obs)