Description Usage Arguments Examples
Fit BIQQ Model for Origins of Electoral Systems example assuming that only k clues are sought
1 2 3 4 5 6 7 | biqq_es_k(k, clue_data, fit = NULL, alpha_prior = rep(1, times = 4),
pi_alpha = rep(1, times = 4), pi_beta = rep(1, times = 4),
q0_alpha = rep(1, times = 4), q0_beta = rep(1, times = 4),
q1_alpha = rep(1, times = 4), q1_beta = rep(1, times = 4),
extract_pars = "abcd", out_fun = function(x) { mean(x$abcd[, 2] -
x$abcd[, 1]) }, iter = 8000, chains = 2, warmup = 1000,
cores = 1)
|
k |
Integer. Number of clues sought |
clue_data |
Data frame. All known XYK cases from which only k cases are randomly drawn for BIQQ model |
fit |
Stan model fit object |
alpha_prior |
Numeric vector of length 4. Dirichlet distribution parameters for proportions of 4 possible types in the population. Defaults to |
pi_alpha |
Numeric vector of length 4. Alpha shape parameters for Beta distribution of probabilities of assignment for 4 possible types in the population. Defaults to |
pi_beta |
Numeric vector of length 4. Beta shape parameters for Beta distribution of probabilities of assignment for 4 possible types in the population. Defaults to |
q0_alpha |
Numeric vector of length 4. Alpha shape parameters for Beta distribution of probabilities of not observing clue given that it was sought and any of four possible types. Defaults to |
q0_beta |
Numeric vector of length 4. Beta shape parameters for Beta distribution of probabilities of not observing clue given that it was sought and any of four possible types. Defaults to |
q1_alpha |
Numeric vector of length 4. Alpha shape parameters for Beta distribution of probabilities of observing clue given that it was sought and any of four possible types. Defaults to |
q1_beta |
Numeric vector of length 4. Beta shape parameters for Beta distribution of probabilities of observing clue given that it was sought and any of four possible types. Defaults to |
extract_pars |
Character vector. Names of posterior parameters to extract as taken by |
out_fun |
Function. The function, which takes posterior samples extracted using |
iter |
Integer. Total number of iterations in each chain. Defaults to 20000, |
chains |
Integer. Number of MC chains. Defaults to 2 |
warmup |
Integer. Number of warm-up iterations in each chain. Defaults to 5000 |
cores |
Integer. Number of cores to use for parallel computation. Defaults to 1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | ## Not run:
library(biqq)
es_fit <-
init_biqq(model_code = stan_es,
data = data_es_init)
sims <- 10 # Number of simulations
N <- nrow(data_es) # Number of cases
# Generate hyperparameters for Stan
q0_alpha_beta <- mapply(m = c(q.a0 = 0.1, # Assumptions on mean of q0's
q.b0 = 0.1,
q.c0 = 0.05,
q.d0 = 0.3),
sd = rep(.01, times = 4),
FUN = beta_prior)
q1_alpha_beta <- mapply(m = c(q.a1 = 0.95, # Assumptions on mean of q1's
q.b1 = 0.9,
q.c1 = 0.475,
q.d1 = 0.5),
sd = rep(.01, times = 4),
FUN = beta_prior)
# Rstan setup options
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
# Run the analysis
betas <-
parallel::mclapply(X = rep(0:N, each = sims),
FUN = biqq::biqq_es_k,
fit = es_fit,
clue_data = data_es,
q0_alpha = q0_alpha_beta["alpha",],
q0_beta = q0_alpha_beta["beta",],
q1_alpha = q1_alpha_beta["alpha",],
q1_beta = q1_alpha_beta["beta",],
chains = 2,
cores = 1,
extract_pars = "abcd",
out_fun = function(x) { mean(x$abcd[,2] - x$abcd[,1]) })
betas <- matrix(unlist(betas), ncol = sims, byrow = TRUE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.