Section 13.4 Comparing Sample Variances
In the previous section we discussed inference associated with the comparison of the expectations of a numerical measurement between two sub-population. Inference included the construction of a confidence interval for the difference between expectations and the testing of the hypothesis that the expectations are equal to each other.
In this section we consider a comparisons between variances of the measurement in the two sub-populations. For this inference we consider the ratio between estimators of the variances and introduce a new distribution, the \(F\)-distribution, that is associated with this ratio.
Assume, again, the presence of two sub-populations, denoted \(a\) and \(b\text{.}\) A numerical measurement is taken over a sample. The sample can be divided into two sub-samples according to the sub-population of origin. In the previous section we were interested in inference regarding the relation between the expectations of the measurement in the two sub-populations. Here we are concerned with the comparison of the variances.
Specifically, let \(X_a\) be the measurement at the first sub-population and let \(X_b\) be the measurement at the second sub-population. We want to compare \(\Var(X_a)\text{,}\) the variance in the first sub-population, to \(\Var(X_b)\text{,}\) the variance in the second sub-population. As the basis for the comparison we may use \(S_a^2\) and \(S_b^2\text{,}\) the sub-samples variances, which are computed from the observations in the first and the second sub-sample, respectively.
Consider the confidence interval for the ratio of the variances. In ChapterΒ 11 we discussed the construction of the confidence interval for the variance in a single sample. The derivation was based on the sample variance \(S^2\) that serves as an estimator of the population variance \(\Var(X)\text{.}\) In particular, the distribution of the random variable \((n-1)S^2/\Var(X)\) was identified as the chi-square distribution on \(n-1\) degrees of freedom. A confidence interval for the variance was obtained as a result of the identification of a central region in the chi-square distribution that contains a pre-subscribed probability.
β1β
This statement holds when the distribution of the measurement is Normal.
β2β
Use \(\Prob(\mbox{\texttt{qchisq(0.025,n-1)}} \leq (n-1)S^2/\Var(X) \leq \mbox{\texttt{qchisq(0.975,n-1)}}) = 0.95\) and rewrite the event in a format that puts the parameter in the center. The resulting 95% confidence interval is \([(n-1)S^2/\mbox{\texttt{qchisq(0.975,n-1)}},(n-1)S^2/\mbox{\texttt{qchisq(0.025,n-1)}}]\text{.}\)
In order to construct a confidence interval for the ratio of the variances we consider the random variable that is obtained as a ratio of the estimators of the variances:
\begin{equation*}
\frac{S_a^2/\Var(X_a)}{S^2_b/\Var(X_b)} \sim F_{(n_a-1,n_b-1)}\;.
\end{equation*}
The distribution of this random variable is denoted the \(F\)-distribution. This distribution is characterized by the number of degrees of freedom associated with the estimator of the variance at the numerator and by the number of degrees of freedom associated with the estimator of the variance at the denominator. The number of degrees of freedom associated with the estimation of each variance is the number of observation used for the computation of the estimator, minus 1. In the current setting the numbers of degrees of freedom are \(n_a-1\) and \(n_b-1\text{,}\) respectively.
β3β
The \(F\) distribution is obtained when the measurement has a Normal distribution. When the distribution of the measurement is not Normal then the distribution of the given random variable will not be the \(F\)-distribution.
The percentiles of the \(F\)-distribution can be computed in
R using the function qf. For example, the 0.025-percentile of the distribution for the ratio between sample variances of the response for two sub-samples is computed by the expression qf(0.025,dfa,dfb), where \(\mbox{\texttt{dfa}} = n_a - 1\) and \(\mbox{\texttt{dfb}} = n_b - 1\text{.}\) Likewise, the 0.975-percentile is computed by the expression qf(0.975,dfa,dfb). Between these two numbers lie 95% of the given \(F\)-distribution. Consequently, the probability that the random variable \(\{S_a^2/\Var(X_a)\}/\{S_b^2/\Var(X_b)\}\) obtains its values between these two percentiles is equal to 0.95:
\begin{equation*}
\begin{aligned}
\lefteqn{\frac{S_a^2/\Var(X_a)}{S_b^2/\Var(X_b)} \sim F_{(n_a-1,n_b-1)} \quad \Longrightarrow }\\ & \Prob \big( \mbox{\texttt{qf(0.025,dfa,dfb)}} \leq {\textstyle \frac{S_a^2/\Var(X_a)}{S_b^2/\Var(X_b)}} \leq \mbox{\texttt{qf(0.975,dfa,dfb)}} \big) = 0.95\;.\end{aligned}
\end{equation*}
A confidence interval for the ratio between \(\Var(X_a)\) and \(\Var(X_b)\) is obtained by reformulation of the last event. In the reformulation, the ratio of the variances is placed in the center:
\begin{equation*}
\Big\{\frac{S_a^2/S_b^2}{\mbox{\texttt{qf(0.975,dfa,fdb)}}} \leq \frac{\Var(X_a)}{\Var(X_b)} \leq \frac{S_a^2/S_b^2}{\mbox{\texttt{qf(0.025,dfa,dfb)}}}\Big\}\;.
\end{equation*}
This confidence interval has a significance level of 95%.
Next, consider testing hypotheses regarding the relation between the variances. Of particular interest is testing the equality of the variances. One may formulate the null hypothesis as \(H_0: \Var(X_a)/\Var(X_b) = 1\) and test it against the alternative hypothesis \(H_1: \Var(X_a)/\Var(X_b) \not = 1\text{.}\)
The statistic \(F = S_a^2/S_b^2\) can used in order to test the given null hypothesis. Values of this statistic that are either much larger or much smaller than 1 are evidence against the null hypothesis and in favor of the alternative hypothesis. The sampling distribution, under that null hypothesis, of this statistic is the \(F_{(n_a-1,n_b-1)}\) distribution. Consequently, the null hypothesis is rejected either if \(F < \mbox{\texttt{qf(0.025,dfa,dfb)}}\) or if \(F >\mbox{\texttt{qf(0.975,dfa,dfb)}}\text{,}\) where \(\mbox{\texttt{dfa}} = n_a - 1\) and \(\mbox{\texttt{dfb}} = n_b - 1\text{.}\) The significance level of this test is 5%.
Given an observed value of the statistic, the \(p\)-value is computed as the significance level of the test which uses the observed value as the threshold. If the observed value \(f\) is less than 1 then the \(p\)-value is twice the probability of the lower tail: \(2\cdot \Prob(F < f)\text{.}\) On the other hand, if \(f\) is larger than 1 one takes twice the upper tail as the \(p\)-value: \(2\cdot \Prob(F > f) = 2\cdot [1-\Prob(F \leq f)]\text{.}\) The null hypothesis is rejected with a significance level of 5% if the \(p\)-value is less than 0.05.
In order to illustrate the inference that compares variances let us return to the variable
dif.mpg and compare the variances associated with the two levels of the factor heavy. The analysis will include testing the hypothesis that the two variances are equal and an estimate and a confidence interval for their ratio.
The function
var.test may be used in order to carry out the required tasks. The input to the function is a formula such dif.mpg~heavy, with a numeric variable on the left and a factor with two levels on the right. The default application of the function to the formula produces the desired test and confidence interval:
var.test(dif.mpg~heavy)
## ## F test to compare two variances ## ## data: dif.mpg by heavy ## F = 0.61965, num df = 102, denom df = 101, p-value = 0.01663 ## alternative hypothesis: true ratio of variances is not equal to 1 ## 95 percent confidence interval: ## 0.4189200 0.9162126 ## sample estimates: ## ratio of variances ## 0.6196502
Consider the report produced by the function. The observed value of the test statistic is
F = 0.6197, and it is associated with the \(F\)-distribution on num df = 102 and denom df = 101 degrees of freedom. The test statistic can be used in order to test the null hypothesis \(H_0: \Var(X_a)/\Var(X_b) = 1\text{,}\) that states that the two variance are equal, against the alternative hypothesis that they are not. The \(p\)-value for this test is p-value = 0.01663, which is less than 0.05. Consequently, the null hypothesis is rejected and the conclusion is that the two variances are significantly different from each other. The estimated ratio of variances, given at the bottom of the report, is 0.6196502. The confidence interval for the ratio is reported also and is equal to \([0.4189200, 0.9162126]\text{.}\)
In order to relate the report to the theoretical discussion above let us recall that the sub-samples variances are \(s^2_a = 2.020750\) and \(s_b^2 = 3.261114\text{.}\) The sub-samples sizes are \(n_a = 103\) and \(n_b = 102\text{,}\) respectively. The observed value of the statistic is the ratio \(s_a^2/s_b^2 = 2.020750/3.261114 = 0.6196502\text{,}\) which is the value that appears in the report. Notice that this is the estimate of the ratio between the variances that is given at the bottom of the report.
The \(p\)-value of the two-sided test is equal to twice the probability of the tail that is associated with the observed value of the test statistic as a threshold. The number of degrees of freedom is \(\mbox{\texttt{dfa}} = n_a - 1 = 102\) and \(\mbox{\texttt{dfb}} = n_b - 1 = 101\text{.}\) The observed value of the ratio test statistic is \(f = 0.6196502\text{.}\) This value is less than one. Consequently, the probability \(\Prob(F < 0.6196502)\) enters into the computation of the \(p\)-value, which equals twice this probability:
2*pf(0.6196502,102,101)
## [1] 0.01662612
Compare this value to the \(p\)-value that appears in the report and see that, after rounding up, the two are the same.
For the confidence interval of the ratio compute the percentiles of the \(F\) distribution:
qf(0.025,102,101)
qf(0.975,102,101)
## [1] 0.676317
## [1] 1.479161
The confidence interval is equal to:
\begin{equation*}
\begin{aligned}
\Big[\frac{s_a^2/s_b^2}{\mbox{\texttt{qf(0.975,102,101)}}} , \frac{s_a^2/s_b^2}{\mbox{\texttt{qf(0.025,102,101)}}}\Big] &= \Big[\frac{0.6196502}{1.479161} , \frac{0.6196502}{0.676317}\Big]\\ &= [0.4189200, 0.9162127]\;,\end{aligned}
\end{equation*}
which coincides with the reported interval.
