# Writing $\beta$ and X for a qualitative model

Express the following model in matrix form, ie: specify $$\beta$$ and $$X$$ so that the model can be written as $$Y = X \beta + \epsilon$$.

The model $$Y_{ij} = \mu_i + \epsilon_i$$ where $$Y_{ij}$$ represents the $$j$$-th observation observed at level $$i$$ of a qualitative explanatory variable $$T$$, for $$i=0,...,4$$ and $$j=1,2$$.

I know how to write the vector $$\beta$$ (just a column of $$\mu_0$$ to $$\mu_4$$), but how do you write the matrix X?

## 1 Answer

Write $$\tilde{Y}$$ as a vector of length $$10,$$ by stacking $$Y_{01},Y_{02},Y_{11},Y_{12},...,Y_{42}.$$ Similarly define $$\tilde{\varepsilon}.$$ You are now looking for a $$10\times 5$$ matrix $$X$$.

$$\beta^T=(\mu_0,\mu_1,\mu_2,\mu_3,\mu_4)$$

$$X=\begin{bmatrix}1&0&0&0&0\\ 1&0&0&0&0\\ 0&1&0&0&0\\ 0&1&0&0&0\\ 0&0&1&0&0\\ 0&0&1&0&0\\ 0&0&0&1&0\\ 0&0&0&1&0\\ 0&0&0&0&1\\ 0&0&0&0&1\end{bmatrix}$$

Then $$\tilde{Y}=X\beta+\tilde{\varepsilon}$$ is an expression of $$Y_{ij}=\mu_i+\varepsilon_{ij}.$$

If instead you had $$Y_{ij}=\mu_0+\mu_i+\varepsilon_{ij},$$ $$\tilde{Y}$$ and $$\tilde{\varepsilon}$$ will have length $$8.$$ Then

$$X=\begin{bmatrix}1&1&0&0\\ 1&1&0&0\\ 1&1&0&0\\ 1&1&0&0\\ 1&0&1&0\\ 1&0&1&0\\ 1&0&0&1\\ 1&0&0&1\end{bmatrix}$$

will be your design matrix so that $$\tilde{Y}=X\beta+\tilde{\varepsilon}.$$

• I understand that, my problem was with how to construct the design matrix X. I know it is made up of 1's and 0's, and that the first column is just 1's, but how do you determine the other entries? – Student_1996 Apr 20 at 21:03
• The first column will not be all $1$'s in the form you wrote. To get $Y_{ij}=\mu_i+\epsilon_{ij},$ take $X_{ij}=1$ and $0$ otherwise. See if this helps. – Arnab Auddy Apr 20 at 22:00
• I still don't understand for which cases the ij-th entry is 1? – Student_1996 Apr 21 at 8:18
• Sorry I was not clear enough. I have edited the answer. – Arnab Auddy Apr 21 at 19:48