Document Sample

Running HLM using Proc Mixed Lan Xue 1 This work focuses on fitting hierarchical linear models with PROC MIXED (SAS). It is based on the SAS help menu and a paper by Sawako Suzuki and Ching-Fang Sheu (see reference). It contains three parts: the first part discusses the notations used in PROC MIXED, especially the understandings of RANDOM and SUBJECT options in PROC MIXED; the second part discusses several examples illustrated in Sawako Suzuki and Ching-Fang Sheu, we further discuss why those SAS code are used; the third part summaries some helpful simple steps to write the SAS code for a HLM. Part 1: Notations used in SAS proc Mixed. Y X Z e Here, is an unknown vector of fixed-effects parameters with known design matrix X, is an unknown vector of random-effects parameters with known design matrix Z, is an unknown random error vector . In Proc Mixed, (1) Model part defines the fixed effects, so the design matrix X will be determined. (2) Random part defines the random effects, so Z will be determined. (3) Subject gives the classifying (Blocking) variable. We will see the difference between with Subject command and without Subject command in the next example. Example: The data consists of the test scores and IQ score of the students from 3 classes. There are 10 students in each class. Our total samples size is 30. Code1, With subject command: proc mixed data=rc; class class; model Score = IQ / s; random intercept IQ / type=un sub=Class s; run; Code2, without subject command: proc mixed data=rc; class class; model Score = IQ / s; random intercept IQ / type=un s; 1 The author was supported by the assistantship from Statistics Consulting Service and under the supervision of Prof. Connie Page. run; Since the two codes have the same model statement, they will have the same design matrix for the fixed effects: X which is a 30 2 matrix with 1 and the IQ score for i-th student as its i-th row. But the Z matrix will be different. Z matrix for the first code, Z1 is a 30 6 matrix defined as follows: 1 q1,1 0 0 0 0 . . 0 0 0 0 1 q 0 0 0 0 1,10 0 0 1 q 2,1 0 0 0 Z1 = 0 0 . . 0 0 0 1 q 2,10 0 0 0 0 0 0 1 q3,1 0 0 0 0 . . 0 0 0 0 1 q3,10 But the Z matrix for the second code, Z2 is a 30 2 matrix same as X. 1 q1,1 1 . 1 q 1,10 1 q 2,1 . Z2= 1 1 q 2,10 1 q3,1 1 . 1 q 3,10 Part 2: SAS codes for HLM. Level Name Factor and Covariate 1 ----i Student Pretest Score 2 ----j Class NA 3 ----k School Condition (4 levels) Example1: HLM: we consider 3-level HLM with only random coefficient for interceptor. y ijk = 0 jk + 1 * PS + i ( j ( k )) Student level, coefficient of PS is fixed, but coefficient of interceptor is allowed to be varying across the classes (School). 0 jk = 0 k + j (k ) Class level, no predictor available at this level and the coefficient of interceptor is allowed to be varying across School. 0k = 0 + 2 * CC 3 * TV 4 * CCTV + k School level, with factor: Condition (4 levels). So, put those three level models together, we have, y ijk = 0 + 1 * PS + 2 * CC 3 * TV 4 * CCTV + k + j (k ) + i ( j ( k )) Here the fixed coefficients are: 0 , 1 , 2 , 3 , 4 the random are: k , j (k ) As what is given in the paper. SAS code: In the above example, we have fixed effects: Intercept, PS, CC, TV, CCTV. So the determined corresponding design matrix for fixed effects X is a N 5 matrix, with (1, i-th student’s pretest score, arrangement of the conditions on the student) as its i-th row. Then our model statement in Proc Mixed, should be: Model Y = PS CC TV CCTV; Secondly, in the above example, we have K+J*K random effects: k k 1,...,K j ( k ) j 1,..., J k 1,... K So, if we put them together in the vector form, define I k be the indicator variable for k-th school. k=1,…K. I j{k ) be the indicator variable for j(k) class. j=1,…J, k=1,…,K K Y = 0 * I + 1 * PS + 2 * CC 3 * TV 4 * CCTV + k 1 k * Ik + j {k ) * I j (k ) + E j ,k Then we can see that, Z= ( I 1 , I 2 ,…., I k ,I 1(1) ,…, I J ( K ) ) r= ( 1 , …, k , 1(1) , …., J ( K ) ) So to generate the indicators I k k=1,…K, the random statement with Sub= School is needed. Random Intercept / Sub = School ; Another option is: Random School ; Since School is defined in Class statement, the indicator variables at each level of school will be automatically generated. To generate the indicators I j{k ) , the random statement with Sub= Class (School) needed. Random Intercept / Sub= Class(School); Similarly, another option is: Random Class(School); Finally, our SAS code for this 3 level HLM with only random coefficient for interceptor is: proc Mixed; class class school condition; model Y= PS CC TV CCTV ; random Intercept / Sub = School; random Intercept / Sub = Class(School); run; Or proc Mixed; class class school condition; model Y= PS CC TV CCTV ; random School; random Class(School); run; Example 2: The same data as above, if we allow the coefficient of Pretest Score (PS) is random too. Consider the following 3 level HLM: y ijk = 0 jk + 1 jk * PS + i ( j ( k )) 0 jk = 0 k + j (k ) 1 jk = 1k + j (k ) 0 k = 0 + 02 * CC 03 * TV 04 * CCTV + k 1k = 1 + k After putting them together, we have y ijk = 0 + 1 *PS + 02 * CC 03 * TV 04 * CCTV + k + j (k ) + j (k ) *PS + k *PS + i ( j ( k )) Here the fixed coefficients are: 0 , 1 , 02 , 03 , 04 The random are : k , k , j (k ) , j (k ) The design matrix for fix effects: X should be a N 5 matrix as, X= (1, PS, CC, TV,CCTV) And the design matrix for random effects Z of the form: Z= ( I 1 , I 1 *PS, I 2 ,I 2 *PS,…., I k ,I k *PS, I 1(1) , I 1(1) *PS,…, I J ( K ) ,I J ( K ) *PS) r= ( 1 , 1 ,…, k , , k , 1(1) , 1(1) ,…., J ( K ) , J (k ) ) So the SAS code should be: Proc Mixed; class class school condition; model Y= PS CC TV CCTV ; random Intercept PS / Sub = School; random Intercept PS/ Sub = Class(School); run; Part3: Discussion Because of the nested structure of the HLM, in the random statement, the subject command is very useful to generate the needed design matrix. There are some simple rules we can apply to use subject command for the HLM. (1). Write the models for different level together (2). Put the random effects in the same level together, for example y ijk = 0 + 1 *PS + 02 * CC 03 * TV 04 * CCTV + k + k *PS random effects at school level + j (k ) + j (k ) *PS random effects at class level + i ( j ( k )) (3). Then use the Random statement for each level separately, using subject equals to the corresponding level and the effects are the effects exist in that level. random Intercept PS/ subject = school; random Intercept PS/ subject = class; References [1] SAS help menu 8.0 [2] Using PROC MIXED in Hierarchical Linear Models: Examples from two- and three- level school-effect analysis, and meta-analysis research, Sawako Suzuki & Ching- Fan Sheu, Depaul University, Chicago.

DOCUMENT INFO

Shared By:

Categories:

Tags:

Stats:

views: | 6 |

posted: | 3/5/2012 |

language: | English |

pages: | 6 |

OTHER DOCS BY xiuliliaofz

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.