Skip to contents

compromise_allocation() needs the cost of a unit in each stratum, which is not a constant: the units of all strata share the routes, and a stratum far from the depot or thinly spread costs more to reach. This function measures the field cost by routing samples of several allocations around the current one, fits the cost surface G(n) = c0 + sum_h a_h n_h + b sqrt(sum_h n_h) (a cost per unit of each stratum plus a travel term shared by the whole sample, as in routed_cost_curve()), and allocates again with the marginal costs a_h + b / (2 sqrt(n)), as two_stage_design() does. The sample sizes come from the fitted surface, so the design spends the budget at its routed cost. It stops when the allocation no longer changes.

Usage

compromise_design(
  frame,
  depot,
  cost_model,
  strata,
  planning,
  sd,
  budget,
  criterion = c("minimax", "weighted", "average"),
  weights = NULL,
  totals = NULL,
  cost_start = NULL,
  max_iter = 6,
  size = NULL,
  selection = c("lpm", "systematic", "srs"),
  matrix = NULL,
  method = c("haversine", "euclidean", "osrm"),
  max_length = Inf,
  max_stops = Inf,
  n_rep = 5,
  iterations = 100,
  seed = 1
)

Arguments

frame

Data frame of units as in select_units(), including the depot row named in depot.

depot

Name of the depot unit in frame$unit.

cost_model

A field_cost_model().

strata

Column of frame with the stratum of each unit.

planning

Data frame with a column stratum (the strata of frame) and one standard-deviation column per study variable.

sd

Names of the standard-deviation columns, one per variable.

budget

Field budget, in the currency of the cost model.

criterion

"minimax", "weighted" or "average".

weights

Weights of the variables for "weighted" and "average", in the order of sd (equal by default).

totals

Optional population totals of the variables, to report the coefficients of variation.

cost_start

Starting cost per unit of each stratum, named by stratum (default: the visit and interview costs plus the travel cost of the median trip from the depot to the units of the stratum).

max_iter

Maximum number of rounds.

size

Optional size column for probability-proportional-to-size selection.

selection

Selection method of select_units(): "lpm", "systematic" or "srs".

matrix

Optional travel_matrix() of the frame (computed from the coordinates otherwise).

method

Distance method of travel_matrix() when matrix is NULL ("osrm" queries the road network once for the whole frame).

max_length, max_stops

Route limits passed to route_fieldwork().

n_rep

Routed samples per allocation of the cost surface.

iterations

GRASP iterations per routing.

seed

Seed.

Value

The final fieldopt_compromise_allocation, whose column cost is the marginal cost per unit of each stratum and whose attribute cost is the routed cost G(n), with the extra attributes cost_average (G(n) / n), cost_coef (c0, one a per stratum, b), cost_points (the routed allocations with their mean cost), r_squared of the surface, history (one row per round) and converged.

Details

The relative losses are those of compromise_allocation() at the final marginal costs: each variable's own optimum is priced with the same costs as the compromise.

Examples

set.seed(4)
cells <- expand.grid(x = 1:12, y = 1:12)
cells$unit <- paste0("c", seq_len(nrow(cells)))
cells$zone <- ifelse(cells$x <= 4, "near", "far")
frame <- rbind(data.frame(unit = "depot", x = 1, y = 6, zone = NA), cells)
model <- field_cost_model(per_travel = 4, per_unit = 30)
planning <- data.frame(
  stratum = c("near", "far"), sd_corn = c(30, 12), sd_cattle = c(8, 20)
)
compromise_design(frame, "depot", model,
  strata = "zone", planning = planning, sd = c("sd_corn", "sd_cattle"),
  budget = 3000, method = "euclidean", n_rep = 2, iterations = 10
)
#> 
#> ── Compromise allocation (minimax) ─────────────────────────────────────────────
#> n = 86 for a cost of 2988 (budget 3000); largest loss 60.7% above a variable's
#> own optimum.
#> Routed cost: the column cost is the marginal cost per unit of each stratum;
#> average 34.74 per unit (surface fitted on 18 routed allocations, R-squared 1).
#> sd_corn: variance 32350, 1.607 times its optimum 20140.
#> sd_cattle: variance 31400, 1.601 times its optimum 19610.
#> # A tibble: 2 × 4
#>   stratum  size  cost     n
#>   <chr>   <int> <dbl> <int>
#> 1 near       48  32.8    32
#> 2 far        96  32.9    54