Converts a creel schedule calendar and circuit definitions into a
sampling frame tibble with inclusion_prob and p_period columns
ready for creel_design(survey_type = "bus_route").
Inclusion probability formula: inclusion_prob = p_site * p_period
where p_period = crew / n_circuits.
n_circuits is the number of distinct circuit values in sampling_frame
(or 1 when circuit is NULL). crew is the number of field crews
deployed simultaneously.
Usage
generate_bus_schedule(
schedule,
sampling_frame,
site,
p_site,
circuit = NULL,
crew,
seed = NULL
)Arguments
- schedule
A
creel_scheduletibble fromgenerate_schedule(). Currently unused in computation but required to ensure the caller has built a valid schedule before constructing the sampling frame.- sampling_frame
A data frame with site and p_site columns (and optionally circuit).
- site
Column in
sampling_framegiving site identifiers (tidy selector: bare name, quoted string, or tidyselect helper).- p_site
Column in
sampling_framegiving per-site selection probability within the circuit. Values must sum to 1.0 per circuit (tolerance 1e-6).- circuit
Optional column giving circuit assignment. If
NULL, all sites are treated as a single circuit.- crew
Integer scalar: number of crews in the field simultaneously.
- seed
Optional integer seed (reserved for future randomised designs; currently unused as the function is deterministic).
Value
A tibble: sampling_frame columns plus p_period and
inclusion_prob. inclusion_prob = p_site * p_period.
Examples
sched <- generate_schedule(
start_date = "2024-06-01",
end_date = "2024-06-14",
n_periods = 1,
sampling_rate = c(weekday = 0.3, weekend = 0.6),
seed = 42
)
frame <- data.frame(
site = c("A", "B", "C"),
p_site = c(0.4, 0.3, 0.3),
stringsAsFactors = FALSE
)
generate_bus_schedule(sched, frame, site = site, p_site = p_site, crew = 2)
#> # A tibble: 3 × 4
#> site p_site p_period inclusion_prob
#> <chr> <dbl> <dbl> <dbl>
#> 1 A 0.4 2 0.8
#> 2 B 0.3 2 0.6
#> 3 C 0.3 2 0.6
