In statistics and in particular in regression analysis, a design matrix, also known as model matrix or regressor matrix and often denoted by X, is a matrix of values of explanatory variables of a set of objects. Each row represents an individual object, with the successive columns corresponding to the variables and their specific values for that object. The design matrix is used in certain statistical models, e.g., the general linear model.[1] [2] [3] It can contain indicator variables (ones and zeros) that indicate group membership in an ANOVA, or it can contain values of continuous variables.
The design matrix contains data on the independent variables (also called explanatory variables), in a statistical model that is intended to explain observed data on a response variable (often called a dependent variable). The theory relating to such models uses the design matrix as input to some linear algebra : see for example linear regression. A notable feature of the concept of a design matrix is that it is able to represent a number of different experimental designs and statistical models, e.g., ANOVA, ANCOVA, and linear regression.
The design matrix is defined to be a matrix
X
Xij
X
A regression model may be represented via matrix multiplication as
y=X\beta+e,
\beta
e
The design matrix has dimension n-by-p, where n is the number of samples observed, and p is the number of variables (features) measured in all samples.[4] [5]
In this representation different rows typically represent different repetitions of an experiment, while columns represent different types of data (say, the results from particular probes). For example, suppose an experiment is run where 10 people are pulled off the street and asked 4 questions. The data matrix M would be a 10×4 matrix (meaning 10 rows and 4 columns). The datum in row i and column j of this matrix would be the answer of the i th person to the j th question.
The design matrix for an arithmetic mean is a column vector of ones.
This section gives an example of simple linear regression—that is, regression with only a single explanatory variable—with seven observations.The seven data points are, for i = 1, 2, …, 7. The simple linear regression model is
yi=\beta0+\beta1xi+\varepsiloni,
\beta0
\beta1
\begin{bmatrix}y1\ y2\ y3\ y4\ y5\ y6\ y7\end{bmatrix} =\begin{bmatrix}1&x1\\1&x2\\1&x3\\1&x4\\1&x5\\1&x6\ 1&x7\end{bmatrix} \begin{bmatrix}\beta0\ \beta1\end{bmatrix} + \begin{bmatrix}\varepsilon1\ \varepsilon2\ \varepsilon3\\ \varepsilon4\ \varepsilon5\ \varepsilon6\ \varepsilon7\end{bmatrix}
This section contains an example of multiple regression with two covariates (explanatory variables): w and x.Again suppose that the data consist of seven observations, and that for each observed value to be predicted (
yi
yi=\beta0+\beta1wi+\beta2xi+\varepsiloni
\begin{bmatrix}y1\ y2\ y3\ y4\ y5\ y6\ y7\end{bmatrix}=\begin{bmatrix}1&w1&x1\\1&w2&x2\\1&w3&x3\\1&w4&x4\\1&w5&x5\\1&w6&x6\ 1&w7&x7\end{bmatrix} \begin{bmatrix}\beta0\ \beta1\ \beta2\end{bmatrix} + \begin{bmatrix}\varepsilon1\ \varepsilon2\ \varepsilon3\\ \varepsilon4\ \varepsilon5\ \varepsilon6\ \varepsilon7\end{bmatrix}
Here the 7×3 matrix on the right side is the design matrix.
This section contains an example with a one-way analysis of variance (ANOVA) with three groups and seven observations. The given data set has the first three observations belonging to the first group, the following two observations belonging to the second group and the final two observations belonging to the third group.If the model to be fit is just the mean of each group, then the model is
yij=\mui+\varepsilonij
\begin{bmatrix}y1\ y2\ y3\ y4\ y5\ y6\ y7\end{bmatrix}=\begin{bmatrix}1&0&0\\1&0&0\ 1&0&0\ 0&1&0\ 0&1&0\ 0&0&1\ 0&0&1\end{bmatrix} \begin{bmatrix}\mu1\ \mu2\ \mu3\end{bmatrix} + \begin{bmatrix}\varepsilon1\ \varepsilon2\ \varepsilon3\\ \varepsilon4\ \varepsilon5\ \varepsilon6\ \varepsilon7\end{bmatrix}
\mui
i
The ANOVA model could be equivalently written as each group parameter
\taui
yij=\mu+\taui+\varepsilonij
\tau1
\begin{bmatrix}y1\ y2\ y3\ y4\ y5\ y6\ y7\end{bmatrix}=\begin{bmatrix}1&0&0\\1&0&0\ 1&0&0\ 1&1&0\ 1&1&0\ 1&0&1\ 1&0&1\end{bmatrix} \begin{bmatrix}\mu\ \tau2\ \tau3\end{bmatrix} + \begin{bmatrix}\varepsilon1\ \varepsilon2\ \varepsilon3\\ \varepsilon4\ \varepsilon5\ \varepsilon6\ \varepsilon7\end{bmatrix}
\mu
\taui
i
\tau1