Skip to main content

Section 12.4 Testing Hypothesis on Proportion

Consider the problem of testing hypothesis on the probability of an event. Recall that a probability \(p\) of some event can be estimated by the observed relative frequency of the event in the sample, denoted \(\hat P\text{.}\) The estimation is associated with the Bernoulli random variable \(X\text{,}\) that obtains the value 1 when the event occurs and the value 0 when it does not. The statistical model states that \(p\) is the expectation of \(X\text{.}\) The estimator \(\hat P\) is the sample average of this measurement.
With this formulation we may relate the problem of testing hypotheses formulated in terms of \(p\) to the problem of tests associated to the expectation of a measurement. For the latter problem we applied the \(t\)-test. A similar, though not identical, test is used for the problem of testing hypothesis on proportions.
Assume that one in interested in testing the null hypothesis that the probability of the event is equal to some specific value, say one half, versus the alternative hypothesis that the probability is not equal to this value. These hypotheses are formulated as \(H_0:p = 0.5\) and \(H_1:p\not = 0.5\text{.}\)
The sample proportion of the event \(\hat P\) is the basis for the construction of the test statistic. Recall that the variance of the estimator \(\hat P\) is given by \(\Var(\hat P) = p(1-p)/n\text{.}\) Under the null hypothesis we get that the variance is equal to \(\Var(\hat P) = 0.5(1-0.5)/n\text{.}\) A natural test statistic is the standardized sample proportion:
\begin{equation*} Z = \frac{\hat P - 0.5}{\sqrt{0.5 (1-0.5)/n}}\;, \end{equation*}
that measures the ratio between the deviation of the estimator from its null expected value and the standard deviation of the estimator. The standard deviation of the sample proportion is used in the ratio.
If the null hypothesis that \(p=0.5\) holds true then one gets that the value 0 is the center of the sampling distribution of the test statistic \(Z\text{.}\) Values of the statistic that are much larger or much smaller than 0 indicate that the null hypothesis is unlikely. Consequently, one may consider a rejection region of the form \(\{|Z| > c\}\text{,}\) for some threshold value \(c\text{.}\) The threshold \(c\) is set at a high enough level to assure the required significance level, namely the probability under the null hypothesis of obtaining a value in the rejection region. Equivalently, the rejection region can be written in the form \(\{Z^2 > c^2\}\text{.}\)
As a result of the Central Limit Theorem one may conclude that the distribution of the test statistic is approximately Normal. Hence, Normal computations may be used in order to produce an approximate threshold or in order to compute an approximation for the \(p\)-value. Specifically, if \(Z\) has the standard Normal distribution then \(Z^2\) has a \(\chi^2\) distribution on one degree of freedom.
In order to illustrate the application of hypothesis testing for proportion consider the following problem: In the previous section we obtained the curb weight of 2,414 lb as the sample median. The weights of half the cars in the sample were above that level and the weights of half the cars were below this level. If this level was actually the population median then the probability that the weight of a random car is not exceeding this level would be equal to 0.5.
Let us test the hypothesis that the median weight of cars that run on diesel is also 2,414 lb. Recall that 20 out of the 205 car types in the sample have diesel engines. Let us use the weights of these cars in order to test the hypothesis.
The variable "fuel.type" is a factor with two levels "diesel" and "gas" that identify the fuel type of each car. The variable "heavy" identifies for each car whether its weight is above the level of 2414 or not. Let us produce a \(2 \times 2\) table that summarizes the frequency of each combination of weight group and the fuel type:
fuel <- cars$fuel.type
table(fuel,heavy)
##         heavy
## fuel     FALSE TRUE
##   diesel     6   14
##   gas       97   88
Originally the function "table" was applied to a single factor and produced a sequence with the frequencies of each level of the factor. In the current application the input to the function are two factors
 1 
To be more accurate, the variable "heavy" is not a factor but a sequence with logical components. Nonetheless, when the function "table" is applied to such a sequence it treats it as a factor with two levels, "TRUE" and "FALSE".
. The output is a table of frequencies. Each entry to the table corresponds to the frequency of a combination of levels, one from the first input factor and the other from the second input factor. In this example we obtain that 6 cars use diesel and their curb weight was below the threshold. There are 14 cars that use diesel and their curb weight is above the threshold. Likewise, there are 97 light cars that use gas and 88 heavy cars with gas engines.
The function "prop.test" produces statistical tests for proportions. The relevant information for the current application of the function is the fact that frequency of light diesel cars is 6 among a total number of 20 diesel cars. The first entry to the function is the frequency of the occurrence of the event, 6 in this case, and the second entry is the relevant sample size, the total number of diesel cars which is 20 in the current example:
prop.test(6,20)
## 
##  1-sample proportions test with continuity correction
## 
## data:  6 out of 20, null probability 0.5
## X-squared = 2.45, df = 1, p-value = 0.1175
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
##  0.1283909 0.5433071
## sample estimates:
##   p 
## 0.3
The function produces a report that is printed on the screen. The title identifies the test as a one-sample test of proportions. In later chapters we will apply the same function to more complex data structures and the title will change accordingly. The title also identifies the fact that a continuity correction is used in the computation of the test statistic.
The line under the title indicates the frequency of the event in the sample and the sample size. (In the current example, 6 diesel cars with weights below the threshold among a total of 20 diesel cars.) The probability of the event, under the null hypothesis, is described. The default value of this probability is "p = 0.5", which is the proper value in the current example. This default value can be modified by replacing the value 0.5 by the appropriate probability.
The next line presents the information relevant for the test itself. The test statistic, which is essentially the square of the \(Z\) statistic described above
 2 
The test statistic that is computed by default is based on Yates’ correction for continuity, which is very similar to the continuity correction that was used in ChapterΒ 6 for the Normal approximation of the Binomial distribution. Specifically, the test statistic to the continuity correction for testing \(H_0:p = p_0\) takes the form \([|\hat p - p_0|-0.5/n]^2/[p_0(1-p_0)/n]\text{.}\) Compare this statistic with the statistic proposed in the text that takes the form \([\hat p - p_0]^2/[p_0(1-p_0)/n]\text{.}\) The latter statistic is used if the argument "correct = FALSE" is added to the function.
, obtains the value 2.45. The sampling distribution of this statistic under the null hypothesis is, approximately, the \(\chi^2\) distribution on 1 degree of freedom. The \(p\)-value, which is the probability that \(\chi^2\) distribution on 1 degree of freedom obtains a value above 2.45, is equal to 0.1175. Consequently, the null hypothesis is not rejected at the 5% significance level.
The bottom part of the report provides the confidence interval and the point estimate for the probability of the event. The confidence interval for the given data is \([0.1283909, 0.5433071]\) and the point estimate is \(\hat p = 6/20 = 0.3\text{.}\)
It is interesting to note that although the deviation between the estimated proportion \(\hat p = 0.3\) and the null value of the probability \(p = 0.5\) is relatively large still the null hypothesis was not rejected. The reason for that is the smallness of the sample, \(n = 20\text{,}\) that was used in order to test the hypothesis. Indeed, as an exercise let us examine the application of the same test to a setting where \(n = 200\) and the number of occurrences of the event is 60:
prop.test(60,200)
## 
##  1-sample proportions test with continuity correction
## 
## data:  60 out of 200, null probability 0.5
## X-squared = 31.205, df = 1, p-value = 2.322e-08
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
##  0.2384423 0.3693892
## sample estimates:
##   p 
## 0.3
The estimated value of the probability is the same as before since \(\hat p = 60/200 = 0.3\text{.}\) However, the \(p\)-value is \(2.322 \times 10^{-8}\text{,}\) which is way below the significance threshold of 0.05. In this scenario the null hypothesis is rejected with flying colors.
This last example is yet another demonstration of the basic characteristic of statistical hypothesis testing. The consideration is based not on the discrepancy of the estimator of the parameter from the value of the parameter under the null. Instead, it is based on the relative discrepancy in comparison to the sampling variability of the estimator. When the sample size is larger the variability is smaller. Hence, the chances of rejecting the null hypothesis for the same discrepancy increases.