DistanceDevelopment / Distance

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

`dht2` does not understand uniform key function models #151

Open erex opened 1 year ago

erex commented 1 year ago

Highlighted by workshop participant (working with dung surveys over short distances). dht2 fails with uninterpretable error message when handed a "fitted" uniform function.

MRE:

library(Distance)
data(ducknest)
units <- convert_units(ducknest_units$Units[2],
                       ducknest_units$Units[1],
                       ducknest_units$Units[3])
uni <- ds(ducknest, key="unif",
          convert_units = units,
          truncation = 2)
hn <-  ds(ducknest, key="hn",
          convert_units = units,
          truncation = 2)
gof_ds(uni)
gof_ds(hn)
trouble <- dht2(uni, flatfile=ducknest,
                convert_units = units,
                strat_formula = ~Region.Label)
notrouble <- dht2(hn, flatfile=ducknest,
                convert_units = units,
                strat_formula = ~Region.Label)

dht2 failure for uniform model

Error in abs(x) : non-numeric argument to mathematical function

generated by this line of code

df_unc <- lapply(ddf, varNhat, data = res)

but quite happy with the half normal model.

erex commented 1 year ago

supplement:

the above lapply function is calling varNhat. Suspect the problem is in varNhat which on this line is looking for the Hessian of the fitted model to get some variance bits-and-pieces.

There won't be a Hessian when the detection function is uniform without adjustments.

LHMarshall commented 4 months ago

as Eric pointed out above in the varNhat function line 50 fails as there is no hessian matrix

>   vcov <- solvecov(model$hessian)$inv
Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  : 
  'data' must be of a vector type, was 'NULL'

> model$hessian
NULL