Directed review round: units drawn with probability proportional to size
Source:R/select_directed.R
select_directed.RdDraws a review round aimed at the units where a review is worth most,
while keeping a known inclusion probability for every clip. A unit is a
group of occasions, such as site x month x species. Each unit gets a
size, typically the expected gain of one review predicted by an
occupancy model; n_units units are drawn with probability
proportional to size (PPS), one occasion is drawn at random within each
drawn unit, and every prediction of that occasion at or above
threshold becomes a clip, as in sampling_mode = "random_detections"
of select_clips().
Usage
select_directed(
detections,
units,
n_units,
threshold,
size_col = "size",
floor = 0.05,
occasion_unit = c("file", "minute"),
previous = NULL,
seed = 2026,
remap_from = NULL,
remap_to = NULL
)Arguments
- detections
A data frame of predictions, one row per BirdNET prediction, as returned by
read_selection_tables()(columnssite,confidence,begin_path,begin_time,end_timeandfile_offset).- units
A data frame with one row per eligible unit: the columns that define the unit (any columns of the prepared predictions, such as
site,species_codeandmonth) and the size column. Only listed units are drawn, so leave out the units that need no review, for instance those where a review has already confirmed the species.- n_units
Integer scalar >= 1, number of units to draw.
- threshold
Numeric scalar, confidence threshold: an occasion is a candidate when it has at least one prediction at or above it, and its clips are all such predictions. Use the threshold of the occupancy analysis.
- size_col
Character scalar, column of
unitswith the size (a non-negative numeric column withoutNA).- floor
Numeric scalar >= 0, share of the mean size added to every size, so that a unit with size 0 can still be drawn. Without it, a unit the model judges worthless is never reviewed and the model is never corrected there.
- occasion_unit
Character scalar, the occasion of the occupancy model:
"file"(the whole recording) or"minute"(minute of the file, fromfile_offset).- previous
NULL, a character vector of paths, a data frame, or a list of these: manifests of earlier review rounds (of any design). Their clips are left out, matched by recording file and start: an occasion is a candidate only while it has a prediction at or abovethresholdnot yet reviewed.- seed
Integer scalar, seed of the draws. The global random number generator is left as it was.
- remap_from, remap_to
NULLor character scalars. Replace the prefixremap_fromof thebegin_pathpaths byremap_to, e.g."N:/"and"/Volumes/Arara/". Backslashes are turned into forward slashes first.
Value
The manifest of the round, with the columns of select_clips(),
sampling_mode = "directed_pps", n_candidates
(\(N_u\)), n_drawn = 1 and, at the end, stratum (the unit, its
values joined by |). The attribute "units" holds the units
with their size, size_used (after the floor), n_occasions,
inclusion_prob_unit and drawn, for the record of the round; save it
next to the manifest.
Details
Inclusion probabilities. With sizes \(x_u\) (after the floor),
the inclusion probability of unit \(u\) is
\(\pi_u = n x_u / \sum x\), and units whose \(\pi_u\) would exceed 1
are taken with certainty while the others share the rest of n_units.
The units are drawn by systematic PPS
sampling in a random order, which gives exactly these \(\pi_u\). The
occasion is then drawn among the \(N_u\) candidate occasions of the
unit, so each clip has inclusion_prob \(= \pi_u / N_u\). The round is
conditional on the earlier rounds: inclusion_prob is the probability
of this round, given what was reviewed before.
What the weights support. Weighted by 1 / inclusion_prob, the clips
of the round estimate totals and ratios (such as the precision) of the
candidate predictions of the listed units (Horvitz and Thompson 1952,
doi:10.1080/01621459.1952.10483446
). Systematic PPS has no simple
joint inclusion probability, so the exact design variance is not
available; approximations that treat the draw as with replacement are
usually conservative. The units were chosen by a model, so the round is
not a sample of all predictions: an occupancy model that reads it needs
the inclusion probabilities, which export_occupancy_data() writes.
A unit without candidate occasions (all reviewed, or no prediction at or
above threshold) is dropped with a message before the draw.
Examples
ex <- system.file("extdata", "example", package = "sheepdog")
pred <- read_selection_tables(file.path(ex, "birdnet"))
#> 4 combined table(s) and 0 per-audio table(s) found in 4 folder(s):
#> - /home/runner/work/_temp/Library/sheepdog/extdata/example/birdnet/ARA: BirdNET_SelectionTable.txt
#> - /home/runner/work/_temp/Library/sheepdog/extdata/example/birdnet/BAI: BirdNET_SelectionTable.txt
#> - /home/runner/work/_temp/Library/sheepdog/extdata/example/birdnet/NHE: BirdNET_SelectionTable.txt
#> - /home/runner/work/_temp/Library/sheepdog/extdata/example/birdnet/XAR: BirdNET_SelectionTable.txt
#> 7553 predictions read from 4 site(s).
# units and their size, for instance the expected gain from a model
units <- data.frame(site = c("ARA", "BAI", "NHE", "XAR"),
species_code = "Boana raniceps_boa-ran",
month = "2021-11", size = c(1, 2, 3, 4))
sel <- select_directed(pred, units, n_units = 2, threshold = 0.5)
#> 3 clips from 2 unit(s) drawn of 4 (round 1).
attr(sel, "units")
#> site species_code month size n_occasions size_used
#> 1 XAR Boana raniceps_boa-ran 2021-11 4 15 4.125
#> 2 NHE Boana raniceps_boa-ran 2021-11 3 15 3.125
#> 3 BAI Boana raniceps_boa-ran 2021-11 2 2 2.125
#> 4 ARA Boana raniceps_boa-ran 2021-11 1 14 1.125
#> inclusion_prob_unit drawn
#> 1 0.7857143 TRUE
#> 2 0.5952381 TRUE
#> 3 0.4047619 FALSE
#> 4 0.2142857 FALSE
# then cut_clips(sel, "validation_directed") with the audio at hand