This note is still being edited: the text may contain typos, inaccuracies, and locally unpolished passages. If you find something, please let the author know (contact information on the course page).
1 Testing a simple hypothesis of the form \(\overrightarrow {\theta } = \overrightarrow {\theta }_0\)
where \(\overrightarrow {\theta }_0 \in \mathbb {R}^{\tilde{k}}\) is an arbitrary fixed vector.
For example, \(\overrightarrow {\theta }_0 = \overrightarrow {0}\): in this case we test \(\overrightarrow {X} = \overrightarrow {\varepsilon }\) against \(\overrightarrow {X} = \mathbf{z}\overrightarrow {\theta } + \overrightarrow {\varepsilon }\), where \(\overrightarrow {\theta } \neq \overrightarrow {0}\). In essence, we are testing the hypothesis that the given regressors \(\mathbf{z}\) genuinely affect the values of the dependent variable \(\overrightarrow {X}\). The null hypothesis in this case is that \(\overrightarrow {X}\) is simply noise, not depending in any way on the regressors.
Geometry of testing the simple hypothesis \(\mathbf z\overrightarrow{\theta}=\overrightarrow{\theta}_0\) (Three.js version): the observation \(X\), its projection \(\widehat X=X_L=\mathbf z\widehat{\overrightarrow\theta}\) onto the subspace \(L\), the hypothesized point \(F=\mathbf z\overrightarrow{\theta}_0\), and the discrepancy vector \(\overrightarrow{FB}=X_L-\mathbf z\overrightarrow{\theta}_0\). The right angle at vertex \(B\) of the triangle \(OFB{\to}A\) illustrates that \(X-X_L\perp L\), and the \(F\)-statistic, when \(H_0\) holds, compares the length of the short discrepancy \(\overrightarrow{FB}\) (lying in \(L\)) with the length of the error \(\overrightarrow{BA}=\widehat{\overrightarrow\varepsilon}\) (perpendicular to \(L\)) — by Cochran’s theorem these vectors are independent. The labels are genuinely rendered LaTeX (KaTeX), anchored to their line/vector and rotated along it; when the scene is rotated with the mouse they stay in place. The mouse wheel zooms.
How can we test \(H_0\) against \(H_1\)? Let us take a closer look at fig. @LinearRegrHypTest:GraphSimpelHyp: if the null hypothesis is true, i.e. the unknown true parameter \(\overrightarrow {\theta }\) equals \(\overrightarrow {\theta }_0\), then its estimator \(\widehat{\overrightarrow {\theta }}\) should not differ much from \(\overrightarrow {\theta }_0\), since
It is convenient to compare \(\mathbf{z}\widehat{\overrightarrow {\theta }} - \mathbf{z}\overrightarrow {\theta }_0\) specifically with the last vector, with the vector \(\overrightarrow {X} -\widehat{\overrightarrow {X}} = \overrightarrow {X}_{L^\perp }\), since by Cochran’s theorem on the orthogonal decomposition of a Gaussian vector, these vectors are independent. By the same theorem we can find (assuming \(H_0\) holds) the distributions of the squared lengths of these vectors. For the vector \(\overrightarrow {FB}\), note that under \(H_0\)
For the vector \(\overrightarrow {BA} = \overrightarrow {X} -\widehat{\overrightarrow {X}} = \overrightarrow {X}_{L^\perp }\) we have \(\mathbb {E}\left[\overrightarrow {X}_{L^\perp }\right] = \overrightarrow {0}\), so
Definition 1 Let \(\xi_{1}, \xi_{2}\) be independent random variables distributed according to the laws \(\chi_{n_{1}}^{2}, \chi_{n_{2}}^{2}\) respectively. Then the random variable \[
\frac{\xi _{1} / n_{1}}{\xi _{2} / n_{2}}
\] has the Fisher distribution with \(n_{1}, n_{2}\) degrees of freedom (denoted \(\operatorname {F}_{n_1, n_2}\)).
The density of the Fisher distribution \(\operatorname{F}_{d_1,d_2}\) — the distribution of the ratio \(\frac{\xi_1/d_1}{\xi_2/d_2}\) of independent \(\chi^2_{d_1}, \chi^2_{d_2}\) random variables (see the definition of the F-statistic above). Move the sliders \(d_1, d_2\) — the density updates continuously; the buttons set four characteristic examples. If \(H_0\) holds, the numerator and denominator of the \(F\)-statistic estimate the same variance \(\sigma^2\), and as \(d_1, d_2\) grow, their ratio concentrates around \(1\) (dashed vertical line).
By definition Definition 1, it follows the Fisher distribution with \(\tilde{k}, n - \tilde{k}\) degrees of freedom: \(F \sim \operatorname {F}_{\tilde{k}, n - \tilde{k}}\).
Test of significance level \(\alpha\) for testing \(H_0\) against \(H_1\): if the \(F\)-statistic is too large — greater than the quantile of level \(1-\alpha\) from the distribution \(\operatorname {F}_{\tilde{k}, n - \tilde{k}}\) — then we reject \(H_0\). That is,
The coffee machine in the building lobby promises to pour a \(200\) ml espresso. A skeptical student measured the volumes of \(8\) purchased servings and got (in ml): \[
205, \quad 193, \quad 189, \quad 197, \quad 187, \quad 196, \quad 191, \quad 194.
\] Assuming the serving volume is distributed as \(\mathscr {N}\left(\theta , \sigma^2\right)\) with unknown \(\theta , \sigma^2\), use the \(F\)-test to check the hypothesis \(H_0: \theta = 200\) (the machine pours as much as it promises) at significance levels \(5\%\) and \(1\%\).
SolutionSolution
Let us write the measurements as a linear Gaussian model with one parameter:
Under \(H_0\) the statistic \(F\) is distributed as \(\operatorname {F}_{1,7}\). The needed quantiles: \(Q_{\operatorname {F}_{1,7}}(0.95) \approx 5.59\), \(Q_{\operatorname {F}_{1,7}}(0.99) \approx 12.25\). Since \(5.59 < 9.25 < 12.25\), at significance level \(5\%\) we reject \(H_0\), while at significance level \(1\%\) we cannot reject it; the \(p\)-value equals
In total, a moderately strict skeptic would conclude that the machine is underpouring.
Note that for \(\tilde{k} = 1\) the test we constructed is exactly the squared two-sided Student’s test for the mean of a normal sample:
\[
F = T^2, \qquad T = \frac{\left(\overline{\overrightarrow {X}} - \theta _0\right)\sqrt{n}}{\sqrt{\operatorname {RSS}/(n-1)}} \approx -3.04 \sim T_{n-1} \text{ under } H_0,
\]
and \(\left|T\right| \approx 3.04 > Q_{T_7}(0.975) \approx 2.36\) — the same conclusion.
AnswerAnswer
At significance level \(5\%\) we reject the hypothesis; at \(1\%\) we cannot reject it (\(p\)-value \(\approx 1.9\%\)).
ExampleExample 2
A taxi service advertises a fare: \(100\) rubles for pickup plus \(30\) rubles per kilometer traveled. A passenger suspects it’s coming out more expensive, and recorded the costs of seven trips:
Distance\(d_i\), km
2
4
5
7
9
12
15
Fare\(P_i\), rub.
160
219
269
355
422
501
564
Assuming the cost of a trip is described by the model \(P_i = a + b \cdot d_i + \varepsilon_i\), where \(d_i\) is the distance, and the errors \(\varepsilon_i \sim \mathscr {N}\left(0, \sigma^2\right)\) are independent (\(\sigma^2\) is unknown; the noise arises from paid waiting time, traffic, and rounding), test the hypothesis about the advertised fare \[
H_0: \; \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} 100 \\ 30 \end{pmatrix}
\] at significance level \(5\%\).
SolutionSolution
This is a linear Gaussian model \(\overrightarrow {P} = \mathbf{z}\overrightarrow {\theta } + \overrightarrow {\varepsilon }\) with an intercept and one regressor: \[
\overrightarrow {\theta } = \begin{pmatrix} a \\ b\end{pmatrix}, \qquad \mathbf{z} = \begin{pmatrix} 1 & 1 & \ldots & 1 \\ d_1 & d_2 & \ldots & d_7 \end{pmatrix}^T, \qquad n = 7, \quad \tilde{k} = k + 1 = 2,
\] and we test the simple hypothesis \(\overrightarrow {\theta } = \overrightarrow {\theta }_0 = (100, 30)^T\) about the whole parameter vector. We have \[
\begin{align} \mathbf{z}^T\mathbf{z} & = \begin{pmatrix} n & \sum _i d_i \\ \sum _i d_i & \sum _i d_i^2\end{pmatrix} = \begin{pmatrix} 7 & 54 \\ 54 & 544 \end{pmatrix}, \qquad \mathbf{z}^T\overrightarrow {P} = \begin{pmatrix} \sum _i P_i \\ \sum _i d_iP_i \end{pmatrix} = \begin{pmatrix} 2490 \\ 23296 \end{pmatrix} \\ \widehat{\overrightarrow {\theta }} & = \left(\mathbf{z}^T\mathbf{z}\right)^{-1}\mathbf{z}^T\overrightarrow {P} = \frac{1}{892}\begin{pmatrix} 544 & -54 \\ -54 & 7 \end{pmatrix}\begin{pmatrix} 2490 \\ 23296 \end{pmatrix} \\ & = \frac{1}{892}\begin{pmatrix} 544 \cdot 2490 - 54 \cdot 23296 \\ -54 \cdot 2490 + 7 \cdot 23296\end{pmatrix} = \frac{1}{892}\begin{pmatrix} 96576 \\ 28612\end{pmatrix} \approx \begin{pmatrix} 108.27 \\ 32.08 \end{pmatrix} \end{align}
\] The pickup is estimated at \(108\) rubles instead of the advertised \(100\), and the kilometer at \(32.1\) rubles instead of \(30\): it does look like the passenger is indeed being charged an inflated fare. Let us check whether the deviation is significant. \[
\begin{align} \operatorname {RSS} & = \left\| \overrightarrow {P} - \mathbf{z}\widehat{\overrightarrow {\theta }}\right\| ^2 \approx 2290.1 \\ \left|\overrightarrow {FB}\right|^2 & = \left(\widehat{\overrightarrow {\theta }} - \overrightarrow {\theta }_0\right)^T \mathbf{z}^T\mathbf{z} \left(\widehat{\overrightarrow {\theta }} - \overrightarrow {\theta }_0\right) \approx 4677.9 \\ F & = \frac{\left|\overrightarrow {FB}\right|^2 / \tilde{k}}{\operatorname {RSS}/(n - \tilde{k})} = \frac{4677.9/2}{2290.1/5} \approx 5.11 \end{align}
\] Under \(H_0\) we have \(F \sim \operatorname {F}_{2,5}\), and \(Q_{\operatorname {F}_{2,5}}(0.95) \approx 5.79 > 5.11\): at significance level \(5\%\) the hypothesis about the advertised fare cannot be rejected; the \(p\)-value equals \[
\mathbb {P}\left( F > 5.11 \mid H_0 \right) \approx 6.2\% .
\] Seven trips, with noise \(\widehat{\sigma } = \sqrt{\operatorname {RSS}/(n - \tilde{k})} \approx 21\) rubles, is too little data to confidently distinguish \((108.27, 32.08)\) from \((100, 30)\). Note also that \(Q_{\operatorname {F}_{2,5}}(0.9) \approx 3.78 < 5.11\), i.e. at significance level \(10\%\) the hypothesis would already have been rejected. Failing to reject \(H_0\) here is not proof that the fare is honest, but rather a statement that there is not enough data: the passenger should record more trips.
AnswerAnswer
\(F \approx 5.11 < Q_{\operatorname {F}_{2,5}}(0.95) \approx 5.79\): at significance level \(5\%\) the hypothesis cannot be rejected (\(p\)-value \(\approx 6.2\%\)).
ProblemProblem 1
Suppose the model has no intercept, and we test the hypothesis \(\theta_1 = \ldots = \theta_k = 0\). Express the \(F\)-statistic for this hypothesis and the coefficient of determination \(R^2\) of the model in terms of each other.
2 General case: testing a composite hypothesis of the form \(\mathbf{w}^T\overrightarrow {\theta } = \overrightarrow {\tau }_0\)
Continuing from the previous section, consider a composite parametric null hypothesis against a composite parametric alternative:
where \(\mathbf{w} \in \mathbb {R}^{\tilde{k} \times m}\) is some fixed matrix of dimension \(\tilde{k} \times m, \; m \leq \tilde{k}\) of full rank: \(\operatorname {rk}(\mathbf{w}) = m\). \(\overrightarrow {\tau }_0 \in \mathbb {R}^{m}\) is some fixed vector.
ExampleExample 3
A new batch of coins has been minted. Before putting them into use, it was decided to run a study to check that the coins are identical. On a scale with measurement error distributed as \(\mathcal{N}\left(0, \sigma^{2}\right)\), two coins were weighed, with the first weighed \(n_1\) times and the second \(n_2\) times. All measurements were made independently. Formulate the hypothesis that the masses of the coins are the same.
SolutionSolution
Let \(Y^{(1)}_{1}, \ldots , Y^{(1)}_{n_1}\) and \(Y^{(2)}_{1}, \ldots , Y^{(2)}_{n_2}\) be independent samples from the distributions \(\mathcal{N}\left(a_{1}, \sigma^{2}\right)\) and \(\mathcal{N}\left(a_{2}, \sigma^{2}\right)\) respectively. We consider the hypothesis \(H_{0}: a_{1}=a_{2}\).
Consider the linear model \(\overrightarrow {X}= \mathbf{z} \overrightarrow {\theta } + \overrightarrow {\varepsilon }\), where
It is worth noting that hypothesis \(H_0\) from LinearRegrHypTest:ComposHyp is composite only if the matrix \(\mathbf{w}^T\) has fewer rows than columns, i.e. \(m < \tilde{k}\). Note that the simple hypothesis \(\overrightarrow {\theta } = \overrightarrow {\theta }_0\) from the previous section is a special case of LinearRegrHypTest:ComposHyp: one just needs to take \(\mathbf{w} = \mathbf{I}_{\tilde{k}}, \; \overrightarrow {\tau }_0 = \overrightarrow {\theta }_0\).
Geometry of testing the composite hypothesis \(\mathbf w^T\overrightarrow{\theta}=\overrightarrow{\tau_0}\) (Three.js version): the subspace \(L_1\) (condition \(\mathbf w^T\overrightarrow{\theta}=0\)) and its orthogonal complement \(L_2\) in \(L\), the affine subspaces \(\mathcal L_1=L_1+\overrightarrow{l_2}\) and its estimate \(\widehat{\mathcal L}_1=L_1+X_{L_2}\), and the points \(B=X_L=\mathbf z\widehat{\overrightarrow{\theta}}\) and \(F=X_{\mathcal L_1}\) (constrained OLS estimate). The right angles at vertices \(B\) and \(F\) of the triangle \(AFB\) illustrate the Pythagorean theorem. The labels are genuinely rendered LaTeX (KaTeX), anchored to their line/vector and rotated along it; when the scene is rotated with the mouse they stay in place and correctly update their angle. The mouse wheel zooms; the slider \(\tau_0\) below moves the hypothesis.
How can we test \(H_0\) against \(H_1\)? Let us take a closer look at fig. @LinearRegrHypTest:GraphCompositeHyp. Note that the condition \(\mathbf{w}^T \overrightarrow {\theta } = \overrightarrow {0}\) on the vector \(\mathbf{z}\overrightarrow {\theta } \in \mathbb {R}^{n}\) defines some linear subspace \(L_1\) within the subspace
Since the rank of the matrix \(\mathbf{w}^T\) equals \(m\), i.e. the number of its rows, the condition \(\mathbf{w}^T \overrightarrow {\theta } = \overrightarrow {0}\) imposes \(m\) linear constraints on the \(\tilde{k}\)-dimensional vector \(\overrightarrow {\theta }\). Hence,
\[
\dim (L_1) = \dim (L) - m = \tilde{k}-m.
\]
Denote by \(L_2\) the orthogonal complement of \(L_1\) within the subspace \(L\). We have \(\dim (L_2) = \dim (L) - \dim (L_1) = m\).
The condition \(\mathbf{w}^T \overrightarrow {\theta } = \overrightarrow {\tau }_0\) on the vector \(\mathbf{z}\overrightarrow {\theta } \in \mathbb {R}^{n}\) obviously defines some affine subspace \(\mathcal{L}_1\) with linear part \(L_1\). Let \(\overrightarrow {l}_2 := L_2 \cap \mathcal{L}_1\). Note that \(\mathcal{L}_1 = L_1 + \overrightarrow {l}_2\).
i.e. \(\widehat{\overrightarrow {\tau }}\) is an unbiased estimator of \(\mathbf{w}^T \overrightarrow {\theta }\). Since \(\widehat{\overrightarrow {\tau }}\) is a function of a complete, sufficient statistic, \(\widehat{\overrightarrow {\tau }}\) is the optimal estimator of \(\mathbf{w}^T \overrightarrow {\theta }\).
Note that \(\overrightarrow {X}_{\mathcal{L}_1} = \overrightarrow {X}_{L_1} + \overrightarrow {l}_2\)
If \(H_0\) holds, then the estimator \(\widehat{\overrightarrow {\tau }}\) should be close to \(\overrightarrow {\tau }_0\), and \(\widehat{\mathcal{L}}_1\) should be close to \(\mathcal{L}_1\). The distance between them
as in the previous section, is convenient to compare with \(\left|\overrightarrow {BA}\right| = \left\| \overrightarrow {X} - \overrightarrow {X_L}\right\| = \sqrt{\operatorname {RSS}}\), since by the theorem on the orthogonal decomposition of a Gaussian vector, the vectors
We already know how to find \(\left|\overrightarrow {BA}\right|^2 = \left\| \overrightarrow {X} - \overrightarrow {X_L}\right\|^2 = \operatorname {RSS}\) and how \(\operatorname {RSS}\) is distributed:
Let us express \(\left|\overrightarrow {FB}\right|^2\) in terms of \(\overrightarrow {X}, \mathbf{z}, \mathbf{w}\) and find the distribution of \(\left|\overrightarrow {FB}\right|^2\).
1. The case of orthonormal columns in \(\mathbf{z}\) and in \(\mathbf{w}\). Let us first consider the case where the columns of the matrix \(\mathbf{z} \in \mathbb {R}^{n \times \tilde{k}}\) and of the matrix \(\mathbf{w} \in \mathbb {R}^{\tilde{k} \times m}\) form orthonormal systems in \(\mathbb {R}^{n}\) and \(\mathbb {R}^{\tilde{k}}\) respectively. Such matrices are called semi-orthogonal. In our case we have \(\mathbf{z}^T\mathbf{z} = \mathbf{I}_{\tilde{k}}, \; \mathbf{w}^T\mathbf{w} = \mathbf{I}_m\). Recall that \(n \geq \tilde{k} \geq m\).
and, expanding the squared norm and using semi-orthogonality (\(\mathbf{w}^T \mathbf{z}^T \mathbf{z} \mathbf{w} = \mathbf{w}^T\mathbf{w} = \mathbf{I}_m\)), we get
be an arbitrary singular value decomposition of \(\mathbf{z}\): here \(\tilde{\mathbf{z}} := \mathbf{u}_\mathbf {z} \in \mathbb {R}^{n \times \tilde{k}}\) is a semi-orthogonal matrix, \(\Lambda_\mathbf {z} \in \mathbb {R}^{\tilde{k} \times \tilde{k}}\) is a diagonal matrix with positive numbers on the diagonal, \(\mathbf{v}_\mathbf {z} \in \mathbb {R}^{\tilde{k} \times \tilde{k}}\) is an orthogonal matrix. Note that the columns of \(\mathbf{z}\) and \(\tilde{\mathbf{z}}\) span the same subspace \(L\), and \(\tilde{\mathbf{z}}\) is semi-orthogonal and
If \(\overrightarrow {\theta }\) are the coordinates of an arbitrary vector from \(L\) in the basis formed by the columns of \(\mathbf{z}\), let \(\tilde{\overrightarrow {\theta }}\) be the coordinates of the same vector in the basis formed by the columns of \(\tilde{\mathbf{z}}\). We have
Let us rewrite the condition \(\mathbf{w}^T \overrightarrow {\theta } = \overrightarrow {\tau }_0\) for the vector \(\overrightarrow {\theta }\) as a condition for the vector \(\tilde{\overrightarrow {\theta }}\):
It is easy to show that the matrix \(\mathbf{w}' := \Lambda^{-1}_{\mathbf{z}} \mathbf{v}_{\mathbf{z}}^T \mathbf{w} \in \mathbb {R}^{\tilde{k} \times m}\) has the same rank as \(\mathbf{w}\), i.e. \(m\). Let
be a singular value decomposition of \(\mathbf{w}'\): here \(\tilde{\mathbf{w}} := \mathbf{u}_{\mathbf{w}'} \in \mathbb {R}^{\tilde{k} \times m}\) is a semi-orthogonal matrix, \(\Lambda_{\mathbf{w}'} \in \mathbb {R}^{m \times m}\) is a diagonal matrix with positive numbers on the diagonal, \(\mathbf{v}_{\mathbf{w}'} \in \mathbb {R}^{m \times m}\) is an orthogonal matrix.
Let us return from \(\tilde{\overrightarrow {\tau }}\) to the original \(\overrightarrow {\tau }\): the correspondence \(\tilde{\overrightarrow {\tau }} = \Lambda_{\mathbf{w}'}^{-1}\mathbf{v}^T_{\mathbf{w}'} \cdot \overrightarrow {\tau }\) is linear, so it relates not only the hypothetical values \(\tilde{\overrightarrow {\tau }}_0\) and \(\overrightarrow {\tau }_0\), but also the estimators \(\widehat{\tilde{\overrightarrow {\tau }}}\) and \(\widehat{\overrightarrow {\tau }}\). Hence,
It remains to recognize in the matrix \(\mathbf{v}_{\mathbf{w}'}\Lambda_{\mathbf{w}'}^{-2}\mathbf{v}^T_{\mathbf{w}'}\) the matrix \(\mathbf{b}^{-1}\) from the statement of the theorem. Indeed,
(the last equality is by definition of \(\mathbf{w}' = \Lambda^{-1}_{\mathbf{z}} \mathbf{v}_{\mathbf{z}}^T \mathbf{w}\), and just before it we simply split \(\Lambda_{\mathbf{z}}^{-2} = \Lambda^{-1}_{\mathbf{z}}\Lambda^{-1}_{\mathbf{z}}\) and grouped the factors into a transposed pair). Substituting the singular value decomposition \(\mathbf{w}' = \mathbf{u}_{\mathbf{w}'}\Lambda_{\mathbf{w}'}\mathbf{v}_{\mathbf{w}'}^T\) and using the semi-orthogonality \(\mathbf{u}_{\mathbf{w}'}^T\mathbf{u}_{\mathbf{w}'} = \mathbf{I}_m\):
If \(H_0\) holds, then, by what was proved above and by definition Definition 1, this statistic is distributed according to the Fisher distribution with \(m, n - \tilde{k}\) degrees of freedom: \(F \sim \operatorname {F}_{m, n - \tilde{k}}\).
Test of significance level \(\alpha\) for testing \(H_0\) against \(H_1\): if the \(F\)-statistic is too large — greater than the quantile of level \(1-\alpha\) from the distribution \(\operatorname {F}_{m, n - \tilde{k}}\) — then we reject \(H_0\). That is,
Suppose the model has an intercept \(\theta_0\), and we again test the hypothesis \(\theta_1 = \ldots = \theta_k = 0\). Express the \(F\)-statistic for this hypothesis and the coefficient of determination \(R^2\) of this model in terms of each other.
ExampleExample 5
Under the conditions of example Example 3, construct the \(F\)-test of significance level \(\alpha\) for testing the hypothesis that the masses of the coins are the same.
SolutionSolution
Let us find \(\left|\overrightarrow {BA}\right|^2 = \operatorname {RSS}\). We have
The test \(\left\{ F > Q_{\operatorname {F}_{1, n_1 + n_2 - 2}}(1 - \alpha )\right\}\), where \(Q_{\operatorname {F}_{1, n_1 + n_2 - 2}}(\cdot )\) is the quantile function of the distribution \(\operatorname {F}_{1, n_1 + n_2 - 2}\).
ProblemProblem 3
Let \[
X_{i}=\theta _0+i \theta _1+\varepsilon _{0}+\ldots +\varepsilon _{i},
\]\(i=0,1, \ldots , n\), where \(\theta_0, \theta_1\) are unknown parameters, and the random variables \(\varepsilon_{0}, \ldots , \varepsilon_{n}\) are independently distributed as \(\mathscr {N}\left(0, \sigma^2\right)\). Reduce the problem to a linear Gaussian model and construct the \(F\)-test of significance level \(\alpha\) for testing the hypothesis \(H_{0}: \theta_0=\theta_1\).
In some problems computing the statistic \(F\) is difficult because it requires computing the inverse matrix \(\mathbf{b}^{-1}\). In such cases it is convenient to use the Pythagorean theorem in the triangle \(AFB\) (see fig. @LinearRegrHypTest:GraphCompositeHyp). We have
is called the constrained least squares estimator. It is often more convenient to compute the constrained least squares estimator, and then express \(\left|\overrightarrow {FB}\right|^2\) as
The measured quantity \(x\) is known to depend on temperature \(t\) as follows: \[
x(t)=\theta _{1}+\theta _{2} t+\theta _{3} t^{2}.
\]
A series of independent experiments \(\omega_0\) was performed at temperature values equal to \[
t_{1}=-1, \quad t_{2}=0, \quad t_{3}=1, \quad t_{4}=2, \quad t_{5}=3
\] The corresponding results were obtained: \[
X_{1}(\omega _0)=1, \quad X_{2}(\omega _0)=6, \quad X_{3}(\omega _0)=10, \quad X_{4}(\omega _0)=14, \quad X_{5}(\omega _0)=19
\] The measurement errors are assumed independent and distributed as \(\mathscr {N}\left(0, 1\right)\). In addition, the optimal estimator \(\widehat{\sigma^{2}}=0.4\) of the error variance \(\sigma^{2}\) was found. Using the \(F\)-test, test the hypothesis \(H_{0}\) that \(\theta_{1}=\theta_{2}\) and \(\theta_{3}=0\), at significance level \(\alpha =0.1\).
SolutionSolution
Let \(\overrightarrow {X}=\left(X_{1}, \ldots , X_{5}\right)^{T}\). Consider the linear model
Let us find the \(F\)-statistic in this experiment \(\omega_0\). When \(\theta_1=\theta_2=:\theta\) and \(\theta_3=0\), the model takes the form \(X_i = \theta (1+t_i) + \varepsilon_i\), so
Hence, we need to minimize over \(\theta\) the quadratic function \(30\theta^2 - 288\theta + 694\). The minimum of the function \(a\theta^2+b\theta +c\) (\(a>0\)) is attained at the point \(\theta^* = -b/(2a)\) and equals \(c - b^2/(4a)\):
Density of the \(\operatorname F_{2,2}\) distribution and the \(p\)-value for the observed value of the statistic \(F(\omega_0)=2.5\): the shaded area under the graph to the right of \(2.5\).
If \(H_0\) holds, then \(F \sim \operatorname {F}_{2,2}\). We can test \(H_0\) against \(H_1\) in 2 equivalent ways.
Enum-item1.
Compute the \(p\)-value — the probability of obtaining, in an independent copy of the experiment being run, a value of the statistic that is the same (\(2.5\)) or more critical (greater than \(2.5\)), given that hypothesis \(H_0\) holds, i.e. given \(F \sim \operatorname {F}_{2,2}\):
\[
p = \mathbb {P}\left( F > 2.5 \mid H_0 \right) \approx 28.6\% .
\]
The \(p\)-value is greater than the significance level, so the data is not critical enough, not significant. \(H_0\) should not be rejected.
Enum-item2.
Compute the critical region for this significance level and see whether the sample (statistic) falls into it. This can be done using quantile tables. For example, for the distribution \(\operatorname {F}_{2,2}\) the quantile of level \(1 - \alpha = 0.9\) equals \(9\). That is, the critical region is \(\left\{ F > 9\right\}\). In our experiment \(F(\omega_0) = 2.5 < 9\), so \(H_0\) should not be rejected.
Quantiles at level \(1-\alpha=0.9\) of the \(\operatorname F_{d_1,d_2}\) distribution as a function of \(d_1,d_2\in\naturals\). The cell \(d_1=2,\,d_2=2\) used in the example is highlighted.
AnswerAnswer
\(H_0\) should not be rejected.
ProblemProblem 4
\(Y^{(1)}_{1}, \ldots , Y^{(1)}_{n_1}\) is a sample from the distribution \(\mathscr {N}\left(a_{1}, \sigma^{2}\right)\), \(Y^{(2)}_{1}, \ldots , Y^{(2)}_{n_2}\) is a sample from the distribution \(\mathscr {N}\left(a_{2}, \sigma^{2}\right)\), \(Y^{(3)}_1, \ldots , Y^{(3)}_{n_3}\) is a sample from the distribution \(\mathscr {N}\left(a_{3}, \sigma^{2}\right)\). Construct the \(F\)-test of size \(\alpha\) for testing the hypothesis a) \(H_{0}: a_{1}=a_{2}\) and \(a_{1}+a_{2}=a_{3}\), b) \(H_{0}: a_{1}=2 a_{2}\) and \(a_{1}+3 a_{2}=a_{3}\).
Each part is worth 1 point.
ProblemProblem 5
Solve example Example 5 by computing the constrained least squares estimator.
ProblemProblem 6
Let \(Y^{(1)}_{i} \sim \mathscr {N}\left(a, i\sigma^2\right) , \; i= 1, \ldots , n\), \(Y^{(2)}_{j} \sim \mathscr {N}\left(jb, \sigma^{2}\right), j=1, \ldots , m\) be independent random variables, where \(a\), \(b\), \(\sigma^{2}\) are unknown one-dimensional parameters. Reduce the problem to a linear model and construct the \(F\)-test of size \(\alpha\) for testing the hypothesis \(H_{0}: a+b=1\).
ProblemProblem 7
Using the method of linear regression, construct an approximation of the function \(f(t)\) by a third-degree polynomial \(a_0 + a_1t + a_2t^2 + a_3t^3\) from the following data:
Data for approximating \(f(t)\) by the cubic polynomial \(a_0+a_1t+a_2t^2+a_3t^3\)
Test the hypothesis \(H_0: a_1 = a_2 = a_3 = 0\) at significance level
\(10\%\);
\(5\%\);
\(1\%\);
ProblemProblem 8
Let \(X_{i j} \sim \mathscr {N}\left(\mu_{j}, \sigma^{2}\right), i=1, \ldots , n_{j}, j=1, \ldots , k,-\) be independent random variables, and \(\left\{ \mu_{j}\right\}_{j=1}^{k}, \sigma^{2}\) be unknown parameters. Denote \(N=\sum_{j=1}^{k} n_{j}\). For testing the homogeneity hypothesis \(H_{0}: \mu_{1}=\ldots =\mu_{k}\), the \(F\)-test of one-way analysis of variance is used, with the following statistic \[
F =\frac{\frac{1}{k-1} \sum _{j=1}^{k} n_{j}\left(X_{. j}-X_{. .}\right)^{2}}{\frac{1}{N-k} \sum _{j=1}^{k} \sum _{i=1}^{n_{j}}\left(X_{i j}-X_{. j}\right)^{2}},
\] where \[
X_{. j}=\frac{1}{n_{j}} \sum _{i=1}^{n_{j}} X_{i j}, \qquad X_{. .}=\frac{1}{N} \sum _{j=1}^{k} n_j X_{. j} = \frac{1}{N}\sum _{j=1}^k\sum _{i=1}^{n_j} X_{ij},
\] i.e. \(X_{\cdot j}\) is the sample mean within observation group \(j\), and \(X_{\cdot \cdot }\) is the overall sample mean over all \(N\) observations (a weighted average of the group means with weights \(n_j\)). The expression \(\sum_{j=1}^{k} n_{j}\left(X_{. j}-X_{. .}\right)^{2}\) in the numerator of \(F\) can be interpreted as a measure of between-group spread. The expression \(\sum_{i=1}^{n_{j}}\left(X_{i j}-X_{. j}\right)^{2}\) in the denominator is a measure of spread within group \(j\).
Prove that under \(H_{0}\) we have \(F \sim \operatorname {F}_{k-1, N-k}\).
This problem is worth 3 points.
3 (*) Classical tests as special cases of the linear model
The material of this chapter (together with the chapter on linear regression) is enough to “read” almost the entire standard set of tests built into statistical packages. For concreteness we will focus on the Excel add-in “Analysis ToolPak”; the tools linked to the linear Gaussian model in it are:
three \(t\)-tests: “Paired two-sample \(t\)-test for means”, “Two-sample \(t\)-test assuming equal variances”, “Two-sample \(t\)-test assuming unequal variances”;
“Two-sample \(z\)-test for means”;
“Two-sample \(F\)-test for variances”;
three variants of analysis of variance: “One-way ANOVA”, “Two-way ANOVA with replication”, “Two-way ANOVA without replication”;
“Regression”.
Almost all of them are special cases of the \(F\)-test from this chapter, applied to a suitable linear model (and the few exceptions — Welch’s test and the \(F\)-test for variances — are assembled from the same “building blocks” of Cochran’s theorem). Let us go through them one by one.
3.1 The \(t\)-form of the \(F\)-test for one-dimensional hypotheses
All the \(t\)-statistics listed above are “square roots” of \(F\)-statistics. The following theorem gives this precise meaning.
Theorem 2 Suppose that in the linear Gaussian model \(\overrightarrow {X} = \mathbf{z}\overrightarrow {\theta } + \overrightarrow {\varepsilon }\) we test a one-dimensional (\(m = 1\)) linear hypothesis: \(\mathbf{w} \in \mathbb {R}^{\tilde{k}}\) is a column, \(\tau_0 \in \mathbb {R}\), \[
H_0: \mathbf{w}^T\overrightarrow {\theta } = \tau _0.
\] Denote \(\widehat{\tau } := \mathbf{w}^T\widehat{\overrightarrow {\theta }}\), \(b := \mathbf{w}^T\left(\mathbf{z}^T\mathbf{z}\right)^{-1}\mathbf{w} > 0\), \(\widehat{\sigma^2} := \operatorname {RSS}/(n - \tilde{k})\). Then, under \(H_0\), the statistic \[
T := \frac{\widehat{\tau } - \tau _0}{\sqrt{b \, \widehat{\sigma ^2}}} \sim T_{n - \tilde{k}},
\] and the \(F\)-statistic for this hypothesis equals \(F = T^2\).
ExampleExample 7
Prove the theorem.
SolutionSolution
The estimator \(\widehat{\overrightarrow {\theta }} \sim \mathscr {N}\left(\overrightarrow {\theta }, \sigma^2\left(\mathbf{z}^T\mathbf{z}\right)^{-1}\right)\), so its linear transformation \(\widehat{\tau } = \mathbf{w}^T\widehat{\overrightarrow {\theta }}\) is a one-dimensional Gaussian variable: \[
\widehat{\tau } \sim \mathscr {N}\left(\mathbf{w}^T\overrightarrow {\theta }, \sigma ^2 \mathbf{w}^T\left(\mathbf{z}^T\mathbf{z}\right)^{-1}\mathbf{w}\right) = \mathscr {N}\left(\mathbf{w}^T\overrightarrow {\theta }, \sigma ^2 b\right).
\] Under \(H_0\) we have \(\mathbf{w}^T\overrightarrow {\theta } = \tau_0\), whence \[
\frac{\widehat{\tau } - \tau _0}{\sqrt{\sigma ^2 b}} \sim \mathscr {N}\left(0, 1\right).
\] By Cochran’s theorem the statistics \(\widehat{\overrightarrow {\theta }}\) (a function of \(\overrightarrow {X}_L\)) and \(\operatorname {RSS}\) (a function of \(\overrightarrow {X}_{L^\perp }\)) are independent, and \[
\frac{n - \tilde{k}}{\sigma ^2}\widehat{\sigma ^2} = \frac{\operatorname {RSS}}{\sigma ^2} \sim \chi ^2_{n - \tilde{k}}.
\] By the definition of Student’s distribution (see the chapter on linear regression) \[
T = \frac{\left(\widehat{\tau } - \tau _0\right)/\sqrt{\sigma ^2 b}}{\sqrt{\frac{\operatorname {RSS}}{\sigma ^2} \Big/ (n - \tilde{k})}} = \frac{\widehat{\tau } - \tau _0}{\sqrt{b\, \widehat{\sigma ^2}}} \sim T_{n - \tilde{k}}.
\] Finally, for \(m = 1\) the matrix \(\mathbf{b}\) is the number \(b\), and \[
F = \frac{\left(\widehat{\tau } - \tau _0\right) b^{-1} \left(\widehat{\tau } - \tau _0\right)/1}{\operatorname {RSS}/(n - \tilde{k})} = \frac{\left(\widehat{\tau } - \tau _0\right)^2}{b \, \widehat{\sigma ^2}} = T^2.
\]
Recall (see the chapter on linear regression) that as the number of degrees of freedom \(\nu\) grows, Student’s distribution \(T_\nu\) approaches \(N(0,1)\) — for large samples the difference between the \(t\)-test and the \(z\)-test disappears, and the “heaviness” of the tails of \(T_\nu\) matters primarily for small \(n\).
The density of Student’s distribution \(T_\nu\) compared with \(N(0,1)\): the more degrees of freedom \(\nu\), the thinner the tails and the closer the curve is to the normal one. Move the \(\nu\) slider to see how the curve “flows” into the standard normal; the switch below highlights the two-sided critical tail of level \(\alpha\) and shows how the critical value of \(t\) changes with \(\nu\).
t critical (two-tailed) =
A test of significance level \(\alpha\) based on \(T\) against the two-sided alternative \(H_1: \mathbf{w}^T\overrightarrow {\theta } \neq \tau_0\) coincides with the \(F\)-test:
The advantage of the \(t\)-form is that, unlike \(F = T^2\), it “sees the sign” of the deviation, and thus allows testing one-sided alternatives as well, \(H_1: \mathbf{w}^T\overrightarrow {\theta } > \tau_0\) (the test \(\left\{ T > Q_{T_{n-\tilde{k}}}(1 - \alpha )\right\}\)) and \(H_1: \mathbf{w}^T\overrightarrow {\theta } < \tau_0\) (the test \(\left\{ T < Q_{T_{n-\tilde{k}}}(\alpha )\right\}\)). This is exactly why Excel’s output for the \(t\)-tests gives a pair of values: “\(t\) Critical one-tail” and “\(t\) Critical two-tail” (and the corresponding \(p\)-values).
ProblemProblem 9
(Duality of tests and confidence intervals.) Under the conditions of theorem Theorem 2, show that the two-sided \(t\)-test of significance level \(\alpha\) does not reject \(H_0: \mathbf{w}^T\overrightarrow {\theta } = \tau_0\) if and only if \(\tau_0\) is covered by the confidence interval of confidence level \(1 - \alpha\) for \(\mathbf{w}^T\overrightarrow {\theta }\): \[
\left(\widehat{\tau } - Q_{T_{n-\tilde{k}}}\left(1 - \tfrac {\alpha }{2}\right)\sqrt{b\widehat{\sigma ^2}}, \; \; \widehat{\tau } + Q_{T_{n-\tilde{k}}}\left(1 - \tfrac {\alpha }{2}\right)\sqrt{b\widehat{\sigma ^2}}\right).
\] Thus, one-dimensional hypotheses can be tested “by eye” — via the confidence interval.
3.2 One-sample \(t\)-test
Given a sample \(X_1, \ldots , X_n\) from \(\mathscr {N}\left(\theta , \sigma^2\right)\) (both parameters unknown), we test \(H_0: \theta = \theta_0\). We have already encountered this model in example Example 1 about the coffee machine:
Here \(\widehat{\sigma^2} = \operatorname {RSS}/(n-1) = s^2\) is the unbiased sample variance, and theorem Theorem 2 gives the statistic familiar from the chapter on confidence intervals
In example Example 1 we already saw it in action (and the relation \(F = T^2\)).
In the “Analysis ToolPak” there is no separate button for the one-sample test: it is obtained from the paired test below if a column of constants \(\theta_0\) is supplied as the second “sample”.
ExampleExample 8
A power bank manufacturer advertises a capacity of \(10000\) mA\(\cdot\)h. A tech blogger measured the actual capacity of \(6\) units: \[
9450, \quad 9800, \quad 10150, \quad 9300, \quad 9650, \quad 9550 \quad (\text{mA}\cdot \text{h}).
\] Assuming the capacity is Gaussian, test at significance levels \(5\%\) and \(1\%\) the hypothesis \(H_0: \theta = 10000\) against the one-sided alternative \(H_1: \theta < 10000\) (“the capacity is overstated”; a deviation in the other direction obviously does not concern the buyer).
SolutionSolution
We have \[
\overline{X} = 9650, \qquad s^2 = \frac{1}{5}\sum _{i=1}^6\left(X_i - 9650\right)^2 = 89000, \qquad s \approx 298.3,
\]\[
T = \frac{\overline{X} - 10000}{\sqrt{s^2/6}} = \frac{-350}{121.8} \approx -2.87.
\] The alternative is left-sided, so the critical region is the left tail \(\left\{ T < Q_{T_5}(\alpha )\right\}\). We have \(Q_{T_5}(0.05) \approx -2.02\), \(Q_{T_5}(0.01) \approx -3.36\) and \[
-3.36 < -2.87 < -2.02,
\] so at significance level \(5\%\) the hypothesis is rejected (the capacity is significantly less than advertised), while at significance level \(1\%\) it cannot be rejected; the \(p\)-value equals \(\mathbb {P}\left(T_5 < -2.87\right) \approx 1.7\%\).
AnswerAnswer
\(T \approx -2.87 < Q_{T_5}(0.05) \approx -2.02\): at significance level \(5\%\) we reject (the capacity is overstated); at \(1\%\) we cannot reject (\(p \approx 1.7\%\)).
ProblemProblem 10
In example Example 1 we tested the coffee machine against a two-sided alternative and could not reject \(H_0\) at significance level \(1\%\). But the skeptic from the example is only concerned about underpouring. Using the same data, test the hypothesis \(H_0: \theta = 200\) against the one-sided alternative \(H_1: \theta < 200\) at significance level \(1\%\).
3.3 Paired \(t\)-test
The tool “Paired two-sample \(t\)-test for means”. The data are \(n\)pairs\((X_i, Y_i)\): two measurements on the same object (before/after treatment, left/right eye, two instruments on the same part). Within a pair the measurements are dependent, so the two-independent-samples model does not apply. Instead, let us pass to the differences:
and the hypothesis “there is no effect” becomes \(H_0: \delta = \delta_0\) (usually \(\delta_0 = 0\); Excel allows specifying a “hypothesized mean difference”). This is the one-sample \(t\)-test for \(\overrightarrow {D}\):
What is the gain of the paired scheme? If each object has its own individual level \(\mu_i\), i.e. \(X_i = \mu_i + \xi_i\), \(Y_i = \mu_i - \delta + \eta_i\), then in the differences \(D_i = \delta + (\xi_i - \eta_i)\) the individual levels cancel out: the between-object spread of \(\mu_i\) does not enter the variance of the statistic.
ExampleExample 9
Pulse (beats/min) was measured before and after a cup of espresso from the machine for \(8\) students:
Before
68
74
81
62
90
71
66
78
After
75
75
87
61
95
73
74
78
Assuming the differences are Gaussian, test the hypothesis “coffee has no effect on pulse” at significance level \(5\%\).
so at significance level \(5\%\) the hypothesis is rejected: coffee significantly speeds up the pulse (by \(3.5\) beats/min on average); the \(p\)-value \(\mathbb {P}\left(\left|T_7\right| > 2.89\right) \approx 2.3\%\). At significance level \(1\%\) we could not have rejected it (\(Q_{T_7}(0.995) \approx 3.50\)).
It is instructive to see what would happen if we applied a two-sample test (next section) to the same data, ignoring the pairing: \(\overline{X^{\text{after}}} - \overline{X^{\text{before}}} = 3.5\) — the same, but the between-individual spread of pulse (from \(61\) to \(95\) beats/min) enters the variance estimate: \(s_p \approx 9.6\), \(T \approx 0.73\), \(p \approx 48\%\) — no effect visible at all. The paired scheme removes this spread and makes the effect visible.
AnswerAnswer
Paired \(t\)-test: \(T \approx 2.89\), \(p \approx 2.3\%\) — the hypothesis is rejected (whereas a two-sample test would not have detected the effect: \(p \approx 48\%\)).
ProblemProblem 11
A chip-tuning service promises reduced fuel consumption. For \(6\) cars the average consumption (l\(/100\) km) was measured before and after reflashing:
Before
8.9
10.2
7.8
9.5
11.1
8.4
After
8.5
9.9
7.9
9.0
10.5
8.2
Assuming the differences are Gaussian, test at significance level \(5\%\) the hypothesis “reflashing changes nothing” against the alternative “consumption decreases”.
HintHint
Paired \(t\)-test with a one-sided alternative.
3.4 Two-sample \(t\)-test: equal variances
The tool “Two-sample \(t\)-test assuming equal variances”. The data are two independent samples with a common unknown variance:
we test \(H_0: a_1 - a_2 = \delta_0\) (usually \(\delta_0 = 0\): “the means are equal”).
This is exactly the model from example Example 3 about weighing coins: \(\tilde{k} = 2\), \(\mathbf{w} = (1, -1)^T\), and, as computed in example Example 5,
where \(s_i^2\) are the unbiased sample variances. The estimator \(s_p^2\) is called the pooled variance: both samples are combined into a common “pool” for estimating \(\sigma^2\). By theorem Theorem 2
and the \(F\)-statistic from example Example 5 is its square (for \(\delta_0 = 0\)).
ExampleExample 10
An online store redesigned its checkout form and ran an A/B test: a random half of visitors were shown the old form, the rest the new one. Checkout time (seconds): \[
\begin{align} \text{old } (n_1 = 10)& : \quad 104, \; 111, \; 72, \; 94, \; 104, \; 107, \; 101, \; 108, \; 98, \; 100 \\ \text{new } (n_2 = 12)& : \quad 87, \; 75, \; 77, \; 88, \; 80, \; 96, \; 97, \; 101, \; 85, \; 97, \; 77, \; 78 \end{align}
\] Assuming the samples are Gaussian with a common variance, test at significance level \(1\%\) the hypothesis that the mean checkout time has not changed.
SolutionSolution
Different visitors are in the groups (each saw exactly one form), the samples are independent — a paired scheme is impossible in principle here, this is a genuine two-sample problem. We have \[
\overline{X^{(1)}} = 99.9, \qquad \overline{X^{(2)}} = 86.5, \qquad s_1^2 \approx 121.2, \qquad s_2^2 \approx 86.6.
\] The variances are close, so we apply the test with pooled variance: \[
s_p^2 = \frac{9 s_1^2 + 11 s_2^2}{20} \approx 102.2, \qquad T = \frac{99.9 - 86.5}{s_p\sqrt{\frac{1}{10} + \frac{1}{12}}} = \frac{13.4}{10.11 \cdot 0.428} \approx 3.10.
\] Since \(\left|T\right| = 3.10 > Q_{T_{20}}(0.995) \approx 2.85\), the hypothesis is rejected even at significance level \(1\%\): the new form speeds up checkout (by \(13\) seconds on average); the \(p\)-value \(\approx 0.6\%\).
AnswerAnswer
\(\left|T\right| \approx 3.10 > Q_{T_{20}}(0.995) \approx 2.85\): rejected even at significance level \(1\%\) (\(p \approx 0.6\%\)) — the new form is faster.
3.4.1 (*) Effect size: Cohen’s \(d\)
The \(p\)-value only answers the question “is there an effect” (more precisely, whether the data are compatible with “no effect”), but says nothing about how large the effect is. Because of this, a small, practically insignificant effect with a large sample yields just as small a \(p\)-value as a large effect with a small sample — statistical significance mixes up the effect size with the sample size. The standard way to separate one from the other is to convert the difference of means into dimensionless units by dividing it by the spread of the data.
Definition 2Cohen’s \(d\) effect size for comparing two independent samples with a common variance is the standardized difference of the sample means: \[
\widehat{d} := \frac{\overline{X^{(1)}} - \overline{X^{(2)}}}{s_p},
\] where \(s_p\) is the square root of the pooled variance defined above.
By construction, \(\widehat{d}\) is the difference of means measured in “number of standard deviations”: \(\widehat{d} = 1\) means that the means differ by one \(s_p\). Unlike the \(T\)-statistic, \(\widehat{d}\) does not depend explicitly on the sample sizes \(n_1, n_2\) — it is a feature of the data themselves (of the effect size), not of the precision of its measurement. This is exactly why, as the sample grows, the \(T\)-statistic and the associated \(p\)-value can grow arbitrarily, while \(\widehat{d}\) (for the same true effect) stays put.
J. Cohen proposed conventional benchmarks for interpreting \(\left|d\right|\) in the behavioral and social sciences: \(d \approx 0.2\) is a small effect, \(d \approx 0.5\) a medium one, \(d \approx 0.8\) and above a large one. These thresholds are conventional and depend on the subject area — in physics, for example, effects of \(d = 0.2\) are usually of no interest, while in psychology they are considered quite noticeable.
ExampleExample 11
Find Cohen’s \(d\) for the A/B test from example Example 10.
SolutionSolution
From the solution of example Example 10: \(\overline{X^{(1)}} = 99.9\), \(\overline{X^{(2)}} = 86.5\), \(s_p^2 \approx 102.2\), whence \(s_p \approx 10.11\). Then \[
\widehat{d} = \frac{99.9 - 86.5}{10.11} = \frac{13.4}{10.11} \approx 1.33.
\] By Cohen’s benchmarks this is a large effect: the new checkout form is not only statistically significantly but also practically substantially faster than the old one — the difference in mean checkout time exceeds one standard deviation within each group.
AnswerAnswer
\(\widehat{d} \approx 1.33\).
Cohen’s effect size \(\hat d = \dfrac{\overline{X}^{(1)}-\overline{X}^{(2)}}{s_p}\) for the A/B test (old and new checkout form): two Gaussian distributions shifted by \(\hat d\) standard deviations. Move the \(d\) slider to see how the overlap of the distributions changes with the effect size, and how this same quantity relates to intuitive metrics: the overlap fraction (% overlap), the probability of superiority and the NNT. The default value \(d\approx1.33\) is exactly the one from the example in the text.
The tool “Two-sample \(t\)-test assuming unequal variances”. If \(\sigma_1^2 \neq \sigma_2^2\), then homoscedasticity — the key condition of our linear model (\(\operatorname {Var}\left[\overrightarrow {\varepsilon }\right] = \sigma^2\mathbf{I}_n\)) — is violated, and the entire machinery of this chapter stops working. There is no exact analogue of theorem Theorem 2 here (this is the famous Behrens–Fisher problem), but there is a good approximation — the Welch test:
(the Welch–Satterthwaite approximation: a number of degrees of freedom \(\nu\) is chosen so that Student’s distribution best approximates the true distribution of the denominator). The number \(\nu\) is usually non-integer, \(\min (n_1, n_2) - 1 \leq \nu \leq n_1 + n_2 - 2\); Excel’s output rounds it to an integer.
Practical remarks. When \(s_1^2 \approx s_2^2\) and \(n_1 \approx n_2\), the statistics and conclusions of the two two-sample tests almost coincide. If, however, the variances differ noticeably (especially with different \(n_i\)), the test with pooled variance can badly misstate the significance level, while Welch’s test remains approximately honest. Hence the modern practical recommendation: if in doubt about equality of variances, use Welch’s test right away.
ExampleExample 12
A restaurant is comparing two delivery services. “Courier” delivers predictably, “economy” is cheaper, but hit or miss. Delivery time (minutes): \[
\begin{align} \text{courier } (n_1 = 12)& : \quad 47, \; 53, \; 36, \; 53, \; 45, \; 41, \; 41, \; 40, \; 44, \; 49, \; 48, \; 48 \\ \text{economy } (n_2 = 6)& : \quad 26, \; 29, \; 85, \; 74, \; 96, \; 79 \end{align}
\] Test at significance level \(5\%\) the hypothesis of equal mean delivery times.
The variances differ by more than a factor of \(30\) — the assumption of a common \(\sigma^2\) is obviously unreasonable here, so we apply Welch’s test. Denote \(u := s_1^2/n_1 = 27.5/12 \approx 2.29\) and \(v := s_2^2/n_2 = 891.0/6 = 148.5\):
Since \(\left|T_W\right| = 1.58 < Q_{T_{5.2}}(0.975) \approx 2.55\), the hypothesis cannot be rejected (\(p \approx 17\%\)): yes, “economy” took on average \(19\) minutes longer, but with such a spread and only \(6\) observations this could easily be chance.
It is instructive that the test with pooled variance on the same data would give \(T \approx -2.25\) and \(p \approx 3.9\%\) — “significant”! The pooled estimate \(s_p^2 \approx 297\) averages the huge variance of “economy” with the small variance of “courier” and overstates the precision of the comparison; a small sample with a large variance is the worst case for it. Welch’s test protects against this mistake.
AnswerAnswer
Welch’s test: \(T_W \approx -1.58\), \(\nu \approx 5.2\), \(p \approx 17\%\) — cannot be rejected (whereas the test with pooled variance would give a falsely “significant” \(p \approx 3.9\%\)).
ProblemProblem 12
Prove the bounds for Welch’s number of degrees of freedom: \[
\min (n_1, n_2) - 1 \; \leq \; \nu \; \leq \; n_1 + n_2 - 2.
\]
HintHint
Denote \(u = s_1^2/n_1\), \(v = s_2^2/n_2\) and apply the Cauchy–Schwarz inequality.
3.6\(z\)-tests: known variances
The tool “Two-sample \(z\)-test for means”. If the variances \(\sigma_1^2, \sigma_2^2\) are known (Excel asks you to enter them by hand), then there is no need to estimate \(\sigma^2\), no Studentization is required, and under \(H_0: a_1 - a_2 = \delta_0\) the statistic has an exact normal distribution:
Note: here \(\sigma_1^2 \neq \sigma_2^2\) is allowed — the problem of the previous section arose only from estimating the variances. The one-sample variant is analogous: \(Z = \sqrt{n}\left(\overline{X} - \theta_0\right)/\sigma \sim \mathscr {N}\left(0, 1\right)\).
When can the variance be considered known? Either it is specified in the measuring instrument’s specification sheet (calibrated by the manufacturer on a huge amount of material), or the samples are large enough that \(s_i^2\) can be substituted for \(\sigma_i^2\): then the \(z\)-test is asymptotic (by the CLT it, incidentally, does not even require normality of the samples), and the \(t\)-tests for large \(n\) practically coincide with it (\(T_n \xrightarrow [n \to \infty ]{d} \mathscr {N}\left(0, 1\right)\)).
ExampleExample 13
On a packaging line two dispensers pour sugar into “\(1\) kg” bags. The precision of a dispenser is known from its specification sheet: the bag mass is Gaussian with standard deviation \(\sigma = 5\) g. Over a shift, \(n_1 = n_2 = 40\) bags were sampled from each dispenser; the mean masses were \(\overline{X^{(1)}} = 1002.1\) g and \(\overline{X^{(2)}} = 999.3\) g (the operator did not keep the raw data). Test at significance level \(5\%\) whether the dispensers are set the same.
SolutionSolution
The variances are known — this is a \(z\)-test, and, conveniently, apart from the two means no other data is needed: \[
Z = \frac{1002.1 - 999.3}{\sqrt{\frac{25}{40} + \frac{25}{40}}} = \frac{2.8}{1.118} \approx 2.50.
\] Since \(\left|Z\right| = 2.50 > Q_{\mathscr {N}\left(0, 1\right)}(0.975) \approx 1.96\), at significance level \(5\%\) the hypothesis is rejected: the dispensers are set to different average weights (\(p\)-value \(\approx 1.2\%\)). Note how small the “significant” difference is — \(2.8\) g with \(\sigma = 5\) g: samples of \(40\) bags make the test sensitive to small discrepancies. Significance is not the same thing as practical importance: whether a difference of \(2.8\) g matters is a question for the process engineer, not for statistics.
AnswerAnswer
\(\left|Z\right| \approx 2.50 > 1.96\): rejected, the dispensers are set differently (\(p \approx 1.2\%\)).
3.7\(F\)-test for equality of variances
The tool “Two-sample \(F\)-test for variances”. Here the hypothesis is no longer about the mean, but about the variances of two independent normal samples: \(H_0: \sigma_1^2 = \sigma_2^2\). From the chapter on linear regression we know (essentially — from Cochran’s theorem for the constant-only model) that
The alternative is two-sided (\(\sigma_1^2 \neq \sigma_2^2\)), so we reject if \(F \not\in \left(Q_{\operatorname {F}_{n_1-1,n_2-1}}\left(\frac{\alpha }{2}\right), Q_{\operatorname {F}_{n_1-1,n_2-1}}\left(1 - \frac{\alpha }{2}\right)\right)\). Excel gives a one-sided \(p\)-value \(\mathbb {P}\left(\operatorname {F} > F\right)\) — for a two-sided alternative it needs to be doubled (or, as is often done, the larger variance is put in the numerator in advance).
Two caveats. First, this test is often used to “check equality of variances” in order to choose between the two two-sample \(t\)-tests; such a two-stage procedure distorts the resulting significance level, and it is simpler to just use Welch’s test right away. Second, unlike the \(t\)-tests (fairly robust to non-normality of the samples thanks to the CLT), the \(F\)-test for variances is very sensitive to deviations from normality even for large \(n\).
ExampleExample 14
Next to the old coffee machine from example Example 1 a new one was installed. The same student measured \(8\) espresso servings from the new machine: \[
199, \quad 202, \quad 197, \quad 200, \quad 201, \quad 198, \quad 200, \quad 203 \quad (\text{ml}).
\] Test at significance level \(5\%\) the hypothesis that the machines pour equally consistently (the variances are equal).
SolutionSolution
For the old machine \(s_1^2 = \frac{218}{7} \approx 31.1\) (we already computed the sum of squared deviations \(218\) in example Example 1). For the new one \(\overline{X^{(2)}} = 200\) and \[
s_2^2 = \frac{1}{7}\left(1 + 4 + 9 + 0 + 1 + 4 + 0 + 9\right) = 4.
\] The statistic \[
F = \frac{s_1^2}{s_2^2} = \frac{31.14}{4} \approx 7.79 \sim \operatorname {F}_{7,7} \quad \text{under } H_0.
\] Two-sided quantiles: \(Q_{\operatorname {F}_{7,7}}(0.025) \approx 0.20\) and \(Q_{\operatorname {F}_{7,7}}(0.975) \approx 5.00\); the statistic \(7.79 > 5.00\) falls into the critical region — the hypothesis is rejected: the spread of the old machine is significantly larger (\(p = 2\mathbb {P}\left(\operatorname {F}_{7,7} > 7.79\right) \approx 1.5\%\)). Note: underpouring (a shift in the mean) and instability (spread) are different defects, tested by different tests; as it turns out, the old machine is guilty of both.
AnswerAnswer
\(F \approx 7.79 > Q_{\operatorname {F}_{7,7}}(0.975) \approx 5.00\): rejected, the new machine is more consistent (\(p \approx 1.5\%\)).
ProblemProblem 13
For two independent normal samples, construct a confidence interval of confidence level \(1 - \alpha\) for the ratio of variances\(\sigma_1^2/\sigma_2^2\). Compute it for the two coffee machines from example Example 14 (\(1 - \alpha = 0.95\)).
HintHint
Find a pivotal statistic: a quantity distributed as \(\operatorname {F}_{n_1-1,n_2-1}\) for any\(\sigma_1^2, \sigma_2^2\).
3.8 Analysis of variance (ANOVA)
“One-way analysis of variance” is exactly problem Problem 8: \(k\) independent groups of observations with a common variance, the homogeneity hypothesis \(H_0: \mu_1 = \ldots = \mu_k\) (\(m = k - 1\) linear constraints), the statistic
(between-group spread against within-group spread). Excel outputs a table with \(\operatorname {SS}\), \(\operatorname {df}\), \(\operatorname {MS} = \operatorname {SS}/\operatorname {df}\), \(F\), the \(p\)-value, and the critical value.
ProblemProblem 14
Show that for \(k = 2\) one-way analysis of variance coincides with the two-sample \(t\)-test (with equal variances, \(\delta_0 = 0\)): the \(F\)-statistic of the analysis of variance equals \(T^2\).
we reject the homogeneity hypothesis (\(p\)-value \(\approx 1.2\%\)): the branches perform differently, and, judging by the means, Branch B is “lagging.”
Careful with the interpretation: analysis of variance only says that not all means are equal, but does not say which ones differ. Proper pairwise comparisons after the overall \(F\)-test are a separate topic (multiple comparisons, corrections such as Bonferroni), beyond the scope of this note.
AnswerAnswer
\(F \approx 6.59 > Q_{\operatorname {F}_{2,12}}(0.95) \approx 3.89\): rejected (\(p \approx 1.2\%\)) — judging by the means, Branch B stands out.
ProblemProblem 15
Three seminar groups wrote the same test, scoring the following points (out of \(10\)):
Group 1
6
8
8
8
9
5
Group 2
6
5
6
8
6
7
Group 3
4
7
5
9
8
8
The instructor of group 1 is proud that their group did best. Test the hypothesis of homogeneity across the groups at significance level \(5\%\).
ProblemProblem 16
(Analysis of variance as regression.) Show that one-way analysis of variance is the \(F\)-test of overall significance of the regression (problem Problem 2) for a model with \(k - 1\)dummy regressors for group membership: \[
X = \theta _0 + \theta _1 \; \mathbb {1}_{\text{group } 2} + \ldots + \theta _{k-1}\; \mathbb {1}_{\text{group } k} + \varepsilon .
\]
This problem is worth 2 points.
Two-way analysis of variance generalizes the picture: observations are classified by two factors at once (for example, crop yield: variety \(\times\) fertilizer). In the balanced model “with replication,” \(r\) observations are made in each cell \((i, j)\):
where \(\alpha_i\) is the effect of level \(i\) of the first factor, \(\beta_j\) of the second, \(\gamma_{ij}\) their interaction, and for identifiability the constraints \(\sum_i \alpha_i = \sum_j \beta_j = \sum_i \gamma_{ij} = \sum_j \gamma_{ij} = 0\) are imposed. This is again a linear Gaussian model, and the hypotheses “the first factor has no effect” (\(H_0^{A}\): all \(\alpha_i = 0\)), “the second has no effect” (\(H_0^{B}\)), “there is no interaction” (\(H_0^{AB}\)) are linear hypotheses of the form \(\mathbf{w}^T\overrightarrow {\theta } = \overrightarrow {0}\), to which the general theory applies. Let us write out the answer (the derivation is a direct, though cumbersome, application of the scheme of this chapter via the constrained least squares estimator; we leave it to the reader as an exercise of increased effort). In terms of the cell means \(\overline{X}_{ij\cdot }\), the factor-level means \(\overline{X}_{i\cdot \cdot }, \overline{X}_{\cdot j \cdot }\) and the overall mean \(\overline{X}\):
(the statistics \(F_B, F_{AB}\) are built from \(\operatorname {SS}_{B}, \operatorname {SS}_{AB}\) analogously). The tool “without replication” is the case \(r = 1\): the interaction is then indistinguishable from noise (there is one observation per cell), so the model is taken to be additive (\(\gamma_{ij} = 0\)), and the role of \(\operatorname {SS}_{E}\) is played by the residual sum \(\operatorname {SS}_{\text{res}} = \sum_{i,j}\left(X_{ij} - \overline{X}_{i\cdot } - \overline{X}_{\cdot j} + \overline{X}\right)^2\) with \((a-1)(b-1)\) degrees of freedom.
ProblemProblem 17
An agronomist compares three wheat varieties on three fields with different soil. Each variety is sown once on each field; yield (centner/ha):
Field I
Field II
Field III
Variety A
33
36
42
Variety B
27
34
35
Variety C
26
27
31
Using two-way analysis of variance without replication, test at significance level \(5\%\) the hypotheses: a) “variety has no effect on yield”; b) “field has no effect on yield”.
3.9 The “Regression” tool
The last and most substantive tool of the “Analysis ToolPak” fits a model with an intercept \(\overrightarrow {X} = \mathbf{z}\overrightarrow {\theta } + \overrightarrow {\varepsilon }\), \(\tilde{k} = k + 1\), and outputs three blocks, all assembled from the results of the chapters on linear regression and on hypothesis testing. Denote, as usual, \(\left(\mathbf{z}^T\mathbf{z}\right)^{-1} = (a_{i,j})\), \(\widehat{\sigma^2} = \operatorname {RSS}/(n - \tilde{k})\).
Block “Regression Statistics”: the coefficient of determination “\(R\) Square” \(R^2 = \operatorname {ESS}/\operatorname {TSS}\); “Multiple \(R\)” \(= \sqrt{R^2}\) (as we will see in the chapter on correlation coefficients, this is the sample correlation between \(\overrightarrow {X}\) and \(\widehat{\overrightarrow {X}}\)); “Standard Error” \(= \sqrt{\widehat{\sigma^2}}\); “Adjusted \(R\) Square”
— a version of \(R^2\) penalized for the number of regressors: ordinary \(R^2\) never decreases when any regressor is added, even a useless one, whereas \(R^2_{adj}\) can decrease (unbiased estimators of the residual and response variances are used instead of biased ones).
Block “ANOVA”: rows “Regression” / “Residual” / “Total” with \(\operatorname {df} = k, \; n - k - 1, \; n-1\) and \(\operatorname {SS} = \operatorname {ESS}, \operatorname {RSS}, \operatorname {TSS}\); the statistic
— the \(F\)-test of overall significance of the regression (“do the regressors explain anything at all”), familiar to us from problem Problem 2 (there also — its expression in terms of \(R^2\)); “Significance \(F\)” is its \(p\)-value.
Table of coefficients, one row per parameter \(\theta_j\) (including the intercept — “\(Y\) Intercept”): the estimator \(\widehat{\theta }_j\); its standard error\(\operatorname {se}_j := \sqrt{a_{j,j}\widehat{\sigma^2}}\); “\(t\) Stat”
— a test of significance of an individual coefficient: this is theorem Theorem 2 with \(\mathbf{w} = \overrightarrow {e}_j\), \(\tau_0 = 0\), \(b = a_{j,j}\); the (two-sided) “\(P\)-value” and the bounds of the confidence interval \(\widehat{\theta }_j \pm Q_{T_{n - \tilde{k}}}\left(1 - \frac{\alpha }{2}\right)\operatorname {se}_j\) at confidence level \(95\%\) (coincides with the interval from the chapter on linear regression).
ExampleExample 16
Run the taxi ride data from example Example 2 through the “Regression” tool and read the output.
SolutionSolution
The tool’s output (all numbers recomputed from the formulas above):
Figure 1
Figure 2
Coeff.
Std. error
\(t\)-stat.
\(P\)-value
Lower\(95\%\)
Upper\(95\%\)
\(Y\)-intercept
\(108.27\)
\(16.71\)
\(6.48\)
\(0.0013\)
\(65.31\)
\(151.23\)
\(d\) (km)
\(32.08\)
\(1.90\)
\(16.92\)
\(1.0 \cdot 10^{-5}\)
\(27.20\)
\(36.95\)
Let us read it.
The model explains the data excellently: \(R^2 \approx 0.983\) (and \(R^2_{adj} \approx 0.979\) is not far behind), the typical spread of price around the line — “Standard Error” \(\sqrt{\widehat{\sigma^2}} \approx 21.4\) rubles.
“Significance \(F\)” \(\approx 10^{-5}\): the hypothesis “distance has no effect on price at all” (\(\theta_1 = 0\)) is soundly rejected — as expected. Note: for \(k = 1\) this \(F\)-test is equivalent to the \(t\)-test of the single coefficient, and indeed \(F = 286.25 = 16.92^2 = t_1^2\), and the \(p\)-values coincide.
Looking at the coefficient rows: both are significantly different from zero. The confidence interval for the pickup fee \((65.3, \; 151.2)\) covers the advertised \(100\) rubles, and the interval for the per-kilometer price \((27.2, \; 36.9)\) covers the advertised \(30\) rubles/km. That is, coefficient by coefficient there is no complaint about the fare.
Compare with example Example 2, where the joint hypothesis \((a, b) = (100, 30)\) gave \(p \approx 6.2\%\) — much closer to the boundary. There is no contradiction: the joint \(F\)-test looks at both parameters at once (its “confidence region” is an ellipse in the \((a,b)\) plane, accounting for the negative correlation between the estimators \(\widehat{a}\) and \(\widehat{b}\)), and the point \((100, 30)\) lies close to the boundary of this ellipse, even though it falls freely into the rectangle formed by the two separate intervals. We saw the reverse effect in problem Problem 7 about cubic regression: there each coefficient is insignificant by the \(t\)-test (multicollinearity inflates the standard errors), while the joint\(F\)-test does see the effect. Moral: coefficient-by-coefficient \(t\)-tests and the joint \(F\)-test answer different questions, and one must not substitute one for the other.
3.10 Summary
Let us gather the section’s glossary into one table (\(s^2\), \(s_i^2\), \(s_D^2\) are unbiased sample variances, \(s_p^2\) is the pooled variance, \(\widehat{\sigma^2} = \operatorname {RSS}/(n - \tilde{k})\)):
The same tests under the same names live in every statistical package: in python these are scipy.stats.ttest_1samp, ttest_rel (paired), ttest_ind (two-sample; the equal_var flag switches between pooled variance and Welch), f_oneway (one-way analysis of variance), and statsmodels OLS (the full regression output); in R — t.test, var.test, aov, lm/summary.