# optStrat: Obtain an Optimal Vector of Sample Sizes Given Constraint on... In elec.strat: Functions for election audits using stratified random samples

## Description

`optStrat` will obtain sample sizes so that, if a maximum observed overstatement of `t` or less is observed, the sample will produce a p-value less than `alpha`. The sample that `optStrat` obtains minimizes the total number of batches required for audit. `optStrat` includes options so that, given the number of samples required for audit for optimal sample sizes, the sample that minimizes the expected number of audited ballots is found.

`optStrat` can be a very computationally expensive function, and should only be used for small contests.

## Usage

 ```1 2``` ``` optStrat(Z,alpha, t, bal=TRUE, optBal=FALSE, numSamp = TRUE, asTaint = FALSE, asNumber = FALSE, M = NULL, takeOutZeroMMB=TRUE) ```

## Arguments

 `Z` A `strat.elec.data` object. `t` Value of the observed maximum, either as the MRO, as taint, or as the overstatement of the margin in votes. `alpha` Threshold for the p-value. If an audit does not uncover an overstatement less than `t`, the sample obtained will ensure that the p-value is less than `alpha`. `bal` If `bal = TRUE`, the output will include the expected number of audited ballots for the sample. `optBal` If `bal = TRUE`, given the number of batches required for audit in an optimal sample, `optSamp` will find the sample that minimizes the expected number of audited ballots. This may dramatically increase the runtime of `optStrat`. `numSamp` If `numSamp = TRUE`, the output will include the total number of audited batches. `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. `takeOutZeroMMB` Setting `takeOutZeroMMB = TRUE` will consider batches with a `maximumMarginBound` of zero as having no chance of being sampled.

## Author(s)

Mike Higgins

See `get.first.r.samp, get.next.r.samp`, and `get.prop.samp ` for other methods to obtain sample sizes so that, if a maximum observed overstatement of `t` or less is observed, the sample will produce a p-value less than `alpha`. `get.first.r.samp` uses the `first.r` algorithm to obtain the sample, `get.next.r.samp` uses the `next.r` algorithm to obtain the sample, and `get.prop.samp` finds a vector of sample sizes that is proportional to stratum sizes.
 ```1 2 3 4``` ``` data(CA_House_2008) optStrat(CA_House_2008.strat[[3]], alpha = .1, t = .01, asTaint = TRUE) optStrat(CA_House_2008.strat[[3]], alpha = .1, t = .01, asTaint = TRUE, optBal = TRUE) ```