The Problem
Example #485: Let us test the null hypothesis that the success rate in the population is 36%. In symbols, this is:
H0 : p = 0.36
HA : p ≠ 0.36
To test this hypothesis, we collect data. The data are a series of “Success” and “Failure” values. In this sample, the data are
“Failure”, “Success”, “Success”, “Failure”, “Success”, “Failure”, “Failure”, “Failure”, “Failure”, “Failure”, “Success”, “Failure”, “Success”, “Success”, “Failure”, “Failure”, “Failure”, “Failure”, “Failure”, “Failure”, “Success”, “Success”, “Failure”, “Failure”, “Failure”, “Failure”, “Failure”, “Success”, “Failure”
With this information, calculate the test statistic corresponding to the null hypothesis. Use the Wald version of the test statistic.
Information given:
To summarize the above, the values of import are:
Summary statistics from the problem
\( p_0 \)
| = |
0.36 |
\( x \)
| = |
9 |
\( n \)
| = |
29 |
\( \hat{p} \)
| = |
0.3103 |
Calculate these values yourself then hover your mouse over the grey spaces to see if you calculated them correctly.
Assistance
Hide Solution
$$ \begin{align}
z &= \frac{ \hat{p} - p_0}{\sqrt{ \frac{ \hat{p} \left(1 - \hat{p}\right) }{n}}} \\[3em]
&= \frac{ 0.3103 - 0.36}{\sqrt{ \frac{ 0.3103\ \left(1 - 0.3103 \right) }{29}}} \\[1em]
&= \frac{ -0.0497}{\sqrt{ \frac{ 0.3103\ \left( 0.6897\right) }{29}}} \\[1em]
&= \frac{ -0.0497}{\sqrt{ \frac{ 0.214031 }{29}}} \\[1em]
&= \frac{ -0.0497}{\sqrt{ 0.00738}} \\[1em]
&= \frac{ -0.0497}{ 0.085909} \\[1em]
&= -0.578 \\[1em]
\end{align}
$$
And so, the test statistic is z = -0.578. To use this, you would compare it to the ciritical value from the z-table.
For instance, let us specify α = 0.05. This is a two-tailed test, because the alternative hypothesis uses ≠. Because of these two facts, the two critical values are -1.96 and +1.96.
Since the test statistic is between the two critical values, it is not in the rejection region. Thus, we fail to reject the null hypothesis in favor of the alternative.
Hide the R Code
The Wald test is pedagogically simple to understand. That is why it is used in introductory textbooks. It is actually based on the Normal approximation to the Binomial distribution. There are several improvements to the test. For these reasons, R does not have a built-in function to perform the Wald test for proportions. The following code echoes the above calculations to provide the Wald test statistic.
Copy and paste the following code into your R script window, then run it from there.
sample = c("Failure", "Success", "Success", "Failure", "Success", "Failure", "Failure", "Failure", "Failure", "Failure", "Success", "Failure", "Success", "Success", "Failure", "Failure", "Failure", "Failure", "Failure", "Failure", "Success", "Success", "Failure", "Failure", "Failure", "Failure", "Failure", "Success", "Failure")
x = sum(sample=="Success")
n = length(sample)
phat = x/n
se2 = phat*(1-phat)/n
ts = (phat - 0.36)/sqrt(se2)
ts
In the R output, the test statistic is the number output after running the “ts
” line. Note that R will give you calculations that are more accurate and more precise than doing the calculations by hand. As such, this computer-calculated test statistic will differ slightly from the one you calculate by hand.
Hide the Excel Code
The Wald test is pedagogically simple to understand. That is why it is used in introductory textbooks. It is actually based on the Normal approximation to the Binomial distribution. There are several improvements to the test. For such reasons, Excel does not have a built-in function to perform the Wald test for proportions. The following code echoes the above calculations to provide the Wald test statistic.
Copy and paste the following code into your Excel window, making sure the value sample
ends up in A1
after pasting.
How to calculate the test statistic in Excel.
sample | | | |
Failure |
|
p0: |
0.36 |
Success |
|
x: |
=COUNTIF(A:A,"Success") |
Success |
|
n: |
=COUNTIF(A:A,"Success")+COUNTIF(A:A,"Failure") |
Failure |
|
p-hat: |
=D3/D4 |
Success |
|
ts: |
=(D5-D2)/sqrt(D5*(1-D5)/D4) |
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Success |
|
|
|
Failure |
|
|
|
Success |
|
|
|
Success |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Success |
|
|
|
Success |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Failure |
|
|
|
Success |
|
|
|
Failure |
|
|
|
The Wald test statistic is the number calculated in cell D6. Again, when you paste this code into Excel, make sure that you start the pasting in cell A1. To help with that, you may want to also copy this notice. It seems to help.