天天看點

Repeated 和 Random選項

Repeated和Random在GLM和Mixed模型中都有涉及。參考随機效應VS固定效應。

隻要沒加Repeated 或 Random的都是固定效應。

1. Repeated in GLM

the REPEATED statement enables you to test hypotheses about the measurement factors (often called within-subject factors) as well as the interactions of within-subjectfactors with independent variables in the MODEL statement (often called between-subject factors).

  1. REPEATED語句就是檢驗within-subject factors和interactions of within-subjectfactors with independent variables的effect。

between-subject effects on the MODEL statement and the main within-subject effect on the REPEATED statement

  1. 也就是說within-subject effect也放在repeated中,between-subject effects 需要放在MODEL中。

資料來自Comparing the SAS GLM and MIXED Procedures for Repeated Measures

data forglm(keep=person gender y1-y4)
formixed(keep=person gender age y);
input person gender$ y1-y4;
output forglm;
y=y1; age=8; output formixed;
y=y2; age=10; output formixed;
y=y3; age=12; output formixed;
y=y4; age=14; output formixed;
datalines;
1 F 21.0 20.0 21.5 23.0
2 F 21.0 21.5 24.0 25.5
3 F 20.5 24.0 24.5 26.0
4 F 23.5 24.5 25.0 26.5
5 F 21.5 23.0 22.5 23.5
6 F 20.0 21.0 21.0 22.5
7 F 21.5 22.5 23.0 25.0
8 F 23.0 23.0 23.5 24.0
9 F 20.0 21.0 22.0 21.5
10 F 16.5 19.0 19.0 19.5
11 F 24.5 25.0 28.0 28.0
12 M 26.0 25.0 29.0 31.0
13 M 21.5 22.5 23.0 26.5
14 M 23.0 22.5 24.0 27.5
15 M 25.5 27.5 26.5 27.0
16 M 20.0 23.5 22.5 26.0
17 M 24.5 25.5 27.0 28.5
18 M 22.0 22.0 24.5 26.5
19 M 24.0 21.5 24.5 25.5
20 M 23.0 20.5 31.0 26.0
21 M 27.5 28.0 31.0 31.5
22 M 23.0 23.0 23.5 25.0
23 M 21.5 23.5 24.0 28.0
24 M 17.0 24.5 26.0 29.5
25 M 22.5 25.5 25.5 26.0
26 M 23.0 24.5 26.0 30.0
27 M 22.0 21.5 23.5 25.0
;

ODS HTML;

proc glm data=forglm;
class gender;
model y1-y4=gender / nouni;
repeated age 4 (8 10 12 14)  / printe;
run;      

between-subject effects on the MODEL statement and the main within-subject effect on the REPEATED statement.

  1. 就是說把重複因素放repeated中,fixed因素放model中。

The NOUNI option suppresses the printing of one-way ANOVAs for each of the four variables。就是說不列印每個Yi的單因素方差分析。

  1. printe是列印 R 矩陣和相關系數矩陣。

1.1

Repeated 和 Random選項
Repeated 和 Random選項

 這是輸入變量的level都是哪些。

1.2

Repeated 和 Random選項
Repeated 和 Random選項

 這是檢查重複測量之間的相關性。零假設是說滿足Type H結構,P值是0.1997,接受原假設,說明是Type H結構。

Repeated 和 Random選項
Repeated 和 Random選項
  1. Type H是符合對稱結構,就是上述結構。即不同測量之間是相關性相同的。

 it is not necessary to make a multivariate assumption about these data. These tests are still valid but are less powerful than the univariate tests given the Type H assumption (Muller et al. 1992)

  1. 在滿足Type H結構下,multivariate的檢驗效能不如univariate tests。

1.3 

Repeated 和 Random選項

上述是within-subject effect, AGE 和 AGE*GENDER的mulvariate 檢驗。

1.4

Repeated 和 Random選項

 上述是between-subject 和 within-subject的effect檢驗。

2. Repeated in MIXED

all fixed effects, both between- and within-subject, on the MODEL statement in PROC MIXED。

  1. 把這些固定效應都放在MODEL中。

The REPEATED statement is used to specify the matrix in the mixed model。

2.1

REPEATED語句是指定R矩陣結構。R是啥,詳見固定效應 VS 随機效應。

  • REPEATED <repeated-effect> </ options>; 

For many repeated measures models, no repeated effect is required in the REPEATED statement. Simply use the SUBJECT= option to define the blocks of and the TYPE= option to define their covariance structure

  1. 在大部分情況下,不需要指定repeated-effect。

到底在 / 之前指定還是不指定 repeated- effect,參考Usage Note 23757: When can I omit the repeated effect (preceding the slash) in the REPEATED statement in PROC MIXED?

假設要在VISIT 1 - VISIT 9個測一次,結果一個subject忘記在VISIT 3測量了,無論VISIT 3這條觀測有沒有存到資料中,隻要在REPEATED指定 repeated-effect,兩次結果都相同。如果不指定,模型參數都有非常輕微不同。

這是因為,如果 VISIT 3壓根沒有, 如果指定<repeated-effect>,模型都會把這條缺失的VISIT 3當作VISIT3. VISIT 4 當作VISIT 4,如果不指定,因為VISIT 3是不存在的,模型會把下一條觀測當作VISIT 3.

總結:

  1. 在有missing data時使用repeated-effect,無論missing data出現在explanatory variables or the dependent variable。
  2. 缺失是某個測量值缺失,或者在某個VISIT忘記的測量,或測量了沒有值,都屬于缺失值。
  3. 如果TYPE = CS,則不需要。因為TYPE = CS是說對同一patient任意兩次測量之間,測量關系(協方差)是相同的。不管資料值是否缺失。
  4. 當使用TYPE = 
    Repeated 和 Random選項
    時,必須使用兩個REPEATED 變量,詳見SAS help.
  5. 很重要的是:在使用repeated時候按subject visit 排下序。
Repeated 和 Random選項
proc mixed data=formixed;
class gender age person;
model y = gender|age;
repeated / type=cs sub=person;
run;      

The SUB= option specifies PERSON to be the subject effect, which instructs PROC MIXED to make the 108 x108 variance-covariance matrix of the entire data vector to be block diagonal with 27 4 x 4 blocks.

Each of these blocks has the covariance structure given by the TYPE= option.

  1. sub = 是說重複測量是測量的哪個unit.

上述資料共有27個人,4次測量,27x4 = 108. 108 x 108方差-協方差矩陣,共有27個 4 x 4對角矩陣。

相關介紹參考重複測量 - MIXED混合模型。

3. Compare REPEATED in GLM and MIXED

3.1缺失值的處理

Repeated 和 Random選項
Repeated 和 Random選項

GLM是删掉整條觀測,上述例子我們随機整四個缺失值,則這四個缺失值所在的觀測被删除。

MIXED中是需要long form型資料,也就是27 x 4是108條,有四條有缺失值,隻使用104條。

4. RANDOM in GLM

only in the extra F tests produced by the RANDOM statement. Other features in the GLM procedure—including the results of the LSMEANS and ESTIMATE statements—assume that all effects are fixed, so that all tests and estimability checks for these statements are based on a fixed-effects model, even when you use a RANDOM statement

  1. GLM中random隻是product extra F test. 
  2. 像LSMEANS ESTIMATE等都是基于模型的固定效應進行估計的。
  3. 如果想要真正的随機,用MIXED的模型。

4.1

random pat(vacgrp)/test ;      

這是說對vacgrp作F檢驗時,使用pat*vacgrp的互動作用作為分母,也就是組内誤差,組間誤差仍是vacgrp的誤差。其餘的F檢驗都是使用模型的Error作為分母。

test h=vacgrp e=pat(vacgrp);      

這兩段代碼的作用時完全相同的。

4.2

lsmeans vacgrp / cl STDERR;
 estimate '用estimate計算lsmean ACT' intercept 1 vacgrp 1 0;      

均值計算時,這兩端代碼産生的結果也是相同的。詳細的estimate用法參考SAS Estimate 或 Contrast。

data arthr;
 input vacgrp $ pat mo1 mo2 mo3 ;
 datalines;
ACT 101 6 3 0
ACT 103 7 3 1
ACT 104 4 1 2
ACT 107 8 4 3
PBO 102 6 5 5
PBO 105 9 4 6
PBO 106 5 3 4
PBO 108 6 2 3
;
 
data discom; set arthr;
/* keep vacgrp pat visit score;*/
 score = mo1; visit = 1; output;
 score = mo2; visit = 2; output;
 score = mo3; visit = 3; output;
run;


proc glm data = discom;
 class vacgrp pat visit;
 model score = vacgrp pat(vacgrp) visit vacgrp*visit/ss3;
 test h=vacgrp e=pat(vacgrp);
 lsmeans vacgrp / cl STDERR;
 quit;
run;      

5. RANDOM in MIXED

 REOEATED中的TYPE是指定R矩陣結構,RANDOM中的TYPE是指定G矩陣結構。

 G矩形結構可參考随機效應 VS 固定效應。

6. Other REPEATED in GLM

handling repeated measures designs with one repeated response variable.

在有多個反應變量或者一個反應變量被測量多次時候使用。

6.1

model Y1-Y12=group / nouni;
 REPEATED TRIAL 3 (A B C), TIME 4 (T1 T2 T3 T4);      

three treatments are administered at each of four times, for a total of twelve dependent variables on each experimental unit. 

假設有三種實驗在四個不同的時間進行. 則每一位受試有十二個分數.

括号内的值用來标明組别,如 TRIAL 這個重複變量有三組 即 A B 與 C.

6.2

本文來自部落格園,作者:Iving,轉載請注明原文連結:https://www.cnblogs.com/SAS-T/p/15551706.html

繼續閱讀