waldtest {fastei}R Documentation

Performs a matrix-wise Wald test for two eim objects

Description

This function compares two eim objects (or sets of matrices that can be converted to such objects) by computing a Wald test on each component of their estimated probability matrices. The Wald test is applied using bootstrap-derived standard deviations, and the result is a matrix of p-values corresponding to each group-candidate combination.

Usage

waldtest(
  object1 = NULL,
  object2 = NULL,
  X1 = NULL,
  W1 = NULL,
  X2 = NULL,
  W2 = NULL,
  nboot = 100,
  seed = NULL,
  alternative = "two.sided",
  ...
)

Arguments

object1

An eim object, as returned by eim.

object2

A second eim object to compare with object.

X1

A ⁠(b x c)⁠ matrix representing candidate votes per ballot box.

W1

A ⁠(b x g)⁠ matrix representing group votes per ballot box.

X2

A second ⁠(b x c)⁠ matrix to compare with X.

W2

A second ⁠(b x g)⁠ matrix to compare with W.

nboot

Integer specifying how many times to run the EM algorithm per object.

seed

An optional integer indicating the random seed for the randomized algorithms. This argument is only applicable if initial_prob = "random" or method is either "mcmc" or "mvn_cdf". Aditionally, it sets the random draws of the ballot boxes.

alternative

Character string specifying the type of alternative hypothesis to test. Must be one of "two.sided" (default), "greater", or "less". If "two.sided", the test checks for any difference in estimated probabilities. If "greater", it tests whether the first object has systematically higher probabilities than the second. If "less", it tests whether the first has systematically lower probabilities.

...

Additional arguments passed to bootstrap and run_em.

Details

It uses Wald test to analyze if there is a significant difference between the estimated probabilities between a treatment and a control set. The test is performed independently for each component of the probability matrix.

The user must provide either of the following (but not both):

The Wald test is computed using the formula:

z_{ij} = \frac{p_{1,ij}-p_{2,ij}}{\sqrt{s_{1,ij}^2+s_{2,ij}^2}}

In this expression, s_{1,ij}^2 and s_{2,ij}^2 represent the bootstrap sample variances for the treatment and control sets, respectively, while p_{1,ij} and p_{2,ij} are the corresponding estimated probability matrices obtained via the EM algorithm.

Value

A list with components:

Each entry in the pvals matrix is the p-value from Wald test between the corresponding entries of the two estimated probability matrices.

Examples

sim1 <- simulate_election(num_ballots = 100, num_candidates = 3, num_groups = 5, seed = 123)
sim2 <- simulate_election(num_ballots = 100, num_candidates = 3, num_groups = 5, seed = 124)

result <- waldtest(sim1, sim2, nboot = 100)

# Check which entries are significantly different
which(result$pvals < 0.05, arr.ind = TRUE)


[Package fastei version 0.0.0.7 Index]