Dht2 function and binned distaance

102 views
Skip to first unread message

Delphine Ducros

unread,
Jul 23, 2020, 11:14:28 AM7/23/20
to distance-sampling
Hello again everyone,

I have another question: I tried to use the dht2 function on my data, which contains binned distance (columns distbegin and distend).

I have the following table:

Region.Label Area Effort distbegin distend Sample.Label
1         Nord 8961   4.09        NA      NA            1
2         Nord 8961   3.87        NA      NA            2
3         Nord 8961  39.63      0.08    0.18            3
4         Nord 8961  39.63      0.08    0.18            3
5         Nord 8961  39.63      0.08    0.18            3
6         Nord 8961  39.63      0.00    0.08            3

which I used to create the following detection function:

hn.cos2.df <- ds(data, max(data$distend), formula = ~1,key="hn", adjustment="cos", order = 2)

And I am applying th dht2 function as follows:

dht2(ddf=hn.cos2.df, flatfile=data, strat_formula = ~ Region.Label, stratification = "geographical")

However, when I apply the dht2 function, I receive the following warning:

Warning messages:
1: In `[<-.data.frame`(`*tmp*`, flatfile$Sample.Label %in% sl_diff,  :
  provided 7 variables to replace 6 variables
2: In `[<-.data.frame`(`*tmp*`, flatfile$Sample.Label %in% sl_diff,  :
  provided 7 variables to replace 6 variables

And the object resulting from the dht2 function is then incomplete:

Summary statistics:
 Region.Label  Area CoveredArea  Effort n   k ER se.ER cv.ER
            2 22407    2327.068 1491.71 0  18  0     0     0
         Nord  8961    4690.608 3006.80 0  87  0     0     0
          Sud 10699    3586.924 2299.31 0  42  0     0     0
        Total 42067   10604.599 6797.82 0 147  0     0     0

Abundance estimates:
 Region.Label Estimate se  cv LCI UCI  df
            2        0  0   0   0   0   1
         Nord        0  0   0   0   0   1
          Sud        0  0   0   0   0   1
        Total        0  0 NaN NaN NaN NaN

Component percentages of variance:
 Region.Label Detection  ER
            2       NaN NaN
         Nord       NaN NaN
          Sud       NaN NaN
        Total       100   0

I have no NA in my data, except in the distbegin and distend colums, for cases where no observation was made.

I tried replacing the columns distbegin and distend by a single column named "distance", made of a vector of random values, and in that case, I do not have the warning message anymore, and the object resulting from the dht2 function is then complete.

Would that mean that dht2 only takes a "distance" column, but not binned distances?

Otherwise, would you any idea about why I get this warning?

Many thanks for you help ! 

Delphine


Eric Rexstad

unread,
Jul 23, 2020, 1:43:04 PM7/23/20
to Delphine Ducros, distance-sampling

Delphine

Thanks for your report about problems with `dht2`.  We'll have a look at the problem and may contact you off-line about particulars.

Meanwhile, you should be able to work around the problem in the manner you described: replace the two columns distbegin and distend with a single column named "distance", into that column place the midpoint of the bin (e.g. below your end points are 0.08 and 0.18, use the value 0.13 for distance.

Then use the "cutpoints=" argument in your call to ds() to conduct your binned analysis.  You should be able to send the result of that call to ds() off to dht2().  Let us know if that works for you.

--
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 on the web visit https://groups.google.com/d/msgid/distance-sampling/b73d3a81-b8f0-453a-a1b9-95501257ac83o%40googlegroups.com.
-- 
Eric Rexstad
Centre for Ecological and Environmental Modelling
University of St Andrews
St Andrews is a charity registered in Scotland SC013532

David Lawrence Miller

unread,
Jul 24, 2020, 2:06:29 AM7/24/20
to Delphine Ducros, distance-sampling
Hi Delphine, hi listfolks,

Thanks for taking dht2 for a spin and sorry you had some problems. Would
you mind sending me your data off-list and I'll take a look at what's
going on here?

cheers,
--dave


On 23/07/2020 16:14, Delphine Ducros wrote:
> --
> 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
> <mailto:distance-sampl...@googlegroups.com>.
> <https://groups.google.com/d/msgid/distance-sampling/b73d3a81-b8f0-453a-a1b9-95501257ac83o%40googlegroups.com?utm_medium=email&utm_source=footer>.

DEFOS DU RAU Pierre

unread,
Jul 24, 2020, 2:50:04 AM7/24/20
to Eric Rexstad, Delphine Ducros, distance...@googlegroups.com

Hello & Thank you Eric and Delphine. But when it comes to multispecies DS survey with binned distance (e.g. songbird by point or seabirds by transect), would it make sense to estimate local guild species richness in a DS framework, as one can expect to detect all species in the closest bin but less so in the further bins? Would it be theoretically “allowed” ??? Of course, assuming models would converge, regional size estimates would make no sense but DSM application could be partially interesting by outputting a layer of local sp richness, no?

Sorry if I am totally misleading but curiosity nibbles me (as we say in French)

Thanks a lot for all the so fast replies to any questions almost everyday on this list!

Pierre

 

De : 'Eric Rexstad' via distance-sampling <distance...@googlegroups.com>
Envoyé : jeudi 23 juillet 2020 19:42
À : Delphine Ducros <ducros....@gmail.com>; distance-sampling <distance...@googlegroups.com>
Objet : Re: [distance-sampling] Dht2 function and binned distaance

Delphine Ducros

unread,
Jul 24, 2020, 11:29:23 AM7/24/20
to distance-sampling
Hello,

Thank you very much for your quick reply !  Indeed, using a single column named 'distance' and cutpoints worked for me !

Cheers,

Delphine
To unsubscribe from this group and stop receiving emails from it, send an email to distance...@googlegroups.com.

David Lawrence Miller

unread,
Jul 28, 2020, 5:51:23 AM7/28/20
to Delphine Ducros, distance-sampling
Just to follow-up on this issue. Delphine and I corresponded off-list to
get to the bottom of this.

The warnings were caused by a bug in how pre-binned data was handled in
dht2 (i.e., when columns distend and distbegin were present but distance
is not). This is fixed in the latest versions of Distance on github and
will be included in the forthcoming CRAN release.

In the meantime the fix suggested by Eric seems to do the job if you
don't want to use the development version of the package.

cheers,
--dave

On 23/07/2020 16:14, Delphine Ducros wrote:
> --
> 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
> <mailto:distance-sampl...@googlegroups.com>.
> <https://groups.google.com/d/msgid/distance-sampling/b73d3a81-b8f0-453a-a1b9-95501257ac83o%40googlegroups.com?utm_medium=email&utm_source=footer>.

Delphine Ducros

unread,
Jul 30, 2020, 3:07:34 AM7/30/20
to distance-sampling
Many thanks again David !!

Cheers,

Delphine

Annika Zuleger

unread,
Feb 9, 2021, 8:34:13 AM2/9/21
to distance-sampling
Hello everyone,

I am doing a camera trap distance sampling project, which I already completed using the Distance for Windows software. 

I am now trying to move my analysis to R and experience pretty much the same problem as discussed aboved although I don't use distbegin and distend, but a single column for distance and cutpoints in the analysis. This is what my data looks like and the model I'm fitting:

head_deer.png
sum_deer_hr.png
However, when I use the dht2 function I receive the same warning and incomplete output (see below, in this example my data also includes transects without observations, but the problems remains when I run the analysis only for those transects where the species was observed). 

deer_dht_no_strat.png

Any suggestions?

I already tried to install the latest version of Distance from Github, but it always returns the error: "Failed to install 'Distance' from GitHub:
  (konvertiert von Warnung) cannot remove prior installation of package ‘dplyr’ "

Thank you very much!

Best,
Annika

Eric Rexstad

unread,
Feb 9, 2021, 9:43:03 AM2/9/21
to Annika Zuleger, distance-sampling

Annika

A quick read of your question suggests the problem might be at the end of your email, rather than the beginning.

I think the problem you are having may have been fixed last summer (when the correspondence between Delphine and Dave Miller took place).  That version of the Distance package 1.0.2 was loaded onto CRAN last December.

I suggest you install version 1.0.2 of Distance from CRAN (which hopefully will circumvent the "fail to install Distance from Github" problem).  Try running your analysis with that version of the package and see what happens.  If the problems persist, we will further investigate.

To unsubscribe from this group and stop receiving emails from it, send an email to distance-sampl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/distance-sampling/5c21290f-7927-4695-b37d-f2d8e61f83c0n%40googlegroups.com.

Annika Zuleger

unread,
Feb 9, 2021, 10:37:00 AM2/9/21
to distance-sampling
Dear Eric,

Thanks for the quick reply!

According to R I have the latest version (1.0.2) installed (I just installed it last week for the first time), so I guess the problem must be somewhere else.

Eric Rexstad

unread,
Feb 10, 2021, 2:42:17 AM2/10/21
to Annika Zuleger, distance-sampling

Annika

OK, that eliminates the simple solution, meaning we need to investigate more complex solutions.  Would you be willing to send your data set and the code you have run off-list to me so I can investigate further?

Annika Zuleger

unread,
Feb 12, 2021, 4:39:27 AM2/12/21
to distance-sampling
Hey everyone,

a quick follow-up on this issue. Eric and me corresponded off-list and got the the bottom of my problem:

The main issue was basically just a problem with my dataset, because I had a sampling location (in my case camera trap) with 0 survey effort, resulting in the NaNs in the analysis and outpout of the dht2 function. Simply removing this line from my data frame already solved the main issue of false dht2 output. 

My encounter rate estimates were also actually not 0, but because this was a camera trap project and my survey effort is measured in seconds and therefore considerably high, the encounter rate was also calculated per seconds and as a result it is so vanishingly small, that R prints it as 0. So no error here.

Regarding the Warning message, I received when running the dht2 function, this was caused because the software expected my data frame to have a field "object", which I did not have. 
Warning_dht2.png
The simple solution is to add a field "object" with detections numbered 1 to number of detections. 
The Distance package code on Github has already been corrected so that the "object" field is no longer required in the data frame.

I hope this helps some of you who experience similar problems.

Thanks so much again, Eric!

Best, Annika
Reply all
Reply to author
Forward
0 new messages