selection_consistency: Summarize consistency of planning-unit states

View source: R/analysis_selection.R

selection_consistencyR Documentation

Summarize consistency of planning-unit states

Description

Summarize recurrence and disagreement of canonical planning-unit states across stored solutions.

Usage

selection_consistency(x, solution_groups = NULL)

Arguments

x

A solutionset-class object returned by solve.

solution_groups

Optional named list assigning every stored numeric solution id to exactly one group. If NULL, all solutions form the group "all".

Details

States are obtained from get_solution_states. All stored solutions contribute equally, and all planning units are returned. solution_groups can partition the stored solutions into named groups; consistency is then summarized separately within each group.

Frequencies describe the proportion of stored solutions in the corresponding group. They are conditional summaries of the supplied SolutionSet, not probabilities or formal measures of uncertainty. variable is TRUE when more than one state occurs for a planning unit within a solution group.

Value

A data.frame with one row per planning unit and solution group, including selection, managed and unmanaged frequencies, dominant state and frequency, number of observed states, whether the unit is variable within the group, Shannon entropy, and normalized entropy.

See Also

get_solution_states, selection_frequency, selection_similarity, solution_filter

Examples

# Load a complete simulated multi-action problem.
example_data <- load_sim_multiaction()

problem <- create_problem(
  pu = example_data$planning_units,
  features = example_data$features,
  dist_features = example_data$dist_features,
  cost = "cost"
) |>
  add_actions(
    example_data$actions,
    cost = example_data$action_costs
  ) |>
  add_effects(
    example_data$effect_assumptions
  ) |>
  add_constraint_targets_relative(0.05) |>
  add_objective_min_cost(
    alias = "cost",
    include_pu_cost = FALSE
  ) |>
  add_objective_max_effect(
    alias = "benefit"
  ) |>
  set_method_weighted_sum(
    aliases = c("cost", "benefit"),
    runs = set_runs_grid(n = 5),
    normalize_weights = TRUE
  )

if (requireNamespace("rcbc", quietly = TRUE)) {
  problem <- set_solver_cbc(problem, verbose = FALSE)
  solutions <- solve(problem)

  consistency <- selection_consistency(solutions)
  head(consistency)

  solution_ids <- get_runs(solutions)$solution_id
  solution_ids <- solution_ids[!is.na(solution_ids)]

  if (length(solution_ids) >= 2L) {
    cut <- ceiling(length(solution_ids) / 2)
    groups <- list(
      first = solution_ids[seq_len(cut)],
      second = solution_ids[seq.int(cut + 1L, length(solution_ids))]
    )

    selection_consistency(
      solutions,
      solution_groups = groups
    )
  }
}


multiscape documentation built on Oct. 12, 2026, 5:08 p.m.