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 withobject
.- 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 withX
.- W2
A second
(b x g)
matrix to compare withW
.- 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"
ormethod
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.- ...
Value
A list with components:
pvals
: a numeric matrix of p-values with the same dimensions as the estimated probability matrices (pvals
) from the input objects.statistic
: a numeric matrix of z-statistics with the same dimensions as the estimated probability matrices (pvals
).eim1
andeim2
: the originaleim
objects used for comparison.
Each entry in the pvals matrix is the p-value from Wald test between the corresponding entries of the two estimated probability matrices.
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):
Two
eim
objects viaobject1
andobject2
, orFour matrices:
X1
,W1
,X2
, andW2
, which will be converted intoeim
objects internally.
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.
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)
#> row col
#> [1,] 1 1
#> [2,] 2 1
#> [3,] 3 1
#> [4,] 4 1
#> [5,] 5 1
#> [6,] 1 2
#> [7,] 2 2
#> [8,] 3 2
#> [9,] 4 2
#> [10,] 3 3
#> [11,] 4 3
#> [12,] 5 3