# Two-Sample Hotelling's $T^2$ test example work through.

Let $\textrm{x}_{11},\ldots,\textrm{x}_{1n_1}$ and $\textrm{x}_{21},\ldots,\textrm{x}_{2n_2}$ be two observed samples where $\textrm{x}_{ij}$ is a $p$ vector from $\sim N_p (\mu_1,\Sigma)$ and $\sim N_p(\mu_2,\Sigma)$ for the two samples respectevely.

From these samples I can find: $\bar{\textrm{x}}_1,\bar{\textrm{x}}_2,S_1,S_2$

where $$S_1=\frac{1}{n_1} \sum_j (\textrm{x}_{1j}-\bar{\textrm{x}}_1)(\textrm{x}_{1j}-\bar{\textrm{x}}_1)'$$ $$S_2=\frac{1}{n_2} \sum_j (\textrm{x}_{2j}-\bar{\textrm{x}}_2)(\textrm{x}_{2j}-\bar{\textrm{x}}_2)'$$ I have that if I let $\mu_1-\mu_2=\delta,$ $$\bar{\textrm{x}}_1-\bar{\textrm{x}}_2 \sim N_p\left( \delta, \frac{n_1+n_2}{n_1n_2}\Sigma \right)$$

Assume weighted covariance matrix $S=\frac{1}{n_1+n_2}(n_1S_1+n_2S_2)$.

How is the $S$ distributed? I know it should be Wishart distribution, but I'm not sure how. I think that $n_1S_1 \sim (n_1,\Sigma)$ or $(n_1-1,S_1)$ if $S_1$ is an estimate of $\Sigma$ and the same argument for $n_2S_2 \sim (n_2,\Sigma)$ My guess is: $S\sim (n_1+n_2-2,\Sigma)$, but I don't fully understand why.

Now I'm having trouble with with $T^2$ distribution. My notes only tell me what to do when $\textrm{x}\sim N(\mu,\Sigma)$. But in our case $\bar{\textrm{x}}_1-\bar{\textrm{x}}_2 \sim N_p(\delta, \frac{n_1+n_2}{n_1n_2}\Sigma)$. Thus I tried to bring it into the form $N(\mu,\Sigma)$.

$$\frac{\sqrt{n_1n_2}(\bar{\textrm{x}}_1-\bar{\textrm{x}}_2)}{\sqrt{n_1+n_2}} \sim N_p(\delta, \Sigma)$$ and by the theorem in the book I should try:

$$t^2=(n_1+n_2-2) \left(\frac{\sqrt{n_1n_2} (\bar{\textrm{x}}_1-\bar{\textrm{x}}_2)}{\sqrt{n_1+n_2}} -\delta\right) S^{-1} \left( \frac{\sqrt{n_1n_2} (\bar{\textrm{x}}_1-\bar{\textrm{x}}_2)}{\sqrt{n_1+n_2}}-\delta\right)'$$

But my book has the solution:

$$t^2=\frac{n_1n_2(n_1+n_2-2)}{(n_1+n_2)^2}(\bar{\textrm{x}}_1-\bar{\textrm{x}}_2-\delta)S^{-1}(\bar{\textrm{x}}_1-\bar{\textrm{x}}_2-\delta)'\sim T^2_{p,n_1+n_2-2}$$

Let $y_{1j}$ be the first row of the $p\times n$ matrix whose columns are $x_{11},\ldots,x_{1,n_1}\in\mathbb R^p$, and what we say about it will apply just as much to any of the rows.

The vector $y_{1j} - \bar y _1$ is the orthogonal projection of a vector in $\mathbb R^n$ onto the $(n-1)$-dimensional subspace defined by saying the sum of the coefficients is $0$. Consider an orthonormal basis of that subspace, plus one additional unit vector orthogonal to that subspace. Being orthogonal to that subspace means all of its components are equal. In that basis, the mapping $$y_{1j} \mapsto y_{1j} - \bar y_1 \tag 1$$ where $\operatorname{E} y_{1j} = (\mu,\ldots,\mu)$ and $\operatorname{E} (y_{1j} - \bar y_1) = (0,\ldots,0)$ becomes $$(u_1,\ldots,u_n) \mapsto (0,u_2,u_3,\ldots,u_n)$$ where $\operatorname{E}(u_1,u_2,\ldots,u_n) = (\mu\sqrt n,0,\ldots,0)$ and $\operatorname{E} (0,u_2,u_3,\ldots,u_n) = (0,0,\ldots,0)$.

Then $u_2^2+u_3^2+\cdots + u_n^2\sim \chi^2_{n-1}$, or in other words the sum of the squares of all $n$ components of $(1)$ has that distribution.

And as with the chi-square distribution, so also (in this case) with the Wishart distribution.

• Thanks, I tried to work through this, but encountered a few problems: what is $\bar y_1$? To me, I thought it's logically $\sum_j y_ij/n$. However, the $Y$ matrix has $n$ columns, while the $X$ matrix has $n_1$ columns. Does it mean I have to extend $X=(x_{1,1},...,x_{1,n_1},x_{2,1},...,x_{2,n_2})$? Then if $\bar y_1$ is just a number, I can't find $E(y_{1j}-\bar y_1)=(0,...,0)$. Also I don't see the connection between this, and the $T^2$ test
– GRS
Aug 29, 2016 at 18:35
• $$\begin{bmatrix} x_{11}, \ldots, x_{1,n_1} \end{bmatrix} = \begin{bmatrix} y_{11}, & \ldots, & y_{1,n_1} \\ y_{21}, & \ldots, & y_{2,n_1} \\ \vdots & & \vdots \\ y_{p1}, & \ldots, & y_{p,n_1} \end{bmatrix}.$$ $$\bar y_1 = \text{the average of the entries in the first row above.}$$ Aug 29, 2016 at 19:09
• $$y_{11}^2 + y_{12}^2 + \cdots + y_{1,n_1}^2 = u_1^2+u_2^2 + u_3^2 + \cdots + u_{n_1}^2$$ $$(y_{11} - \bar y_1)^2 + \cdots + (y_{1,n_1} - \bar y_1)^2 = u_2^2 + u_3^2 +\cdots + u_{n_1}^2$$ Aug 29, 2016 at 19:12