Vector Matrix Notation
Vector matrix notation with binary variables
Now let’s write this same model in vector-matrix notation. We need to specify vectors \mathbf{Y}, \boldsymbol{\beta} and \boldsymbol{\epsilon} and design matrix \mathbf{X}.
If we let i=1, \ldots, n, we can see that we have n equations:
\begin{aligned} y_1 & =\alpha+\beta I_{x_1}+\epsilon_1 \\
y_2 & =\alpha+\beta I_{x_2}+\epsilon_2 \\
&\vdots \\
y_n & = \alpha+\beta I_{x_n}+\epsilon_n \end{aligned}
where, for i=1,\ldots,n,
\beta I_{x_i}=
\begin{cases}
\beta \hspace{0.5cm} \mbox{if } x_i=1 \\
0 \hspace{0.5cm} \mbox{if } x_i=0.
\end{cases}
Now suppose that m out of the n observations have x_i=1 and the remaining n-m observations have x_i=0. We may group these data such that
\begin{aligned} y_1 & =\alpha+\beta +\epsilon_1 \\
y_2 & =\alpha+\beta +\epsilon_2 \\
&\vdots \\
y_m & =\alpha+\beta +\epsilon_m \\
y_{m+1} & =\alpha +\epsilon_{m+1} \\
&\vdots \\
y_n & = \alpha+\epsilon_n \end{aligned}
We group all the observations, y_i, into an n dimensional vector Y, and the errors \epsilon_i into another column vector \boldsymbol{\epsilon}:
\begin{aligned}
\mathbf{Y} =&\left(
\begin{array}{c}
y_{1} \\
\vdots \\
y_{m} \\
y_{m+1} \\
\vdots \\
y_{n} \\
\end{array}
\right),
\quad \quad \quad \quad \boldsymbol{\epsilon} &= \left(
\begin{array}{c}
\epsilon_{1} \\
\vdots \\
\epsilon_{m} \\
\epsilon_{m+1} \\
\vdots \\
\epsilon_{n} \\
\end{array}
\right).\\
\end{aligned}
Similarly, we stack the two parameters, \alpha and \beta, into another column vector:
\begin{aligned}
\boldsymbol{\beta} &=&\left(
\begin{array}{c}
\alpha \\
\beta
\end{array}
\right)\end{aligned}
Finally, we append a vector of ones with the single predictor for each i, and create a matrix with two columns of the following form:
\begin{aligned}\mathbf{X}&=&\left(
\begin{array}{cc}
1 & 1 \\
\vdots & \vdots \\
1 & 1\\
1 & 0 \\
\vdots & \vdots \\
1 & 0
\end{array}
\right).
\end{aligned}
such that when we multiply
\mathbf{X} by \boldsymbol{\beta}
\mathbf{X}\boldsymbol{\beta} = \left( \begin{array}{c} \alpha +\beta \\ \vdots \\ \alpha +\beta \\ \alpha \\ \vdots \\ \alpha \end{array} \right).\\