ratio_estimation: Ratio estimator to compute proportion of votes allocated to...

Description Usage Arguments Details Value Examples

View source: R/ratio_estimation.R

Description

Compute ratio estimator for each candidate, standard errors are computed with bootstrap resampling within each stratum and computing the standard error of the samples (no corrections).

Usage

1
2
ratio_estimation(data, stratum, data_stratum, n_stratum, ...,
  std_errors = TRUE, B = 50, seed = NA)

Arguments

data

data.frame

stratum

Unquoted variable indicating the stratum for each polling station.

data_stratum

Data frame with stratum variable (named exactly as in data) and number of polling stations per strata.

n_stratum

Unquoted variable indicating the number of polling stations in each stratum.

...

Unquoted variables indicating the number of votes in each polling station for each candidate.

std_errors

Logical value indicating whether to compute standard errors (using bootstrap), defaults to TRUE.

B

Number of bootstrap replicates used to compute standard errors, defaults to 50.

seed

integer value used to set the state of the random number generator (optional). It will only be used when computing standard errors.

Details

The bootstrap approach we use is not suitable when the number of sampled polling stations within a strata is small. Coverage might improve if confidence intervals are constructed with BCas or t-tables.

Value

A data.frame including the ratio estimation for each party and standard errors (if requested).

Examples

1
2
3
4
5
6
7
8
9
# count number of polling stations per stratum
library(dplyr)
gto_stratum_sizes <- gto_2012 %>%
    dplyr::group_by(distrito_loc_17) %>%
    dplyr::summarise(n_stratum = n())
# stratified random sample (size 6%), sample size proportional to strata size
gto_sample <- select_sample_prop(gto_2012, stratum = distrito_loc_17, 0.06)
ratio_estimation(gto_sample, stratum = distrito_loc_17, 
  data_stratum = gto_stratum_sizes, n_stratum = n_stratum, pri_pvem:otros)

tereom/quickcountmx documentation built on Dec. 2, 2019, 9:58 p.m.