eforensics: Election Forensics Finite Mixture Model

Description Usage Arguments Value Examples

Description

This function estimates a finite mixture model of election fraud

Usage

1
2
3
4
5
eforensics(formula1, formula2, formula3 = NULL, formula4 = NULL,
  formula5 = NULL, formula6 = NULL, data, elegible.voters = NULL,
  weights = NULL, mcmc, model, parameters = "all",
  na.action = "exclude", get.dic = 1000, parComp = T, autoConv = T,
  max.auto = 10)

Arguments

formula1

an object of the class formula as used in lm. The dependent variable of this formula must the number (counts) or proportion of votes for the party or candidate that won the election. If counts are used, the model must be from the binomial family (see model parameter below). If proportions are provided, the model must be from the normal family (see model parameter below)

formula2

an object of the class formula as used in lm. The dependent variable of this formula must the number (counts) or proportion of abstention. The type (count or proportion) must be the same as the independent variable in formula1

formula3

See description below

formula4

See description below

formula5

See description below

formula6

See description below

Formulas 3 to 6

There are four other possible formulas to use: formula3, formula4, formula5, formula6

formula3

an object of the class formula as used in lm. The left-hand side (LHS) of the formula must be mu.iota.m (see example). The mu.iota.m is the probability of incremental fraud by manufacturing votes and it is a latent variable in the model. By specifying the LHS with that variable, the functional automatically identifies that formula as formula3. Default is NULL and it means that probability is not affected by election unit (ballot box, polling place, etc) covariate

formula4

an object of the class formula as used in lm. The left-hand side (LHS) of the formula must be mu.iota.s (see example). The mu.iota.s is the probability of incremental fraud by stealing votes from the opposition and it is a latent variable in the model. By specifying the LHS with that variable, the functional automatically identifies that formula as formula4. Default is NULL and it means that probability is not affected by election unit (ballot box, polling place, etc) covariate

formula5

an object of the class formula as used in lm. The left-hand side (LHS) of the formula must be mu.chi.m (see example). The mu.chi.m is the probability of extreme fraud by manufacturing votes and it is a latent variable in the model. By specifying the LHS with that variable, the functional automatically identifies that formula as formula5. Default is NULL and it means that probability is not affected by election unit (ballot box, polling place, etc) covariate

formula6

an object of the class formula as used in lm. The left-hand side (LHS) of the formula must be mu.chi.s (see example). The mu.chi.s is the probability of extreme fraud by stealing votes from the opposition and it is a latent variable in the model. By specifying the LHS with that variable, the functional automatically identifies that formula as formula6. Default is NULL and it means that probability is not affected by election unit (ballot box, polling place, etc) covariate

data

a dara.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 elegible voters (see parameter elegible.voters)

elegible.voters

string with the name of the variable in the data that contains the number of elegible voters. Default is NULL, but it is required if the independent variables (voters for the winner and abstention) are counts

weights

(not used)

mcmc

a list containing n.iter, which is the number of iterations for the MCMC, burn.in for the burn-in period of the MCMC chain, n.adapt indicating the number of adaptative steps before the estimation (see rjags)

model

a string with the model ID to use in the estimation. Run ef_models() to see the list and descriptions of the models available.

parameters

a string vector with the names of the parameters to monitor. When NULL, it will monitor all the parameters, except the Z's. When parameters='all' (default), it will monitor all parameters, including Z, which is necessary to classify the observations as fraudulent cases or not.

na.action

(not used)

get.dic

logical. If get.dic is FALSE, no DIC is calculated. If get.dic is an integer greater than 0, run model get.dic iterations to get the DIC. If parComp = TRUE, then no DIC is calculated.

parComp

Logical. If parComp = TRUE, then chains are computed in parallel using the runjags architecture. This opens n.chains instances of JAGS. In practice, a max of 4 unique chains can be run due to the way in which JAGS generates initial values.

autoConv

Logical. If parComp = TRUE and autoConv = TRUE, the chains are run until convergence criteria are met. Currently, chains are run for a single period equal to burn.in iterations and monitored for n.iter iterations. If PSRF on the three values of pi are lower than 1.05, then the chain is stopped and the chain is run for n.iter more iterations monitoring all values specified by parameters. If the PSRF for any value is higher than 1.05, then the chain is run for burn.in + n.iter more iterations and the PSRF is again checked. This is repeated, at most, max.auto times. If PSRF is not met by max.auto attempts, a warning message is printed and the chains are run n.iter more times with all parameters monitored.

max.auto

Integer. Number of subsequent tries to achieve a PSRF of 1.05 on pi. After max.auto failures, a warning is thrown and the chain is run n.iter more times monitoring all specified parameters.

Value

The function returns a nested list. The first element of the list is a mcmc object with the samples from the posterior distribution. The second element of the list is a list of summaries (HPD, Mean, etc)

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
model    = 'bl'

## simulate data
## -------------
sim_data = ef_simulateData(n=700, nCov=1, model=model)
data     = sim_data$data

## mcmc parameters
## ---------------
mcmc    = list(burn.in=1, n.adapt=10, n.iter=100, n.chains=2)

## samples
## -------
## help(eforensics)
devtools::document(pkg_folder)
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,
    elegible.voters="N",
    model=model, mcmc=mcmc, get.dic=0)

summary(samples)
summary(samples, join.chains=T)

DiogoFerrari/eforensics documentation built on Aug. 31, 2019, 3:44 p.m.