Error in cat("Sample fraction :", ifelse(attr(x, "sample_fraction")

91 views
Skip to first unread message

Libby White

unread,
Mar 5, 2024, 2:33:07 AMMar 5
to distance-sampling
Hi everyone!

I am using distance sampling with camera traps to estimate density of different duiker species. I measured the FOV of my cameras in the field, so each point has a different sample fraction. I included this when running dht2 for density estimates with a data frame that has 2 columns - sample.label and fraction. I'm getting an error I can't quite figure out... it may be a simple fix but I'm stuck! Any help would be appreciated and thank you. 

Best,
Libby White
Screenshot 2024-03-04 at 8.25.01 PM.png

Libby White

unread,
Mar 5, 2024, 2:33:12 AMMar 5
to distance-sampling
Hi everyone!

I am using distance sampling with camera traps to estimate density of different duiker species. I am getting an interesting error when trying to print my result from running dht2 (screenshot attached). I measured the FOV of my cameras in the field, so each point has a different sample fraction. I included this in the dht2 function, with a data frame that has two columns (fraction and sample.label). The error could be a simple fix, but I'm stuck! Any help would be appreciated and thank you. 

Best, 
Libby White
Screenshot 2024-03-04 at 8.25.01 PM.png

Eric Rexstad

unread,
Mar 5, 2024, 2:54:35 AMMar 5
to Libby White, distance-sampling
Greetings Libby.

You've discovered an interesting bug in dht2​. I've not worked with station-specific sampling fractions before.

It appears the code will perform the computations with station-specific sampling fractions, it simply won't let you see the estimates. Note that the error message comes not from calling dht2​, but rather from the print​ function displaying the results.

A work-around for this bug is to examine the object created by dht2​ without printing. Here's an example using the  minke​ data set included in the Distance​ package.

library(Distance)
data(minke)
minke_df <- ds(minke, truncation=1.5, adjustment=NULL)
# now estimate abundance using dht2
# stratum labels are in the Region.Label column
minke_dht2 <- dht2(minke_df, flatfile=minke, stratification="geographical",
strat_formula=~Region.Label)
# can alternatively report density
# print(minke_dht2, report="density")
attr(minke_dht2,"density")$Density
attr(minke_dht2,"density")$Density_CV
attr(minke_dht2,"density")$LCI
attr(minke_dht2,"density")$UCI

It may not be a pretty of presenting the density estimates, but it is better than an error message.  I'll log this bug in our issues tracker. Thanks for finding it.

From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of Libby White <libby...@gmail.com>
Sent: 05 March 2024 01:30
To: distance-sampling <distance...@googlegroups.com>
Subject: {Suspected Spam} [distance-sampling] Error in cat("Sample fraction :", ifelse(attr(x, "sample_fraction")
 
--
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/2d1db37e-1785-4ea2-98da-add0e79716ban%40googlegroups.com.

Libby White

unread,
Mar 5, 2024, 12:46:16 PMMar 5
to distance-sampling
Hi Eric!

Thanks for your response. That example is really helpful. 

Best,
Libby

Reply all
Reply to author
Forward
0 new messages