Description Usage Arguments Details Value Examples
View source: R/ratio_estimation.R
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).
1 2 | ratio_estimation(data, stratum, data_stratum, n_stratum, ...,
std_errors = TRUE, B = 50, seed = NA)
|
data |
|
stratum |
Unquoted variable indicating the stratum for each polling station. |
data_stratum |
Data frame with stratum variable (named exactly as in
|
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. |
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.
A data.frame
including the ratio estimation for each party
and standard errors (if requested).
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.