# first.r: Obtain a Vector of Sample Sizes with Total Number of Samples... In elec.strat: Functions for election audits using stratified random samples

## Description

`first.r, next.r`, and `propSizes` obtain sample sizes so that the total number of samples is fixed. `first.r` uses the `first.r` algorithm, `next.r` uses the `next.r` algorithm, and `propSizes` finds a vector of sample sizes that is proportional to stratum sizes.

See Higgins, Rivest, Stark for details about the `first.r` and the `next.r` algorithms.

## Usage

 ```1 2 3``` ``` first.r(Z, n, t = 0, asTaint = FALSE, asNumber = FALSE, M = NULL, initSamp = NULL) next.r(Z, n, t = 0, asTaint = FALSE, asNumber = FALSE, M = NULL, initSamp = NULL) propSizes(Z, n) ```

## Arguments

 `Z` A `strat.elec.data` object. `n` The fixed number of samples. When `initSamp` is provided, `first.r` and `next.r` will run for `n` iterations, adding samples iteratively to `initSamp`; `first.r` and `next.r` will produce a vector of sample sizes with a total of `sum(initSamp) + n)` samples. `t` Value of the observed maximum, either as the MRO, as taint, or as the overstatement of the margin in votes. `asTaint` Set `asTaint = TRUE` if `t` is the maximum observed taint. `asNumber` Set `asNumber` if `t` is the maximum observed overstatement of the margin in votes. `M` A priori margin. If NULL, `M` defaults to 1. `initSamp` An initial choice of sample sizes. Used in call of `get.first.r.samp` and `get.next.r.samp` to reduce computational time.

## Details

The arguments `t, asTaint, asNumber, M` are used in `first.r` and `next.r` in the call of `getEbsMargin`. The `getQ` function is bypassed to increase efficiency.

`propStrat` obtains a vector of sample sizes that has exactly `n` samples. It obtains such a sample by sorting values of `k*sum(Z\$strat\$n)/Z\$strat\$n`, where `k = 0, 1, ...`, in increasing order and allocating a sample to the strata corresponding to the first `n` values. Ties are broken by choosing the strata with the largest number of batches. See Higgins, Rivest, Stark for details.

## Author(s)

Mike Higgins, Hua Yang

## References

M. Higgins, R. L. Rivest, P. B. Stark. Sharper p-Values for Stratified Election Audits

See `get.first.r.samp, get.next.r.samp`, and `get.prop.samp` for finding sample sizes given constraints on the p-value and the largest observed overstatement.
 ```1 2 3 4 5 6 7``` ``` data(MN_Senate_2006) MN_Senate_2006.strat\$strat\$audit <- first.r(MN_Senate_2006.strat, n = 150) BaB(MN_Senate_2006.strat) MN_Senate_2006.strat\$strat\$audit <- next.r(MN_Senate_2006.strat, n = 150) BaB(MN_Senate_2006.strat) MN_Senate_2006.strat\$strat\$audit <- propSizes(MN_Senate_2006.strat, n = 150) BaB(MN_Senate_2006.strat) ```