A.17. Construction of a Design Matrix

Often, we may need to create a design matrix (usually denoted by X in linear models contexts) corresponding to a given experimental design. The function DESIGN will provide such a matrix. This is best illustrated by an example.

Suppose we want the design matrix corresponding to a one-way classification model with three groups. The sample sizes are n1 =3,n2 =2 and n3 = 5. As a result, n=n1+n2+n3= 10. What one needs to do is to define a column vector titled ADDRESS which provides the addresses for all nonzero entries (all of which would be 1) in the individual rows. For instance, if the seventh entry in the column ADDRESS is 3 then in the seventh row of resulting matrix X a '1' will be placed in the third column and zero elsewhere.

Suppose we want the design matrix without a column corresponding to the intercept. Then, for our example, we define the vector ADDRESS as a column vector by using the SAS statement

address = {1,1,1,  2,2,  3,3,3,3,3;

and then define

x_w_out = design(address);

An alternative way to obtain the column address would be to use the J function, which can be very handy if matrix X were too big. Specifically, we could use

address = j(n1,1,1)  //  j(n2,1,2)  //  j(n3,1,3);

To obtain the design matrix with a column for intercept, we could pre-augment the matrix X_W_OUT with the corresponding column, namely a column of 1 everywhere or in SAS notation, with the matrix J(N,1,1). Specifically, the new design matrix is X_WITH given by the SAS statement

x_with = j(n,1,1)||x_w_out;

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.183.172