election_event_probs: Compute probability of election events

View source: R/event_probabilities_from_event_list.R

election_event_probsR Documentation

Compute probability of election events

Description

election_event_probs() takes an election argument (created by e.g. plurality_election() or irv_election()) and returns a list containing, for each election event (i.e. each class of election outcomes),

  • a scalar integral indicating the probability of the event,

  • a matrix P indicating which candidate elected (rows) as a function of which action the voter takes (columns), and

  • other objects depending on the method used to compute the event probabilities.

Usage

election_event_probs(
  election,
  method = "sc",
  mc_method = "density",
  alpha = NULL,
  mu = NULL,
  precision = NULL,
  sigma = NULL,
  sims = NULL,
  num_sims = 1e+05,
  sim_window = 0.01,
  cand_names = NULL,
  drop_dimension = F,
  merge_adjacent_pivot_events = F,
  skip_non_pivot_events = T,
  skip_compound_pivot_events = T,
  minimum_volume = 0,
  force_condition_based_mc = F,
  store_time = T,
  maxEvals = .Machine$integer.max,
  tol = 0.01,
  eval_points_for_1d_integral = 100,
  ev_increments = 50,
  en_increments_1st_round = 30,
  en_increments_2nd_round = 100,
  bw_divisor = 2,
  ...
)

Arguments

election

A list with elements n (electorate size), ordinal (logical flag indicating whether it is an ordinal system or not), and events, a list of election events each with elements win_conditions, tie_condition_rows, and P. See ?event_list_functions.

method

Method for estimating event probabilities: one of "sc" (SimplicialCubature), "mc" (Monte Carlo), "ev" (Eggers-Vivyan), or "en" (Eggers-Nowacki). See below for details.

mc_method

Method for Monte Carlo estimation of pivot event probabilities: one of "rectangular", "density", "naive_density".

alpha

Optional vector of parameters for Dirichlet distribution (one for each ballot type). In a plurality election with k candidates, should be of length k; in an ordinal system with 3 candidates, should be length 6.

mu

Optional vector of location parameters for Dirichlet distribution or logistic normal distribution.

precision

Optional scalar precision parameter for Dirichlet distribution.

sigma

Optional covariance matrix for logistic normal distribution.

sims

Optional matrix of simulated elections, one column per ballot type.

num_sims

Optional number of simulated elections, if not provided in sims.

sim_window

Vote share discrepancy within which two candidates will be "nearly tied" when method="mc" and mc_method="rectangular". Larger sim_window means more bias, smaller means more variance. Set to .01 by default.

cand_names

Optional vector of candidate names. If not supplied, will be "a", "b", "c", etc.

drop_dimension

Method "sc" can be sped up for pivot events by integrating the belief function on facets where one candidate is exactly 1/2n behind the other (or they are exactly tied, if drop_dimension=T) rather than in the hypervolume where two candidates are nearly tied.

merge_adjacent_pivot_events

If F, method "sc" computes the probability of e.g. candidate a being just behind b and vice versa; if T, method "sc" saves time by computing the probability of candidates a and b being approximately or exactly tied (depending on drop_dimension).

skip_non_pivot_events

Set to T to avoid computing the probability of events where one vote cannot make a difference, e.g. where candidate a wins by more than one vote. Relevant for methods "sc" and "mc".

skip_compound_pivot_events

Set to T to avoid computing the probability of (near) three-way ties in plurality.

minimum_volume

If greater than zero, we check the volume of S matrices and skip those that do not contain at least minimum_volume.

force_condition_based_mc

Set to T to force Monte Carlo simulations to use the conditions in the election object rather than a faster bespoke method.

store_time

By default we store the time each computation takes, in seconds.

maxEvals

The maximum number of function evaluations to compute an integral via method "sc" (passed to SimplicialCubature::adaptIntegrateSimplex()). If this is exceeded, you still get a result, but it will not be as precise as requested. You can check whether the limit kicked in by looking at the 'message' attribute of each event probability. To prevent the limit from binding, the default is a very large value; the computation may therefore take a very long time.

tol

The relative error requested in computing an integral via method "sc" (passed to SimplicialCubature::adaptIntegrateSimplex()). For faster imprecise computation (e.g. for testing), set to e.g. .2.

eval_points_for_1d_integral

Sets the subdivisions argument to integrate() when SimplicialCubature::adaptIntegrateSimplex() will be performed on a line.

ev_increments

Increments for numerical integration in method "ev".

en_increments_1st_round

Increments for numerical integration of first-round pivot events in method "en".

en_increments_2nd_round

Increments for numerical integration of second-round pivot events in method "en".

bw_divisor

If ks::hpi determines optimal bandwidth for density estimation is h, we use h/bw_divisor when mc_method="density" or mc_method="naive_density". Allows for undersmoothing.

Details

There are four methods for computing the probability of a given election event:

  • "sc" (or "SC" or "SimplicialCubature") partitions the election event into disjoint simplices and uses the SimplicialCubature to integrate the belief function over these simplices using the adaptive algorithm of Genz and Cools. Slow, but can be sped up by skipping non_pivot_events (skip_non_pivot_events=T), dropping a dimension (drop_dimension=T), merging adjacent pivot events (merge_adjacent_pivot_events=T), and/or (when relevant) skipping compound pivot events (skip_compound_pivot_events=T). Currently implemented only for Dirichlet and Logistic Normal beliefs, but with some adjustment to the syntax could be extended to handle other distributions (get in touch!).

  • "mc" (or "MC" or "Monte Carlo") counts the proportion of simulated elections (supplied by the user or generated from user-supplied parameters) that satisfy election event conditions. Also slow (especially with large num_sums), but like "sc" can be sped up. Can generate simulations from Dirichlet or Logistic Normal belief distributions, or can be applied to any matrix of simulated elections supplied by the user.

  • "ev" (or "EV" or "Eggers-Vivyan") uses numerical integration of the Dirichlet distribution to estimate pivot event probabilities in plurality elections, making an independence assumption when there are more than four candidates. Fast but overstates the probability of low-probability events and limited to Dirichlet beliefs.

  • "en" (or "EN" or "Eggers-Nowacki") uses numerical integration of the Dirichlet distribution to estimate pivot event probabilities in three-candidate IRV elections up to an arbitrary degree of precision. Fast but limited to Dirichlet beliefs.

Value

A list containing one list per election event. Each of these lower-level lists contains

  • integral the event probability

  • P the election probability matrix, indicating which candidate (rows) is elected at this event depending on which action (columns) the voter takes.

  • seconds_elapsed the time to compute this event probability.

For method "sc" these event-specific lists include other output from SimplicialCubature::adaptIntegrateSimplex(), such as functionEvaluations and message.

Examples

alpha3 <- c(.4, .35, .25)*85
sc_out <- plurality_election(k = 3) %>%
  election_event_probs(method = "sc", alpha = alpha3, tol = .1)
sc_out[["a_b"]]$integral
sc_out[["a_b"]]$seconds_elapsed

mc_out <- plurality_election(k = 3) %>%
  election_event_probs(method = "mc", alpha = alpha3, num_sims = 500000)
mc_out[["a_b"]]$integral
mc_out[["a_b"]]$seconds_elapsed

mc_out <- plurality_election(k = 3) %>%
  election_event_probs(method = "ev", alpha = alpha3)
mc_out[["a_b"]]$integral
mc_out[["a_b"]]$seconds_elapsed

aeggers/pivotprobs documentation built on Oct. 28, 2024, 9:46 a.m.