topic 32: two-way mixed effects model

29
Topic 32: Two-Way Mixed Effects Model

Upload: june

Post on 15-Jan-2016

40 views

Category:

Documents


2 download

DESCRIPTION

Topic 32: 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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Topic 32: Two-Way Mixed Effects Model

Topic 32: Two-Way Mixed Effects Model

Page 2: Topic 32: Two-Way Mixed Effects Model

Outline

• Two-way mixed models

• Three-way mixed models

Page 3: Topic 32: Two-Way Mixed Effects Model

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

• Yijk is the kth observation in cell (i, j)

k = 1 to nij

• Have balanced designs with n = nij

Page 4: Topic 32: Two-Way Mixed Effects Model

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)

Page 5: Topic 32: Two-Way Mixed Effects Model

KNNL Example• KNNL Problem 25.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

Page 6: Topic 32: Two-Way Mixed Effects Model

Read and check the data

data a1; infile 'c:\...\CH25PR15.TXT'; input mpg driver car;proc print data=a1; run;

Page 7: Topic 32: Two-Way Mixed Effects Model

The dataObs mpg driver car 1 25.3 1 1 2 25.2 1 1 3 28.9 1 2 4 30.0 1 2 5 24.8 1 3 6 25.1 1 3 7 28.4 1 4 8 27.9 1 4 9 27.1 1 5 10 26.6 1 5

Page 8: Topic 32: Two-Way Mixed Effects Model

Prepare the data for a plot

data a1; set a1; if (driver eq 1)*(car eq 1) then dc='01_1A'; if (driver eq 1)*(car eq 2) then dc='02_1B'; ⋮ if (driver eq 4)*(car eq 5) then dc='20_4E';

Page 9: Topic 32: Two-Way Mixed Effects Model

Plot the data

title1 'Plot of the data';symbol1 v=circle i=none c=black;proc gplot data=a1; plot mpg*dc/frame;run;

Page 10: Topic 32: Two-Way Mixed Effects Model
Page 11: Topic 32: Two-Way Mixed Effects Model

Find the means

proc means data=a1; output out=a2 mean=avmpg; var mpg; by driver car;

Page 12: Topic 32: Two-Way Mixed Effects Model

Plot the meanstitle1 'Plot of the means';symbol1 v='A' i=join c=black;symbol2 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=a2; plot avmpg*driver=car/frame;run;

Page 13: Topic 32: Two-Way Mixed Effects Model
Page 14: Topic 32: Two-Way Mixed Effects Model

Example Revisited

• 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

Page 15: Topic 32: Two-Way Mixed Effects Model

Mixed effects model(unrestricted)

• Yijk = μ + i + j + ()ij + εijk

• Σi =0 (unknown constants)

j ~ N(0, σ2)

• ()ij ~ N(0, σ2)

• εij ~ N(0, σ2)

• σY2 = σ

2 + σ2 + σ2

Page 16: Topic 32: Two-Way Mixed Effects Model

Mixed effects model(restricted)

• Yijk = μ + i + j + ()ij + εijk

• Σi =0 (unknown constants)

• Σ(b)ij =0 for all j

• εij ~ N(0, σ2)

• σY2 = σ

2 + ((a-1)/a)σ2 + σ2

2 21~ (0, ) and ( ) ~ (0, )j ij

aN N

a

Page 17: Topic 32: Two-Way Mixed Effects Model

Parameters

• There are a+3 parameters in this model

–a fixed effects means

–σ2

–σ2

–σ2

Page 18: Topic 32: Two-Way Mixed Effects Model

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

Page 19: Topic 32: Two-Way Mixed Effects Model

EMS (unrestricted)

• E(MSA) = σ2 + bnΣi2 /(a-1)+ nσ

2

• E(MSB) = σ2 + anσ2 + nσ

2

• E(MSAB) = σ2 + nσ2

• E(MSE) = σ2

• Estimates of the variance components can be obtained from these equations, replacing E(MS) with table value, or other methods such as ML

Page 20: Topic 32: Two-Way Mixed Effects Model

EMS (restricted)

• E(MSA) = σ2 + bnΣi2 /(a-1)+ nσ

2

• E(MSB) = σ2 + anσ2

• E(MSAB) = σ2 + nσ2

• E(MSE) = σ2

• Estimates of the variance components can be obtained from these equations, replacing E(MS) with table value, or other methods such as ML

Diff here

Page 21: Topic 32: Two-Way Mixed Effects Model

Hypotheses (unrestricted)

• H0A: σ2 = 0; H1A: σ

2 ≠ 0

– H0A is tested by F = MSA/MSAB with df a-1 and (a-1)(b-1)

• H0B: σ2 = 0; H1B : σ

2 ≠ 0

– H0B is tested by F = MSB/MSAB with df b-1 and (a-1)(b-1)

• H0AB : σ2 = 0; H1AB : σ

2 ≠ 0

– H0AB is tested by F = MSAB/MSE with df (a-1)(b-1) and ab(n-1)

Page 22: Topic 32: Two-Way Mixed Effects Model

Hypotheses (restricted)

• H0A: σ2 = 0; H1A: σ

2 ≠ 0

– H0A is tested by F = MSA/MSAB with df a-1 and (a-1)(b-1)

• H0B: σ2 = 0; H1B : σ

2 ≠ 0

– H0B is tested by F = MSB/MSE with df b-1 and ab(n-1)

• H0AB : σ2 = 0; H1AB : σ

2 ≠ 0

– H0AB is tested by F = MSAB/MSE with df (a-1)(b-1) and ab(n-1)

Page 23: Topic 32: Two-Way Mixed Effects Model

Comparison of Means

• To compare fixed levels of A, std error is

• Degrees of freedom for t tests and CIs are then (a-1)(b-1)

• This is true for both unrestricted and restricted mixed models

2MSAB / bn

Page 24: Topic 32: Two-Way Mixed Effects Model

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

Page 25: Topic 32: Two-Way Mixed Effects Model

SAS Output

Covariance Parameter Estimates

Cov Parm Estimatecar 2.9343car*driver 0.01406Residual 0.1757

Type 3 Tests of Fixed Effects

EffectNum

DFDen DF F Value Pr > F

driver 3 12 458.26 <.0001

Page 26: Topic 32: Two-Way Mixed Effects Model

SAS Output

Least Squares Means

Effect driver EstimateStandard

Error DF t Value Pr > |t|driver 1 26.9300 0.7793 12 34.56 <.0001driver 2 34.1500 0.7793 12 43.82 <.0001driver 3 28.8500 0.7793 12 37.02 <.0001driver 4 30.2600 0.7793 12 38.83 <.0001

Page 27: Topic 32: Two-Way Mixed Effects Model

SAS OutputDifferences of Least Squares Means

Effect driver _driver EstiateStandard

Error DF t Value Pr > |t| Adjustment Adj Pdriver 1 2 -7.2200 0.2019 12 -35.76 <.0001 Tukey-

Kramer

<.0001

driver 1 3 -1.9200 0.2019 12 -9.51 <.0001 Tukey-Kramer

<.0001

driver 1 4 -3.3300 0.2019 12 -16.49 <.0001 Tukey-Kramer

<.0001

driver 2 3 5.3000 0.2019 12 26.25 <.0001 Tukey-Kramer

<.0001

driver 2 4 3.8900 0.2019 12 19.26 <.0001 Tukey-Kramer

<.0001

driver 3 4 -1.4100 0.2019 12 -6.98 <.0001 Tukey-Kramer

<.0001

Page 28: Topic 32: Two-Way Mixed Effects Model

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, e.g. when all are random, use MS(AB)+MS(AC)-MS(ABC) to test A

Page 29: Topic 32: Two-Way Mixed Effects Model

Last slide

• Finish reading KNNL Chapter 25

• We used program topic32.sas to generate the output for today