# Toy data example
canda <- runif(5)
candb <- 1 - canda
white <- runif(5)
black <- 1 - white
total <- round(runif(5, min = 20, max = 40), 0)
toy <- data.frame(canda, candb, white, black, total)
cands <- c("canda", "candb")
table_names <- c("RxC: PCT Black", "RxC PCT White")
# generate formula for passage to ei.reg.bayes() function
form <- formula(cbind(canda, candb) ~ cbind(black, white))
# run bayesian model
suppressWarnings(
ei_bayes <- ei.reg.bayes(form, data = toy, sample = 100, truncate = TRUE)
)
# table creation, using function bayes_table_make
ei_bayes_res <- bayes_table_make(ei_bayes,
cand_vector = cands,
table_names = table_names
)
ei_bayes_res
# Example 2: Corona data
# \donttest{
data(corona)
# create character vectors
cands <- c(
"pct_husted",
"pct_spiegel",
"pct_ruth",
"pct_button",
"pct_montanez",
"pct_fox"
)
table_names <- c("RxC: Pct Hisp", "RxC: Pct Asian", "RxC: Pct White")
# generate formula for passage to ei.reg.bayes() function
form <- formula(cbind(
pct_husted, pct_spiegel, pct_ruth,
pct_button, pct_montanez, pct_fox
)
~ cbind(pct_hisp, pct_asian, pct_white))
# run bayesian model
suppressWarnings(
ei_bayes <- ei.reg.bayes(
form,
data = corona,
sample = 10000,
truncate = TRUE
)
)
# table creation using bayes_table_make
ei_bayes_res <- bayes_table_make(ei_bayes,
cand_vector = cands,
table_names = table_names
)
ei_bayes_res
# }
Run the code above in your browser using DataLab