Learn R Programming

eiCompare (version 3.0.4)

bayes_table_make: EI:RxC Bayes Table Make

Description

Creates data.frame() table from eiPack RxC output, in the same format as ei_est_gen.

Usage

bayes_table_make(ei_bayes_object, cand_vector, table_names)

Value

Data frame object in similar vein to ei_est_gen

Arguments

ei_bayes_object

Output from eiPack ei.reg.bayes() function

cand_vector

Character vector of candidate name variables, usually "pct_johns" or something

table_names

Character vector of column names, e.g., c("RxC: Pct Hisp", "RxC: Pct Asian")

Author

Loren Collingwood <loren.collingwood@ucr.edu>

References

O. Lau, R. T. Moore, and M. Kellermann. eipack: RxC ecological inference and higher-dimension data management. New Functions for Multivariate Analysis, 18(1):43, 2006.

Examples

Run this code

# 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