Topic 3: Two-Way Mixed Effects Model
Outline Two-way mixed models Three-way mixed models
Data for two-way design Y is the response variable Factor A with levels i = 1 to a Factor B with levels j = 1 to b Y ijk is the k th observation in cell (i, j) k = 1 to n ij Have balanced designs with n = n ij
Two-way mixed model Two-way mixed model has One fixed effect One random effect Tests: Again use EMS as guide Two possible models Unrestricted mixed model (SAS) Restricted mixed model (Text)
KNNL Example KNNL Problem 5.15, p 1080 Y is fuel efficiency in miles per gallon Factor A represents four different drivers, a=4 levels Factor B represents five different cars of the same model, b=5 Each driver drove each car twice over the same 40-mile test course
Read and check the data data a1; infile 'c:\...\ch5pr15.txt'; input mpg driver car; proc print data=a1; run;
The data Obs mpg driver car 1 5.3 1 1 5. 1 1 3 8.9 1 4 30.0 1 5 4.8 1 3 6 5.1 1 3 7 8.4 1 4 8 7.9 1 4 9 7.1 1 5 10 6.6 1 5
Prepare the data for a scatterplot data a1; set a1; if (driver eq 1)*(car eq 1) then dc='01_1a'; if (driver eq 1)*(car eq ) then dc='0_1b'; if (driver eq 4)*(car eq 5) then dc='0_4e';
Plot the data title1 'Plot of the data'; symbol1 v=circle i=none c=black; proc gplot data=a1; plot mpg*dc/frame; run;
Find the means proc means data=a1; output out=a mean=avmpg; var mpg; by driver car;
Plot the means title1 'Plot of the means'; symbol1 v='a' i=join c=black; symbol v='b' i=join c=black; symbol3 v='c' i=join c=black; symbol4 v='d' i=join c=black; symbol5 v='e' i=join c=black; proc gplot data=a; plot avmpg*driver=car/frame; run;
Example Revision Suppose that the four drivers were not randomly selected and there is interest in comparing the four drivers in the study Driver (A) is now a fixed effect Still consider Car (B) to be a random effect
Mixed effects model (unrestricted) Y ijk = μ + α i + β j + (αβ) ij + ε ijk α i are unknown constants β j ~ N(0, σ β ) (αβ) ij ~ N(0, σ αβ ) ε ij ~ N(0, σ ) σ Y = σ β + σ αβ + σ Σα i =0 (common restriction)
Mixed effects model (restricted) Y ijk = μ + α i + β j N ε ij ~ N(0, σ ) + (αβ) ij + ε ijk a 1 β j ~ (0, σ β ) and ( αβ ) ij ~ N(0, σ αβ ) a σ Y = σ β + ((a-1)/a)σ αβ + σ Common restrictions on fixed effects Σα i =0 Σ(αb) ij =0 for all j
Parameters There are a+3 parameters in this model a fixed effects means σ β σ αβ σ
ANOVA table The terms and layout of the ANOVA table are the same as what we used for the fixed effects model The expected mean squares (EMS) are different and vary based on the choice of unrestricted or restricted mixed model
EMS (unrestricted) E(MSA) = σ + bnσα i /(a-1)+ nσ αβ E(MSB) = σ + anσ β + nσ αβ E(MSAB) = σ + nσ αβ E(MSE) = σ Estimates of the variance components can be obtained from these equations, replacing E(MS) with table value, or other methods such as ML
EMS (restricted) E(MSA) = σ + bnσα i /(a-1)+ nσ αβ E(MSB) = σ + anσ β E(MSAB) = σ + nσ αβ Different here E(MSE) = σ Estimates of the variance components can be obtained from these equations, replacing E(MS) with table value, or other methods such as ML
Hypotheses (unrestricted) H 0A : σ α = 0; H 1A : σ α 0 H 0A is tested by F = MSA/MSAB with df a-1 and (a-1)(b-1) H 0B : σ β = 0; H 1B : σ β 0 H 0B is tested by F = MSB/MSAB with df b-1 and (a-1)(b-1) H 0AB : σ αβ = 0; H 1AB : σ αβ 0 H 0AB is tested by F = MSAB/MSE with df (a-1)(b-1) and ab(n-1)
Hypotheses (restricted) H 0A : σ α = 0; H 1A : σ α 0 H 0A is tested by F = MSA/MSAB with df a-1 and (a-1)(b-1) H 0B : σ β = 0; H 1B : σ β 0 H 0B is tested by F = MSB/MSE with df b-1 and ab(n-1) H 0AB : σ αβ = 0; H 1AB : σ αβ 0 H 0AB is tested by F = MSAB/MSE with df (a-1)(b-1) and ab(n-1)
Comparison of Means To compare fixed levels of A, std error is MSAB / bn Degrees of freedom for t tests and CIs are then (a-1)(b-1) This is true for both unrestricted and restricted mixed models
Using Proc Mixed proc mixed data=a1; class car driver; model mpg=driver; random car car*driver / vcorr; lsmeans driver / adjust=tukey; run; SAS considers unrestricted model only results in slightly different variance estimates. Not crucial if goal is to compare fixed effect means
SAS Output Covariance Parameter Estimates Cov Parm Estimate car.9343 car*driver 0.01406 Residual 0.1757 Type 3 Tests of Fixed Effects Num Den Effect DF DF F Value Pr > F driver 3 1 458.6 <.0001
SAS Output Least Squares Means Standard Effect driver Estimate Error DF t Value Pr > t driver 1 6.9300 0.7793 1 34.56 <.0001 driver 34.1500 0.7793 1 43.8 <.0001 driver 3 8.8500 0.7793 1 37.0 <.0001 driver 4 30.600 0.7793 1 38.83 <.0001 Proc GLM provides wrong SE here
SAS Output Differences of Least Squares Means Effect driver _driver Estiate Standard Error DF t Value Pr > t Adjustment driver 1-7.00 0.019 1-35.76 <.0001 Tukey- Kramer driver 1 3-1.900 0.019 1-9.51 <.0001 Tukey- Kramer driver 1 4-3.3300 0.019 1-16.49 <.0001 Tukey- Kramer driver 3 5.3000 0.019 1 6.5 <.0001 Tukey- Kramer driver 4 3.8900 0.019 1 19.6 <.0001 Tukey- Kramer driver 3 4-1.4100 0.019 1-6.98 <.0001 Tukey- Kramer Adj P <.0001 <.0001 <.0001 <.0001 <.0001 <.0001
Three-way models We can have zero, one, two, or three random effects EMS indicate how to do tests In some cases the situation is complicated and we need approximations of an F test Example: when all are random, use MS(AB)+MS(AC)-MS(ABC) to test A
Last slide Finish reading KNNL Chapter 5 We used program topic3.sas to generate the output for today