mrp_party_estimation_stan: Postratified estimation for the number of votes for a given...

Description Usage Arguments Value Examples

View source: R/mrp_party_estimation_stan.R

Description

The function fits a model using the rstan package and predicts number of votes for a given candidate in unobserved polling stations. Optionally the model can be fit with a stratified random sample of the data, and predict for the population.

Usage

1
2
3
mrp_party_estimation_stan(data, party, stratum, frac = 1, n_iter = 300,
  warmup = 150, n_chains = 2, seed = NA, model_string = NULL,
  set_strata_na = integer(0))

Arguments

data

A data.frame with variables: ln_total, region, distrito_loc_17, tamano_md, tamano_gd, casilla_ex and the column with number of votes for the party.

party

Unquoted variable indicating the column from the data.frame to be modeled.

stratum

If sampling the data, unquoted variable indicating the column from the data.frame to be used as strata. The strata will also be used in the hierarchical structure of the model.

frac

If sampling the data, numeric value indicating the fraction of the data to sample, the sample is selected using stratified sampling with probability proportional to size.

n_iter, warmup, n_chains

Number of iterations, number of warmup iterations and number of chains. to be used in sampling.

seed

Integer value used to set the state of the random number generator.

model_string

String indicating the model to be used, defaults to "neg_binomial".

set_strata_na

Option to exclude strata when fitting the model, used for model evaluation and calibration.

Value

A list containing fit object and vector the simulated counts for the candidate.

Examples

1
2
3
4
mrp_party_pri <- mrp_party_estimation_stan(nal_2012, pri_pvem, frac = 0.02,
    stratum = estrato, n_iter = 300, warmup = 150,
    n_chains = 2, seed = 19291)
quantile(mrp_party$y)

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