I have the following problem:
I have $X_1 ... X_n$ ~ Bernoulli(p) independent. I also have the following test hypothesis: $H_0: p = p_0$ and $H_1: p > p_0$. I define my test as follows:
$T:$ I refuse $H_0$ in favour of $P_1$ if the number of successes is very high.
Now suppose $p_0 = 0.6$ and $n = 20$, we find that we have 18 successes.
I want to find the p-value of the test.
Now this is what I have done:
$p-value = \mathbb{P}(\sum x_i \geq 18)$ = 0.0005240494 However confronting it with the command:
binom.test(18,20,p=.6,alternative=greater)
It is not right (by a factor of 10). My problem is that I am not able to correctly asses what the "number of succession is very high". How do I work around this?
Letting $K=\sum_i \mathbb{I}(X_i = 1)$ be the number of successes, you have $K \sim \text{Bin}(n,p)$. Thus, your p-value is:
$$\begin{equation} \begin{aligned} p \equiv p(k) &\equiv \mathbb{P}( K \geqslant k | H_0) \\[6pt] &= \mathbb{P}( K \geqslant k | K \sim \text{Bin}(n,p_0)) \\[6pt] &= \sum_{r=k}^n \text{Bin}(r|n,p_0). \\[6pt] \end{aligned} \end{equation}$$
With $p_0=0.6$, $n=20$ and $k=18$ you get the p-value:
$$p = \sum_{r=18}^{20} \text{Bin}(r|20, 0.6) = 0.003611472.$$