ei_est_gen: Iterative EI Estimation

Description Usage Arguments Value Note Author(s) References Examples

Description

Iteratively fits EI models for candidates and racial/ethnic groups

Usage

1
2
ei_est_gen(cand_vector, race_group, total, rho = 10, data, table_names, 
sample = 1000, tomog = F, density_plot = F, beta_yes=F,...)

Arguments

cand_vector

Character vector of candidate names, taken from the dataset

race_group

Character vector of formula, e.g., "~ pct_latino"

total

Character vector (e.g., "totvote") of total variable name from data, variable in data is numeric

rho

Rho parameter for ei() estimate, defaults to 10, numeric

data

data.frame() object containing the data

table_names

Character vector of table names with same length as race_group. Used for formatting output. If only one racial group, must provide "Pct. Other" as second element of vector

sample

Number of samples used for EI calculation, default = 1000

tomog

Logical to display tomography plot. If true will will save pdf plot to working directory. Default is FALSE

density_plot

Logical to display density plot of betab and betaw. If true will save pdf plot to working directory. Default is FALSE

beta_yes

Logical to export betas (b, w) in list object in addition to table of results. Default is FALSE

...

Arguments passed onto ei() function

Value

Data frame/table object containing EI individually estimated results. If beta_yes=T, two list items, first the data frame table of results, second dataframe of betas themselves.

Note

If this results in an error, "Error in .subset2(x, i, exact = exact) : invalid subscript type 'list'", just rerun the algorithm again.

Author(s)

Loren Collingwood <loren.collingwood@ucr.edu>

References

eiPack. Gary King (1997). A Solution to the Ecological Inference Problem. Princeton: Princeton University Press.

Examples

 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
# TOY DATA EXAMPLE
canda <- c(.1, .09, .85, .9, .92)
candb <- 1-canda
white <- c(.8, .9, .10, .08, .11)
black <- 1 - white
total <- c(30,80, 70, 20, 29)
toy <- data.frame(canda, candb, white, black, total)

# CREATE VECTORS
cands <- c("canda")
race_group <- c("~ black") # only use one group for example
table_names <- c("EI: PCT Black", "EI: PCT White")

# RUN ei_est_gen()
# KEEP DATA TO JUST ONE ROW FOR EXAMPLE (time) ONLY!
ei_est_gen(cands, race_group, "total",
            data = toy[c(1,3,5),], table_names = table_names, sample=100)


# WARNING -- May take a little while to execute
# Load Package Data
data(corona)
# Create Character Vectors
cands <- c("pct_husted","pct_spiegel","pct_ruth","pct_button","pct_montanez","pct_fox")
race_group3 <- c("~ pct_hisp", "~ pct_asian", "~ pct_white")
table_names <- c("EI: Pct Hisp", "EI: Pct Asian", "EI: Pct White")

# Run ei_est_gen function
results <- ei_est_gen(cand_vector=cands, race_group = race_group3,
			total = "totvote", data = corona, table_names = table_names)

results
# Run ei_est_gen function; Exporting betas into data frame
results_w_betas <- ei_est_gen(cand_vector=cands, race_group = race_group3,
			total = "totvote", data = corona, table_names = table_names, beta_yes=T)

res1 <- results_w_betas[[1]]# table of mean estimates
res1
res2 <- results_w_betas[[2]]# betas of estimates for each precinct

lorenc5/eiCompare documentation built on June 5, 2019, 5:18 p.m.