# CAST: CAST Functions In elec: Collection of functions for statistical election audits

## Description

Collection of functions for planning and evaluating results of a CAST election audit. CAST is a system devised by Dr. Philip B., Stark, UC Berkeley Department of Statistics.

`CAST.calc.sample` determines what size SRS sample should be drawn to have a reasonable chance of certification if the election does not have substantial error. It returns an `audit.plan`. `CAST.sample` takes the audit.plan and draws a sample to audit. `CAST.audit` takes audit data (presumably from the audit of the sample drawn in previous step) and analyzes it.

## Usage

 ```1 2 3 4 5 6 7 8 9``` ```CAST.calc.sample(Z, beta = 0.9, stages = 1, t = 3, as.taint=FALSE, small.cut = NULL, strata = NULL, drop = NULL, method = c("select", "binomial", "hypergeometric"), calc.e.max = TRUE, bound.function = maximumMarginBound) CAST.sample(Z, ns, strata = NULL, seed = NULL, print.trail = FALSE, known = "known") CAST.audit(Z, audit = NULL, plan = NULL, ...) test.CAST() ```

## Arguments

 `Z` elec.data object `beta` the confidence level desired `stages` number of auditing stages. Each stage will have the same confidence level, determined by a function of beta. A value of 1 is a single-stage audit. `t` The maximum amount of error, in votes, expected. `as.taint` Boolean value. TRUE means interpret \$t\$ as a taint in \$[0,1]\$ by batch (so the threshold error will be batch-specific). FALSE means interpret \$t\$ as a proportion of the margin or as number of votes (as described above). `small.cut` Cut-off in votes–any precincts with potential error smaller than this value will not be audited and be assumed to be worst case error. `strata` Name of the stratification column of Z. Not needed if audit plan also being passed in case of CAST.sample. NULL means single strata. `drop` Vector of precincts to drop for whatever reasons (such as they are already known). `method` Method of calculation. `calc.e.max` Should the e.max be taken as given, or recalculated? `bound.function` What function should be used to calculate worst-case potential error of precincts. `ns` EITHER an audit.plan or a vector of sample sizes for the strata. Names must correspond ot the names of the strata. If ns is an audit plan, then the strata variable should not be passed as well. `seed` Seed to use–for reproducability. `print.trail` Print out diagnostics. `known` The column of known precincts that should thus not be selected. Similar to "drop", above. `plan` An audit.plan object that the audit was conducted under. `audit` A data.matrix holding the audit data, if the Z object does not have one, or if it is desirable to override it. If both the Z object has an audit object and audit is not null, it will use this parameter and ignore the one in Z. `...` Passed to CAST.calc.sample if plan is null and needs to be regenerated.

Luke W. Miratrix

## References

Philip B. Stark. CAST: Canvass Audits by Sampling and Testing. University of California at Berkeley Department of Statistics, 2009. URL: http://statistics.berkeley.edu/~stark/Preprints/cast09.pdf. Also see http://www.stat.berkeley.edu/~stark/Vote/index.htm for other relevant information.

`elec.data` for a description of the object that holds precinct-level vote records. See `tri.calc.sample` for a PPEB auditing method. See `CAST.calc.opt.cut` for calculating optimal cut-offs to keep needed sample size low. Also see `sim.race`, `do.audit`, `make.sample`, and `make.truth` for doing simulation studies of this method.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15``` ``` ## Make an example cartoon race (from Stark paper) Z = make.cartoon() ## What should we do? samp.info = CAST.calc.sample( Z ) samp.info ## Draw a sample. samp = CAST.sample( Z, samp.info\$ns ) samp ## Analyze what a CAST audit of santa cruz would entail data(santa.cruz) Z = elec.data( santa.cruz, C.names=c("leopold","danner") ) CAST.calc.sample( Z, beta=0.75, stages=1, t=5, small.cut=60) ```