# Hypothesis testing in elections

The following is a problem I am working on for my stats class regarding hypothesis testing:

I have a random sample $$X_1,...,X_n$$ of voters who either voted for Candidate A ($$X_1=1$$) or for Candidate B ($$X_i=0$$), with probability of voting for A denoted as $$p$$.

I want to test the hypothesis that A will not lose the election: $$H_0:p\geq 0.5$$ vs. $$H_1:p<0.5$$. I set the null parameter space $$\Theta_0=[0.5,1]$$ and the power test to $$\beta_\psi(p)=\mathbb{P}_p(T\leq c)=\sum_{k=0}^c{n\choose k}p^k(1-p)^{n-k}$$, observing that for $$c\in\{0,...,n-1\}$$, the power test is strictly decreasing in $$p$$ and that size of $$\psi$$ is thus $$\beta_\psi(0.5)$$.

Now, I want to find $$c$$ so that the power test is at level 5% with the largest possible power, at sample size $$n=100$$. Is it correct for me to assume that I must find the largest $$c$$ such that $$\beta_\psi(0.5)\leq 0.05$$? I do intuit that this is because of the null hypothesis $$H_0:p\geq 0.5$$ and $$c$$ being in the "same direction" as $$p$$ (number of A voters in the sample is used to "estimate" the probability of voting A, which we want to increase to the minimal degree to satisfy the level-$$\alpha$$ test; the "increasing" being to control type I error and the "to the minimal degree" being to minimize type II error).

Could somebody please verify this? If there are any mistakes or a more rigorous explanation in what I said, please let me know.

Assume polling is random, that subjects of the poll are registered voters, will vote, have decided their preference, tell the truth, and will not change their preference before the election.

Let $$Y$$ be the number out of $$n = 100$$ who will vote for A. Under $$H_0: p = 0.5,$$ we have $$Y \sim\mathsf{Binom}(n=100, p=.5).$$ We will reject $$H_0$$ against $$H_a: p < .5$$ for small observed $$Y.$$ To test at the 5% level, we need to find the critical value $$c = 41$$ such that $$\alpha = P(Y \le c\,|\,p=.5) < 0.05,$$ but as near to $$0.05$$ as possible; with $$\alpha = 0.443.$$ [You are correct that this $$\alpha$$ and $$c$$ give the best power.]

Computations in R:

qbinom(.05, 100, .5)
[1] 42
pbinom(42, 100, .5)
[1] 0.06660531
pbinom(41, 100, .5)
[1] 0.04431304


I do not understand your notation for the power of the test. So I will define and use my own.

The power of a test at level $$\alpha = 0.0443$$ against alternative $$p_a < .5$$ is $$\pi(p_a) = P(Y \le 41 \,|\, p_a).$$ We can plot a power curve for various alternative values $$p_1,$$ as follows:

p.a = seq(0, .5, by=.01)
pwr = pbinom(41, 100, p.a)
plot(p.a, pwr, type="l", ylim=c(0,1), lwd=2, main="Power Curve")
abline(h = c(.05, 1), col="green2")
abline(v = c(0,.5), col="green2")


It seems that we are almost sure to reject $$H_0$$ if the true proportion in favor of A is less than about $$p_a = 0.27.$$

However, if only 40% favor A, we have only about a $$60\%$$ chance of detecting that A will lose the election. In serious election polling it takes a poll with about $$n = 2500$$ subjects to be 95% sure that the margin of sampling error is smaller than $$\pm 2\%.$$

I used exact binomial probabilities from R throughout. However, with $$n = 100,$$ you could get reasonably precise values for the probabilities by using normal approximations to binomial distributions for $$p > 0.05.$$

Below is output from the 'power and sample size' procedure using a recent release of Minitab statistical software. (The dotted power curve is for $$n=2500.)$$

Power and Sample Size
Test for One Proportion

Testing p = 0.5 (versus < 0.5)
α = 0.05

Sample
Comparison p    Size    Power
0.1     100  1.00000
0.1    2500  1.00000
0.2     100  1.00000
0.2    2500  1.00000
0.3     100  0.99491
0.3    2500  1.00000
0.4     100  0.64150
0.4    2500  1.00000


• Thanks a lot! This clears up both my question on finding c as well as my confusion regarding maximizing the power. Plus, the plots are a big help. Mar 23 at 16:46