Description Usage Arguments Value References Examples
This function estimates a finite mixture model of election fraud
1 2 3 4 5 6 7 | eforensics(formula1, formula2, formula3 = NULL, formula4 = NULL,
formula5 = NULL, formula6 = NULL, data, eligible.voters = NULL,
weights = NULL, mcmc, model = "qbl", parameters = "all",
na.action = "exclude", get.dic = 1000, parComp = TRUE,
autoConv = TRUE, max.auto = 10, mcmc.conv.diagnostic = "MCMCSE",
mcmc.conv.parameters = "pi", mcmcse.conv.precision = 0.05,
mcmcse.combine = FALSE)
|
formula1 |
an object of the class |
formula2 |
an object of the class |
formula3 |
See description below |
formula4 |
See description below |
formula5 |
See description below |
formula6 |
See description below
|
data |
a data.frame with the independent variables (voters for the winner and abstention) and the covariates. If the independent variables are counts, the it is necessary to provide the total number of eligible voters (see parameter |
eligible.voters |
string with the name of the variable in the data that contains the number of eligible voters. Default is |
weights |
Deprecated. |
mcmc |
a list containing |
model |
a string with the model ID to use in the estimation. There are three current choices: |
parameters |
a string vector with the names of the parameters to monitor. When |
na.action |
Deprecated. |
get.dic |
Deprecated. |
parComp |
Logical. If |
autoConv |
Logical. If |
max.auto |
Integer. Number of subsequent tries to achieve the convergence conditions outlined by |
mcmc.conv.diagnostic |
a string with the method to use to evaluate convergence. Currenctly, |
mcmc.conv.parameters |
string vector with the name of the parameters to check for convergence using the MCMC standard error. Default is |
mcmcse.conv.precision |
numeric, the value of the precision criterion to evaluate convergence using the MCMC standard error. The MCMC std. error of all parameters included in |
mcmcse.combine |
boolean, if |
The function returns a nested list of class eforensics
with length equal to the number of chains. Each sublist contains up to three named objects:
A mcmc
object that contains the posterior draws for all monitored parameters except for the individual fraud classifications.
A vector that contains the posterior modal classification for each observation. 1 corresponds to no fraud, 2 corresponds to incremental fraud, and 3 corresponds to extreme fraud.
A matrix with three columns that contains the posterior probability of belonging to each class for each observation.
If model = "qbl"
or model = "bl"
, the proportion of frauds estimated at each observation is returned. These values can be accessed for object foo
using attr(foo,"frauds")
. This attribute is a two element list that contains the estimated proportion of votes that are Stolen and Manufactured. Posterior means, HPD intervals, and posterior quantiles are returned for each observation in the data set. These quantities are automatically aggregated over all chains.
Flegal, J. M., Haran, M., & Jones, G. L., Markov chain monte carlo: can we trust the third significant figure?, Statistical Science, 23(2), 250–260 (2008). Brooks, S. P., & Gelman, A., General methods for monitoring convergence of iterative simulations, Journal of computational and graphical statistics, 7(4), 434–455 (1998).
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | set.seed(12345)
library(eforensics)
model = 'qbl'
## simulate data
## -------------
set.seed(12345)
sim_data = ef_simulateData(n=250, nCov=1, nCov.fraud=1,
model="bbl", overdispersion = 100, pi = c(.95,.04,.01))
data = sim_data$data
## mcmc parameters
## ---------------
mcmc = list(burn.in=1000, n.adapt=1000, n.iter=1000, n.chains=2)
## samples
## -------
## help(eforensics)
samples = eforensics(
w ~ x1.w ,
a ~ x1.a,
mu.iota.m ~ x1.iota.m,
mu.iota.s ~ x1.iota.s,
mu.chi.m ~ x1.chi.m,
mu.chi.s ~ x1.chi.s,
data=data,
eligible.voters="N",
model="qbl",
mcmc=mcmc,
parameters = "all",
parComp = TRUE,
autoConv = TRUE,
max.auto = 10,
mcmc.conv.diagnostic = "MCMCSE",
mcmc.conv.parameters = c("pi"),
mcmcse.conv.precision = .05,
mcmcse.combine = FALSE
)
#Summaries for each of the monitored parameters
#Look at each chain separately
summary(samples)
#Combine the chains
summary(samples, join.chains=T)
#Look at the estimated fraud proportions for each observation
attr(samples,"frauds")
#Look at Manufactured and Stolen separately
attr(samples,"frauds")$Manufactured
attr(samples,"frauds")$Stolen
#How accurate is the classification?
#Get the true categories
true_z <- sim_data$latent$z
#What is the modal estimate for the class?
num_z <- (samples[[1]]$piZi*1000) + (samples[[2]]$piZi*1000)
max_z <- apply(num_z,1,which.max)
#How accurate is the modal classification?
table(true_z,max_z)
#How accurately do we uncover the proportion of frauds for each observation?
#Manufactured
true_man <- ((true_z == 1)*0) + ((true_z == 2)*sim_data$latent$iota.m) +
((true_z == 3)*sim_data$latent$chi.m)
#What is the posterior mean proportion of manufactured votes
pred_man <- attr(samples,"frauds")$Manufactured[,1]
#Are they close?
plot(true_man, pred_man, xlab = "True Proportion Manufactured Votes",
ylab = "Estimated Proportion Manufactured Votes")
#Stolen
true_stolen <- ((true_z == 1)*0) + ((true_z == 2)*sim_data$latent$iota.s) +
((true_z == 3)*sim_data$latent$chi.s)
#What is the posterior mean proportion of manufactured votes
pred_stolen <- attr(samples,"frauds")$Stolen[,1]
#Are they close?
plot(true_stolen, pred_stolen, xlab = "True Proportion Stolen Votes",
ylab = "Estimated Proportion Stolen Votes")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.