# Caculate Type II error for Binomial distribution

Basically this is a question if I got the general idea behind the Type II Error right. I’ll set up a little reproducible example:

Given $p_0=0.6$ with an $\alpha$-level of $\alpha=0.1$. As Binomial tests are conservative with respect to $\alpha$ we first calculate (using R) the actual $\alpha$ used:

## Calculating the actual $\alpha$-level:

$P(X< c_1)= 0.0123$

for(i in 1:10){ # lower bound
if(sum(dbinom(0:10, 10, 0.6)[1:(i+1)])<0.05){
c <- sum(dbinom(0:10, 10, 0.6)[1:(i+1)])
}
else break
print(c)
}


$P(X>c_2)=0.0464$

for(i in 10:1){ # upper bound
if(sum(dbinom(0:10, 10, 0.6)[11:i])<0.05){
d <- sum(dbinom(0:10, 10, 0.6)[11:i])
}
else break
print(d)
}


Hence we have an actual $\alpha$ of

$\alpha=P(X<c_1)+P(X>c_2)=0.0123+0.464=0.587$.

## Calculating the critical values $c_1$ and $c_2$:

The critical values $c_1$ and $c_2$ are:

$c_1=3$

qbinom(0.0123, 10, 0.5)


$c_1=8$

qbinom(1-0.0464, 10, 0.5)


## Calculating Type II Error for $p_1=0.5$ and $p_2=0.7$:

$\beta_{0.5}=0.817$

pbinom(8, 10, 0.5) - pbinom(3, 10, 0.5)


$\beta_{0.7}=0.84$

pbinom(8, 10, 0.7) - pbinom(3, 10, 0.7)


## Logic behind this:

The Type II Error $\beta$ with respect to a specific value of a parameter $\vartheta\in H_1$ is defined as $\beta_\vartheta = P(c_1\le X\le c_2|\vartheta\in H_1)$. The critical constants $c_1$ and $c_2$ are calculated under $H_0$ but the probability of $X$ being greater than or equal $c_1$ and less than or equal to $c_2$ is calculated under $H_1$. Is this correct?

Yes, the solutions are correct. Simply put, the probability of not rejecting the null $p_0$ is when $c_1<X<c_2$. Now Type II error happens when we don't reject the null and the alternative is true. For alternative $p_i$, this is the evaluation of $P(c_1 < X < c_2 | p=p_i)$, which is what you have done.