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.

154 Data Structures Chapter 7<br />

Matrices<br />

Create Design Matrices<br />

The Design() function creates a matrix of design columns for a vector or list. There is one column for each<br />

unique value in the vector or list. The design columns have the elements 0 and 1. For example, x below has<br />

values 1, 2, and 3, then the design matrix has a column for 1s, a column for 2s, and a column for 3s. Each<br />

row of the matrix has a 1 in the column representing that row’s value. So, the first row (1) has a 1 in the 1s<br />

column (the first column) and 0s elsewhere; the second row (2) has a 1 in the 2’s column and 0s elsewhere;<br />

and so on.<br />

x=[1, 2, 3, 2, 1];<br />

Design(x);<br />

[1 0 0,<br />

0 1 0,<br />

0 0 1,<br />

0 1 0,<br />

1 0 0]<br />

A variation is the DesignNom() or Design F() function, which removes the last column and subtracts it<br />

from the others. Therefore, the elements of DesignNom() or Design F() matrices are 0, 1, and –1. And<br />

the DesignNom() or Design F() matrix has one less column than the vector or list has unique values.<br />

This operator makes full-rank versions of design matrices for effects.<br />

x=[1, 2, 3, 2, 1];<br />

DesignNom(x);<br />

[1 0,<br />

0 1,<br />

-1 -1,<br />

0 1,<br />

1 0]<br />

DesignNom() is further demonstrated in the “ANOVA Example” on page 165.<br />

To facilitate ordinal factor coding, use the DesignOrd() function. This function produces a full-rank<br />

coding with one less column than the number of unique values in the vector or list. The row for the lowest<br />

value in the vector or list is all zeros. Each succeeding value adds an additional 1 to the row of the design<br />

matrix.<br />

x=[1, 2, 3, 4, 5, 6];<br />

DesignOrd(x);<br />

[0 0 0 0 0,<br />

1 0 0 0 0,<br />

1 1 0 0 0,<br />

1 1 1 0 0,<br />

1 1 1 1 0,<br />

1 1 1 1 1]<br />

Design(), DesignNom(), and DesignOrd() support a second argument that specifies the levels to be<br />

looked up and their order. This feature allows design matrices to be created one row at a time.<br />

• Design(values, levels) creates a design matrix of indicator columns.<br />

• DesignNom(values, levels) creates a full-rank design matrix of indicator columns.<br />

Note the following:<br />

• The values argument can be a single element or a matrix or list of elements.

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

Saved successfully!

Ooh no, something went wrong!