Error when using dht2

76 views
Skip to first unread message

Sunny Murphy

unread,
Apr 15, 2025, 12:46:01 PM4/15/25
to distance-sampling
Good afternoon, 

I'm having a persistent issue when using dht2(). 

My data is stratified geographically and I want to estimate the abundance across strata and overall. Data was stratified by preserves, and since two of them were smaller, they received 5 cameras instead of the 10 designated to the largest preserve. 

Here is my relevant code: 

--- BEGIN ---

coytsects <- cbind.data.frame(unique(coyobs.df$Sample.Label),
                              c(34067,587,40875,3373,10579,15217,7289,2852))
colnames(coytsects) <- c("Sample.Label", "Effort")

geoarea <- cbind.data.frame(c("LeonLevy", "Brownell", "Marx"),
                            c(14624094, 5284054, 214336))
colnames(geoarea) <- c("Region.Label", "Area")

dht2(Coy.hn$ddf, observations = coyobs.dht, transects = coytsects,
     geo_strat = geoarea, convert_units = conversion.factor, er_est = 4.407E-04,
     stratification = "geographical", strat_formula = ~Region.Label,
     total_area = 20122484)

--- END CODE ---

Every time I run the dhts() command, I get the following error: 

Error in dht2(Coy.hn$ddf, observations = coyobs.dht, transects = coytsects, : Some transects have Effort <=0 or NA

I have checked over and over and over again, and there are no <=0 or NA values in my Effort column whatsoever. I've restarted the RStudio program in case it was a software problem, I've rounded up my effort numbers from decimals in case that was tripping up the command, and I'm still getting the same error. 

I looked up a similar question from 2024 and the answer didn't help, as my data is stratified geographically and each stratum was treated slightly differently, again due to the number of cameras. 

I know the ds() command will give me abundance and density estimates, but I would really like to figure out what the issue is here instead of just ignoring it, as I will need to use this in the ongoing project. 

Thanks, 

Sunny M. 

Eric Rexstad

unread,
Apr 16, 2025, 3:17:27 AM4/16/25
to distance-sampling, Sunny Murphy
Greetings Sunny:

There is quite a lot packed into your email. Let me try to unpack the simplest pieces.

If you are analysing data from a survey with geographic stratification, there is no need to use dht2(). Both stratum-specific and aggregate estimates produced by ds() will suit your purposes. dht2() only needs to be used when there are other forms of stratification (replicate or object-level stratification).

To demonstrate the correct arguments for a call to dht2(), and to show the equivalence between results from ds() and dht2() with geographic stratification, here is a demonstration using the minke whale data provided with the Distance package:

library(Distance)
data(minke)
minke.trunc <- 1.5
minke.df.all <- ds(minke, truncation=minke.trunc, key="hr", adjustment=NULL)
usingdht2 <- dht2(ddf=minke.df.all, flatfile=minke, 
                  strat_formula=~Region.Label, stratification="geographical")
print(usingdht2)
print(minke.df.all$dht)

> print(usingdht2) Abundance estimates from distance sampling Stratification : geographical Variance       : R2, n/L Multipliers    : none Sample fraction : 1 Summary statistics: Region.Label   Area CoveredArea  Effort  n  k    ER se.ER cv.ER        North 630582     4075.14 1358.38 49 12 0.036 0.013 0.365        South  84734     1453.23  484.41 39 13 0.081 0.018 0.225        Total 715316     5528.37 1842.79 88 25 0.048 0.011 0.237 Abundance estimates: Region.Label Estimate       se    cv  LCI   UCI     df        North    12181 4638.628 0.381 5500 26980 12.968        South     3653  910.097 0.249 2182  6118 17.963        Total    15835 4834.285 0.305 8388 29891 15.255 Component percentages of variance: Region.Label Detection    ER        North      7.94 92.06        South     18.56 81.44        Total     17.07 82.93

> print(minke.df.all$dht) Abundance and density estimates from distance sampling Variance       : R2, N/L Summary statistics  Region   Area CoveredArea  Effort  n  k         ER      se.ER     cv.ER 1  North 630582     4075.14 1358.38 49 12 0.03607238 0.01317937 0.3653591 2  South  84734     1453.23  484.41 39 13 0.08051031 0.01809954 0.2248102 3  Total 715316     5528.37 1842.79 88 25 0.04133635 0.01181436 0.2858103 Abundance:  Region  Estimate        se        cv      lcl       ucl       df 1  North 12181.419 4638.6283 0.3807954 5499.950 26979.692 12.96781 2  South  3653.345  910.0975 0.2491135 2181.595  6117.971 17.96263 3  Total 15834.764 4834.2848 0.3052957 8388.423 29891.167 15.25496 Density:  Region   Estimate          se        cv         lcl        ucl       df 1  North 0.01931774 0.007356106 0.3807954 0.008722023 0.04278538 12.96781 2  South 0.04311546 0.010740641 0.2491135 0.025746391 0.07220207 17.96263 3  Total 0.02213674 0.006758251 0.3052957 0.011726878 0.04178736 15.25496


You will see from the code above, the arguments "observations", "transects" and "er_est" are superfluous to dht2() when used to produce results from a geographically stratified survey. There is also no need to send only the ddf list element of the dsmodel object to dht2; dht2 can find what it needs from the supplied dsmodel object.

Can you explain why you will need dht2 in your project?

As an aside, I gather your project uses camera traps. Having 5 or even 10 cameras (the equivalent of transects) is likely to give you poor estimates of encounter rate variance with resulting abundance estimates having quite poor precision.

From: 'Sunny Murphy' via distance-sampling <distance...@googlegroups.com>
Sent: 15 April 2025 17:46
To: distance-sampling <distance...@googlegroups.com>
Subject: [distance-sampling] Error when using dht2
 
--
You received this message because you are subscribed to the Google Groups "distance-sampling" group.
To unsubscribe from this group and stop receiving emails from it, send an email to distance-sampl...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/distance-sampling/a6c8f6e2-3f30-43e4-8d2f-6c1b23fbbcb5n%40googlegroups.com.
Message has been deleted
Message has been deleted

Sunny Murphy

unread,
Apr 19, 2025, 1:54:35 AM4/19/25
to distance-sampling
Good morning, 

Thanks for your response. Firstly, on the number of cameras: Unfortunately, some of the preserves we're working in are quite small, and 5 is the maximum number of cameras we can fit. We will group these together as one "region" in the end, but for now, I just wanted to see the results we would get from the pilot when keeping them as separate preserves. These areas have different managers and thus, it is important that we be able to provide information per preserve. Based on the pilot analysis, we will make adjustments as necessary. To assist in precision, we will be doing scat surveys alongside camera monitoring. 

Per this post and from reading the "Help" information on dht2(), I got the impression that dht2() could possibly provide more accurate information for stratified, multispecies surveys. This would be useful due to having to place fewer cameras in some preserves in others, the fact that some species occur far less frequently than others, and also due to the fact that we're going to be using scent lures, and so I want to be prepared for any changes that will bring to encounter rate. I understand that to estimate species-specific density and abundance, I can specify these via the "obs_table =" function, which I've already done, but I'm just looking to see if dht2() could be helpful or more accurate. 

Thanks for your help, 

SM

Sunny Murphy

unread,
Apr 19, 2025, 1:54:43 AM4/19/25
to distance-sampling
I'm not sure what happened to my previous response; really unfortunate that it seems to have disappeared, but I'll briefly summarize it here: 

Some of the preserves we're working in are quite small and can only fit 5-10 cameras, which is why we're limited in that regard. The pilot study results and coincidental scat surveys will help us improve accuracy as best we can, given what we're working with. 

I wanted to use dht2() because there will be different treatments (e.g., scent lures) per preserve/grid, and this is a multispecies survey, so there will be object-level stratification, in addition to geographical stratification. I understand that I can do species-specific estimations by simply creating a separate dataframe per species (which I've done) and/or specifying with the "obs_table=" argument (which I've also done). I just wanted to see if dht2() could possibly help with more accurate/informative results. 

Thanks for your help. 

SM 
On Wednesday, April 16, 2025 at 3:17:27 AM UTC-4 Eric Rexstad wrote:
Reply all
Reply to author
Forward
0 new messages