next up previous index
Next: Parameter Estimation: The Least Up: Linear Models Previous: General Overview   Index

Click for printer friendely version of this HowTo

Setting up Y and X

Setting Y is always a strait forward procedure: you simply fill the vector with the measured values. Setting up X, the design matrix, however, depends on the type of data you have as well as the model you are trying to fit. All of this is best explained with a series of examples.

no_titleno_title

Example 3.13.2.2 (no_title)  

First we will show how to set up the design matrix when there is a single independent variable involved.

If we are given the data,

\begin{displaymath}
\begin{array}{c\vert c}
y & x\\
\hline
1 & 0\\
4 & 1\\
5 & 2
\end{array},
\end{displaymath}

and the function we wish to fit using least squares is,

$\displaystyle y = \beta_0 +
\beta_1x,
$

then

$\displaystyle {\bf Y} =
\left [ \begin{array}{cc}
1\\
4\\
5
\end{array} \righ...
...bf X} =
\left [ \begin{array}{cc}
1 & 0\\
1 & 1\\
1 & 2
\end{array} \right].
$

The column of 1s in X represents $ \beta_0 \times 1 = \beta_0$.

If the equation we wanted to fit was quadratic,

$\displaystyle y = \beta_0 +
\beta_1x + \beta_2x^2,
$

then

$\displaystyle {\bf Y} =
\left [ \begin{array}{cc}
1\\
4\\
5
\end{array} \righ...
... [ \begin{array}{ccc}
1 & 0 & 0\\
1 & 1 & 1\\
1 & 2 & 4
\end{array} \right].
$

If the equation was

$\displaystyle \beta_0\sin(x) + \beta_1x^2,
$

then

$\displaystyle {\bf Y} =
\left [ \begin{array}{cc}
1\\
4\\
5
\end{array} \righ...
...egin{array}{cc}
\sin(0) & 0\\
\sin(1) & 1\\
\sin(2) & 4
\end{array} \right].
$

In general, for the table of data,

\begin{displaymath}
\begin{array}{c\vert c}
y & x\\
\hline
y_1 & x_1\\
y_2 & x_2\\
\vdots & \vdots\\
y_m & x_m
\end{array},
\end{displaymath}

and any function that is linear with respect to the coefficients,

$\displaystyle y = \beta_0f_0(x) + \beta_1f_1(x) + \cdots + \beta_nf_n(x),
$

then

$\displaystyle {\bf X} =
\left [ \begin{array}{cccc}
f_0(x_0) & f_1(x_0) & \cdot...
...ddots & \vdots\\
f_0(x_m) & f_1(x_m) & \cdots & f_n(x_m)
\end{array} \right].
$

$ \vert\boldsymbol{\vert}$

no_titleno_title

Example 3.13.2.4 (no_title)  

If we are given a dataset that contains multiple independent variables, for example:

\begin{displaymath}
\begin{array}{c\vert c\vert c\vert c}
y & x_1 & x_2 & x_3 ...
...0\\
4 & 1 & 2.3 & 0.0010\\
5 & 2 & 7.5 & 0.0004
\end{array},
\end{displaymath}

and we want to find a fit for the function

$\displaystyle y = \beta_0 + \beta_1 x_1
+ \beta_2 x_2 + \beta_3 x_3,
$

then you would end up with

$\displaystyle {\bf Y} =
\left [ \begin{array}{c}
1\\
4\\
5
\end{array} \right...
... & 0.2300\\
1 & 1 & 2.3 & 0.0010\\
1 & 2 & 7.5 & 0.0004
\end{array} \right].
$

$ \vert\boldsymbol{\vert}$

no_titleno_title

Example 3.13.2.6 (no_title)  

Sometimes the independent variable is a list of treatments and the dependent variable consists of a list of values measured after each treatment. For example, if you have the data set,

\begin{displaymath}
\begin{array}{c\vert c\vert c}
\textrm{Treatment 1}&\textrm{...
...& 15.2\\
12.8 & 9.7 & 15.0\\
13.5 & 10.2 & 15.8
\end{array},
\end{displaymath}

we can still use a linear model,

$\displaystyle y = \beta_1x_1 + \beta_2x_2 + \beta_3x_3
$

and estimate the parameters $ \beta_1$, $ \beta_2$ and $ \beta_3$. However, in this case, $ x_i$ consists of a 0 or a 1, depending on which treatment a given $ y$ value was collected from. Thus,

$\displaystyle {\bf Y} =
\left [ \begin{array}{c}
13.2\\
12.8\\
13.5\\
10.4\\...
...1 & 0\\
0 & 1 & 0\\
0 & 0 & 1\\
0 & 0 & 1\\
0 & 0 & 1
\end{array} \right].
$

For a discussion of alternative design matrices (some of which are used, for historical reasons, more often than this one) for this type of data set, see Appendix E. $ \vert\boldsymbol{\vert}$


next up previous index
Next: Parameter Estimation: The Least Up: Linear Models Previous: General Overview   Index

Click for printer friendely version of this HowTo

Frank Starmer 2004-05-19
>