Weekend Workshop I PROC MIXED
Random or Fixed ?RANDOMFIXEDLevels: Selected at random from infinite population Finite number of possibilities Another Experiment Different selections from same population Same Levels Goal Estimate variance components Compare means Inference All levels in population Only levels used in the experiment.
Twins: One gets SAS training method 1, the other gets method 2 Response Y = programming times
PROC MIXED Model PROC MIXED Model Y = X Z + e Variance of is G =,Variance of e is R = Model ; Random ; Repeated ;
PROC MIXED DATA=TWINS; CLASS FAMILY METHOD; MODEL TIME = METHOD; * fixed; RANDOM FAMILY; *<- family ~ N(0, 2 F ) ; Covariance Parameter Estimates Cov Parm Estimate family Residual Type 3 Tests of Fixed Effects Num Den Effect DF DF F Value Pr > F method Intraclass correlation (related to heritability) 2 F /( 2 F + 2 ) Estimated as 21.2/62 or about 1/3. Q: Why not usual (Pearson) correlation?
DemoGet_Twins.sas Twins_MIXED.sas Twins_MIXED.sas
BLUP Y ij = + F i + e ij D i = Family mean – F i + e i. best estimate of F i = ? Variance of (F i – b D i ) is (1-b) 2 2 F + b 2 2 /2 Use b = 2 F /( 2 F + 2 /2) Estimate: b = 21.2/( /2) = Overall mean (Family i mean – Overall mean) PROC MIXED DATA=TWINS; CLASS FAMILY METHOD; MODEL TIME = METHOD; RANDOM FAMILY; ESTIMATE "1 " intercept 1 | family 1; ESTIMATE "2 " intercept 1 | family 0 1; PROC GLM DATA=TWINS; CLASS FAMILY METHOD; MODEL TIME = FAMILY METHOD; LSMEANS FAMILY;
MEANS andBLUPs MEANS and BLUPs (MIXED)(GLM)
Demo Twins_BLUP.sas Twins_BLUP.sasTwins_TEST.sas
REML Estimation (1)Regress out fixed effects (2)Maximze likelihood of residuals (mean known: 0) (3)Variance estimates less biased (unbiased in some simple cases) (3)Variance estimates less biased (unbiased in some simple cases) ML Estimation Search over all (fixed and random) parameters Search over all (fixed and random) parameters Estimates of variances biased low!
Unbalanced Data Unbalanced Data SUBJ Ear plug ABCDEFG I 25 (L)19 (L)29 (R)16 (R)25 (L) II 8 (R)7 (L)23 (L)16 (R)24 (R) III 22 (R)7 (R)14 (L)12 (L) I vs. III free of subject effects for red data. Misses info in other data.
proc glm; class plug worker; model loss = worker plug; Random Worker; Estimate "I vs III - GLM" Plug ; run; proc mixed; class plug worker; model Loss=Plug; Random Worker; Estimate "I vs III - Mixed" Plug ; run; GLM Source DF Type III SS F Value Pr > F worker plug Standard Parameter Estimate Error t Value Pr > |t| I vs III - GLM Type 3 Tests of Fixed Effects Num Den Effect DF DF F Value Pr > F plug Estimates Standard Label Estimate Error DF t Value Pr > |t| I vs III - Mixed Covariance Parameter Estimates Cov Parm Estimate worker Residual
Demo Earplugs.sas Earplugs.sas
Soil Variety Aquariums, 2 aerated 2 not six dishes / aquarium one plant / dish soil x variety combinations ANOVA SourceAir Error A V S VA VS AS AVS Error B SPLIT PLOT
PROC MIXED; CLASS VAR AQUARIUM SOIL AIR; MODEL YIELD = AIR SOIL VAR SOIL*VAR AIR*SOIL AIR*VAR AIR*SOIL*VAR / DDFM=SATTERTHWAITE; RANDOM AQUARIUM(AIR); ESTIMATE "SOIL 1: AIR EFFECT" AIR -1 1 AIR*SOIL ; RUN; Compare Air to No Air within soil 1 Variance of this contrast is hard to figure out: (1/3)[MS(A)+2 MS(B)] Need Satterthwaite df AUTOMATIC IN MIXED!!!
Covariance Parameter Estimates Cov Parm Estimate AQUARIUM(AIR) Residual Type 3 Tests of Fixed Effects Num Den Effect DF DF F Value Pr > F AIR SOIL VAR VAR*SOIL SOIL*AIR VAR*AIR VAR*SOIL*AIR Standard Label Estimate Error DF t Value Pr > |t| SOIL 1: AIR EFFECT
Demo Aquarium.sas Aquarium.sas
Random Coefficient Models Random Coefficient Models the basic idea the basic idea mistakes Program writing time Average programmer Dave Line for individual j: (a 0 + a j ) + ( b 0 + b j )t a 0 + b 0 t
Hierarchial Models (1)Same as split plot - almost (2)Whole and split level continuous predictor variables (typically) (1)Aquarium level (level i): pH i (2)Dish level: Soil nitrogen test (N ij ) Y ij = a i + b i N ij +e ij (3) Idea: a i = 0 + 1 pH i + a i * b i = 0 + 1 pH i + b i * b i = 0 + 1 pH i + b i * Y ij = a i + b i N ij +e ij Y ij = 0 + 1 pH i + a i * + b i N ij +e ij Y ij = 0 + 1 pH i + a i * + ( 0 + 1 pH i + b i * ) N ij +e ij Y ij = [ 0 + 1 pH i + 0 N ij + 1 pH i N ij ] + [a i * +b i * N ij +e ij ] fixed random fixed random PROC MIXED DATA = UNDERWATER; MODEL GROWTH = N P N*P; RANDOM INTERCEPT N / SUBJECT = TANK TYPE=UN;
p Num Den Effect DF DF F Value Pr > F N pH N*pH aquarium N pH growth Num Den Effect DF DF F Value Pr > F N pH Cov Parm Estimate UN(1,1) UN(2,1) UN(2,2) Residual pH N
Demo Hierarchial.sas Hierarchial.sas
Next: Repeated Measures Notes in pdf from NCSU experimental design class (ST 711)
Demo SURGERY.sas SURGERY.sas