DistanceDevelopment / Distance

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

Encounter rate variance of Buckland 2001 cannot be requested by `ds` #182

Open erex opened 5 months ago

erex commented 5 months ago

er_method argument in ds is ignored by dht

Either observed counts (er_method=1) or expected counts (er_method=2) can be requested. Default is "2". When user request er_method=1 results are still using er_method=2

I believe the problem lies within dht, however, users calling ds from the Distance package will not get the results they expect if they specify er_method=1

MRE

library(Distance)
data(Savannah_sparrow_1981)
cu <- convert_units("meter", NULL, "hectare")
pooler1 <- ds(Savannah_sparrow_1981, transect="point", key="hn", adjustment = "cos",
           convert_units = cu, er_method = 1)  # encounter var uses observed counts
pooler1$dht$individuals$summary

pooler2 <- ds(Savannah_sparrow_1981, transect="point", key="hn", adjustment = "cos",
              convert_units = cu, er_method = 2)  # encounter var uses expected counts
pooler2$dht$individuals$summary

se.ER and cv.ER are identical regardless of value of er_method.

Debug trail

erex commented 5 months ago

Supplement to this issue

I checked whether the lack of difference in ER variance estimates was caused by either a) miscommunication between ds and dht and b) lack of covariate in the Savannah sparrow detection function model.

I turned my attention to the amakihi data set to introduce a covariate in the detection function and I ran the analysis in ddf rather than through ds. Result below: my interpretation is that I still can't induce differences in ER variance estimation using varflag:

data("amakihi")  # multiple years as strata
bust <- unflatten(amakihi)
detsize <- ddf(dsmodel=~mcds(key="hn", formula=~MAS),
               data=bust$data, method="ds", meta.data = list(point=TRUE, width=82.5))
summary(detsize)
meth1 <- dht(detsize, region.table = bust$region.table, sample.table = bust$sample.table,
             obs.table = bust$obs.table, options = list(varflag=1))
meth1$individuals$summary
meth2 <- dht(detsize, region.table = bust$region.table, sample.table = bust$sample.table,
             obs.table = bust$obs.table, options = list(varflag=2))
meth2$individuals$summary

Result

> meth1 <- dht(detsize, region.table = bust$region.table, sample.table = bust$sample.table,
+              obs.table = bust$obs.table, options = list(varflag=1))
> meth1$individuals$summary
  Region      Area CoveredArea Effort    n   k       ER     se.ER      cv.ER
1   1292  855298.6    855298.6     40  140  40 3.500000 0.3121472 0.08918492
2    194  876681.1    876681.1     41  172  41 4.195122 0.3088521 0.07362173
3    493  876681.1    876681.1     41  231  41 5.634146 0.3289972 0.05839344
4    494  513179.2    513179.2     24  141  24 5.875000 0.2712859 0.04617632
5    495  855298.6    855298.6     40  212  40 5.300000 0.4938078 0.09317129
6    792  876681.1    876681.1     41  146  41 3.560976 0.1945877 0.05464449
7    793  855298.6    855298.6     40  201  40 5.025000 0.2984737 0.05939775
8  Total 5709118.2   5709118.2    267 1243 267 4.655431 0.1262862 0.02712664
> meth2 <- dht(detsize, region.table = bust$region.table, sample.table = bust$sample.table,
+              obs.table = bust$obs.table, options = list(varflag=2))
> meth2$individuals$summary
  Region      Area CoveredArea Effort    n   k       ER     se.ER      cv.ER
1   1292  855298.6    855298.6     40  140  40 3.500000 0.3121472 0.08918492
2    194  876681.1    876681.1     41  172  41 4.195122 0.3088521 0.07362173
3    493  876681.1    876681.1     41  231  41 5.634146 0.3289972 0.05839344
4    494  513179.2    513179.2     24  141  24 5.875000 0.2712859 0.04617632
5    495  855298.6    855298.6     40  212  40 5.300000 0.4938078 0.09317129
6    792  876681.1    876681.1     41  146  41 3.560976 0.1945877 0.05464449
7    793  855298.6    855298.6     40  201  40 5.025000 0.2984737 0.05939775
8  Total 5709118.2   5709118.2    267 1243 267 4.655431 0.1262862 0.02712664