14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

166 Data Structures Chapter 7<br />

Matrices<br />

Next, add a column of 1s to the design matrix for the intercept term. You can do this by concatenating J<br />

and Design Nom(), as follows:<br />

x = J(9,1,1) || designNom(factor);<br />

[1 1 0,<br />

1 0 1,<br />

1 -1 -1,<br />

1 1 0,<br />

1 0 1,<br />

1 -1 -1,<br />

1 1 0,<br />

1 0 1,<br />

1 -1 -1]<br />

Now, to solve the normal equation, you need to construct a matrix M with partitions:<br />

X′X X′y<br />

y′X y′y<br />

You can construct matrix M in one step by concatenating the pieces, as follows:<br />

M=(x`*x || x`*y)<br />

|/<br />

(y`*x || y`*y);<br />

[ 9 0 0 27,<br />

0 6 3 2,<br />

0 3 6 1,<br />

27 2 1 93]<br />

Now, sweep M over all the columns in X′X for the full fit model, and over the first column only for the<br />

intercept-only model:<br />

FullFit=sweep(M,[1,2,3]); // full fit model<br />

InterceptOnly=sweep(M,[1]); // model with intercept only<br />

Recall that some of the standard ANOVA results are calculated by comparing the results of these two<br />

models. This example focuses on the full fit model, which produces this swept matrix:<br />

[0.111111111111111 0 0 3,<br />

0 0.222222222222222 -0.11111111111111 0.333333333333333,<br />

0 -0.11111111111111 0.222222222222222 0,<br />

-3 -0.33333333333333 0 11.33333333333333]<br />

Examine the model coefficients from the upper right partition of the matrix. The lower left partition is the<br />

same, except that the signs are reversed: 3, 0.333, 0. The results can be interpreted as follows:<br />

• The coefficient for the intercept term is 3.<br />

• The coefficient for the first level of the factor is 0.333.<br />

• The coefficient for the second level is 0.<br />

• Because of the use of Design Nom(), the coefficient for the third level is the difference, –0.333.<br />

• The lower right partition of the matrix holds the sum of squares, 11.333.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!