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 |
object2 |
A second |
X1 |
A |
W1 |
A |
X2 |
A second |
W2 |
A second |
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 |
alternative |
Character string specifying the type of alternative hypothesis to test. Must be one of |
... |
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.
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.
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)