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

Description Usage Arguments Value See Also Examples

View source: R/mrp_party_estimation.R

Description

The function fits a model using the jags function 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(data, party, stratum, frac = 1, n_iter = 1000,
  n_burnin = 500, n_chains = 2, seed = NA, seed_jags = 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, n_burnin, n_chains

Number of iterations, burnin size and chains. to be used in jags.

seed

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

seed_jags

Seed for the call jags.

model_string

String indicating the model to be used, if NULL defaults to "model_bern_t", also available "model_t".

Value

A list with the object fitted using R2jags::jags and the vector of simulated counts per candidate.

See Also

mrp_estimation

Examples

1
2
3
4
5
# predict number of votes for pan_na using 6% of the sample
mrp_gto_pan <- mrp_party_estimation(gto_2012, pan_na,
    stratum = distrito_loc_17, frac = 0.06, n_iter = 200, n_burnin = 100,
    n_chains = 2, seed = 19291)
mrp_gto_pan$fit

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