Solution
First, \(\text{rank}(Z) = 2\). We’re told in part a) that \(\text{colsp}(Z) = \text{colsp}(X)\), so \(\text{rank}(Z) = \text{rank}(X)\). I find it easier to think in terms of \(X\) since the numbers are more straightforward.
Remember, throughout this part, that each \(x_i\) is either 1 or 0! This means that the column \(\vec x^{(1)} = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}\) is made up of 1’s and 0’s, and the column \(\vec x^{(2)} = \begin{bmatrix} x_1^2 \\ x_2^2 \\ \vdots \\ x_n^2 \end{bmatrix}\) is made up of 1’s and 0’s in the same positions, since \(1^2 = 1\) and \(0^2 = 0\).
So, \(X\) only really has two unique columns, and its rank is 2. But since \(\text{rank}(Z) = \text{rank}(X)\), we have \(\text{rank}(Z) = 2\). \(Z\) doesn’t have any repeated columns, but as we showed above, it’s still the case that one of \(Z\)’s columns is a linear combination of the other two.
The only case in which \(\text{rank}(Z) = 1\) is if all of the \(x_i\) are the same, but the matrix \(P\) tells us that that is not the case.
Let’s now look at the matrix \(P\). Notice that rows 1, 2, and 4 of \(P\) are identical, as are rows 3 and 5. Let’s imagine some vector \(\vec y \in \mathbb{R}^5\). What would multiplying \(P\) by \(\vec y\) give us?
$$ P \vec y = \begin{bmatrix} 1/3 & 1/3 & 0 & 1/3 & 0 \\\\ 1/3 & 1/3 & 0 & 1/3 & 0 \\\\ 0 & 0 & 1/2 & 0 & 1/2 \\\\ 1/3 & 1/3 & 0 & 1/3 & 0 \\\\ 0 & 0 & 1/2 & 0 & 1/2 \end{bmatrix} \begin{bmatrix} y_1 \\\\ y_2 \\\\ y_3 \\\\ y_4 \\\\ y_5 \end{bmatrix} = \begin{bmatrix} \frac{1}{3}y_1 + \frac{1}{3}y_2 + \frac{1}{3}y_4 \\\\ \frac{1}{3}y_1 + \frac{1}{3}y_2 + \frac{1}{3}y_4 \\\\ \frac{1}{2}y_3 + \frac{1}{2}y_5 \\\\ \frac{1}{3}y_1 + \frac{1}{3}y_2 + \frac{1}{3}y_4 \\\\ \frac{1}{2}y_3 + \frac{1}{2}y_5 \end{bmatrix} = \begin{bmatrix} \text{mean of } y_1, y_2, y_4 \\\\ \text{mean of } y_1, y_2, y_4 \\\\ \text{mean of } y_3, y_5 \\\\ \text{mean of } y_1, y_2, y_4 \\\\ \text{mean of } y_3, y_5 \end{bmatrix} $$
We know from Chapter 1 that the mean is the constant that minimizes mean squared error. Here, it appears that the prediction returned in \(\vec y\) is not always the same, but is one of two possibilities — rows 1, 2, and 4 have the same prediction, and rows 3 and 5 have the same prediction. This hints to us that rows 1, 2, and 4 come from the same \(x_i\) value, and rows 3 and 5 come from the same \(x_i\) value, and the optimal prediction is some conditional mean. This resembles Lab 9, Activity 2, on one hot encoding with beef, chicken, and fish.
The above observation alone is enough information to answer the question. The two possible answers are \(\boxed{x_1 = 1, x_2 = 1, x_3 = 0, x_4 = 1, x_5 = 0}\) and \(\boxed{x_1 = 0, x_2 = 0, x_3 = 1, x_4 = 0, x_5 = 1}\).
Let’s dive deeper into the math to confirm this. Let’s start with what \(X\) would have had to be. (We can work with \(X\) instead of \(Z\) since both have the same column spaces, so projecting onto either column space will give us the same result; \(X\) is just easier to work with.) And, let’s drop \(\vec x^{(2)}\) from \(X\), since including it will prevent \(X^TX\) from being invertible while not changing \(\text{colsp}(X)\).
$$ X = \begin{bmatrix} 1 & 1 \\\\ 1 & 1 \\\\ 1 & 0 \\\\ 1 & 1 \\\\ 1 & 0 \end{bmatrix} $$
Note that I arbitrarily picked \(x_1 = x_2 = x_4 = 1\) and \(x_3 = x_5 = 0\), but we could reverse the 1’s and 0’s and \(P\) would turn out to be the same.
The formula for the projection matrix is \(P = X (X^TX)^{-1}X^T\). I won’t include all of the algebra here, but if you work out \(P = X (X^TX)^{-1}X^T\), you’ll find that \(P\) is indeed the matrix provided in the problem.
Here’s one final interpretation of what’s going on. Suppose the optimal parameters for this \(X\) and some \(\vec y\) are \(\vec w^{\ast} = \begin{bmatrix} w_0^{\ast} \\ w_1^{\ast} \end{bmatrix}\), which would lead to a hypothesis function of
$$ h(x_i) = w_0^* + w_1^* x_i $$
This hypothesis function only returns one of two values:
If \(x_i = 1\), then \(h(1) = w_0^{\ast} + w_1^{\ast}\)
If \(x_i = 0\), then \(h(0) = w_0^{\ast}\)
So, \(w_0^{\ast}\) is the mean of the \(y\)’s when \(x_i = 0\), and \(w_0^{\ast} + w_1^{\ast}\) is the mean of the \(y\)’s when \(x_i = 1\). This is exactly what we see in the matrix \(P\).