Bootstrapping stratified analysis in R

252 views
Skip to first unread message

Jamie McKaughan

unread,
Jan 31, 2022, 6:00:07 AM1/31/22
to distance-sampling
Hi team,

I have been having a few emails with Dave Miller, but he suggested I come this way now with a query regarding code to bootstrap a stratified analysis from camera trap DS data.

I have been using this code for the stratified analysis by replication:
bab.hr0.dens <- dht2(bab.hr0.Grid, flatfile=bab, strat_formula = ~Region.Label,
                            er_est = "P2", convert_units = conversion, stratification = 'replicate')


Then used the following for the bootstrap:
Dhat_summarize <- function(ests, fit) {
  return(data.frame(Dhat  = ests$individuals$D$Estimate,
                    Label = ests$individuals$D$Label))
}
bootout <- bootdht(bab.hr0.Grid, flatfile=bab, summary_fun=Dhat_summarize, convert.units = conversion, nboot=1000)
bootout
aggregate(bootout$Dhat, list(bootout$Label), mean)
aggregate(bootout$Dhat, list(bootout$Label), quantile, 0.025)
aggregate(bootout$Dhat, list(bootout$Label), quantile, 0.975)
aggregate(bootout$Dhat, list(bootout$Label), sd)


My results are a bit confusing though, I have pasted the results from one analysis for the mean as an example:

> aggregate(bootout$Dhat, list(bootout$Label), mean)

Group.1   x

1 Grid1    151.3114

2 Grid2    15569.1806

3 Grid3    1039898.7671

4 Total     351873.0864

On one analysis I ran it on the Totals were all just the three grid values summed, but the most recent analysis I have run it on (pasted above) appears the total isn't an accumulation, so I don't know if it is effectively running a 'geographic' bootstrap or not.

As a way round to ensure I am getting the right figures - can I take each grid's result and then take the effort weighted mean from them to produce the final result that imitates a bootstrap by replication?

Hope that makes sense - maybe I am over complicating it, but I don't see how I can bootstrap the results any other way.

Best wishes

Jamie

Eric Rexstad

unread,
Jan 31, 2022, 6:39:28 AM1/31/22
to Jamie McKaughan, distance-sampling
Jamie

Good to hear from you again.  Afraid in the months since our last correspondence, I've forgotten the details of your survey design.  The way you invoke dht2​ suggests the strata are not geographic, but I'm not sure what you want.  As I understand, the first argument to bootdht​ is a ds()​object; I've not had experience sending an dht2​ object to bootdht​.

Perhaps an off-list discussion of your design and the objective of your bootstrap analysis are in order before we return to the list hopefully with some answers.

From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of Jamie McKaughan <jamie.mc...@gmail.com>
Sent: 31 January 2022 11:00
To: distance-sampling <distance...@googlegroups.com>
Subject: {Suspected Spam} [distance-sampling] Bootstrapping stratified analysis in R
 
--
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/b429be1e-0452-4397-baa9-7638dff54453n%40googlegroups.com.

Hannah Madden

unread,
Feb 1, 2022, 1:47:15 PM2/1/22
to distance-sampling
Thanks for the discussion. I would be interested to know the answer as I am also working with stratified data.

Jamie McKaughan

unread,
Feb 7, 2022, 2:55:00 AM2/7/22
to distance-sampling
Hi all,

After further discussions I have reverted to a simple bootstrap as the survey design that I implemented did not require a sophisticated type of stratification. Fitting the simple bootstrap behaved much more as anticipated it should.

Thanks
Jamie


Reply all
Reply to author
Forward
0 new messages