repeated measures anova: the wide, the long and … · repeated measures anova output i sas...

81
Repeated Measures Anova Repeated Measures Anova: the Wide, the Long and the Long 2007 West Coast Stata Users Group Phil Ender Statistical Consulting Group UCLA Academic Technology Services October 2007 Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Upload: phungdien

Post on 28-Jul-2018

233 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Repeated Measures Anova:the Wide, the Long and the Long

2007 West Coast Stata Users Group

Phil Ender

Statistical Consulting GroupUCLA Academic Technology Services

October 2007

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 2: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

ATS gets numerous questions on

I Analysis of variance, in general

I Repeated measures analysis of variance, in particular

I With repeated measures on some or on all factors

I Most common stat packages used for anova at UCLA:SPSSSAS

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 3: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

ATS gets numerous questions on

I Analysis of variance, in general

I Repeated measures analysis of variance, in particular

I With repeated measures on some or on all factors

I Most common stat packages used for anova at UCLA:SPSSSAS

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 4: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

ATS gets numerous questions on

I Analysis of variance, in general

I Repeated measures analysis of variance, in particular

I With repeated measures on some or on all factors

I Most common stat packages used for anova at UCLA:SPSSSAS

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 5: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

ATS gets numerous questions on

I Analysis of variance, in general

I Repeated measures analysis of variance, in particular

I With repeated measures on some or on all factors

I Most common stat packages used for anova at UCLA:SPSSSAS

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 6: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Three approaches to repeated measures anova

I The Wide – Multivariate Models

I the Long – Anova Models

I and the Long – Mixed Models

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 7: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Three approaches to repeated measures anova

I The Wide – Multivariate Models

I the Long – Anova Models

I and the Long – Mixed Models

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 8: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Three approaches to repeated measures anova

I The Wide – Multivariate Models

I the Long – Anova Models

I and the Long – Mixed Models

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 9: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Example Design

I To illustrate the different approaches to repeated measuresanova, I will use the following example design:

I Two factors:

I One between-subjects factor (A) with 2 levels

I One repeated (within-subjects) factor (B) with 4 levels

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 10: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Example Design

I To illustrate the different approaches to repeated measuresanova, I will use the following example design:

I Two factors:

I One between-subjects factor (A) with 2 levels

I One repeated (within-subjects) factor (B) with 4 levels

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 11: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Design Schematic

Split-Plot Factorial 2·4

Bb1 b2 b3 b4

A a1 s1 s1 s1 s1

a2 s2 s2 s2 s2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 12: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

¡Warning!

There will be some SAS and SPSS code in this presentation.

Sorry.

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 13: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Wide – Multivariate Models

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 14: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS proc glm

proc glm data=wide;class a;model y1 y2 y3 y4 = a;repeated b 4;

run;quit;

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 15: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Output

I SAS includes two kinds of output:

I Multivariate tests of b and a*b

I Univariate tests of a, b, and a*b

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 16: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Output

I SAS includes two kinds of output:

I Multivariate tests of b and a*b

I Univariate tests of a, b, and a*b

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 17: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Assumptions

Multivariate assumptions:

Observations are multivariate normalCovariance structure – unstructured

Univariate assumptions:

Nonadditivity assumption; no subject by treatment interactionCovariance structure – compound symmetricPlus all the standard ones concerning normality and homogeneityof variance, etc

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 18: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Assumptions

Multivariate assumptions:

Observations are multivariate normalCovariance structure – unstructured

Univariate assumptions:

Nonadditivity assumption; no subject by treatment interactionCovariance structure – compound symmetricPlus all the standard ones concerning normality and homogeneityof variance, etc

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 19: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Now For Some SPSS Code

point ... click

point ... point ... click ... click

point ... click ... click

Actually, the SPSS syntax code looks a lot like the SAS code

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 20: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Now For Some SPSS Code

point ... click

point ... point ... click ... click

point ... click ... click

Actually, the SPSS syntax code looks a lot like the SAS code

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 21: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Now For Some SPSS Code

point ... click

point ... point ... click ... click

point ... click ... click

Actually, the SPSS syntax code looks a lot like the SAS code

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 22: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Multivariate Results in Stata

manova y1 y2 y3 y4 = a

/* multivariate test of a*b interaction */

matrix ymat = (1,0,0,-1\0,1,0,-1\0,0,1,-1)manovatest a, ytransform(ymat)

/* multivariate test of b main effect */

matrix xmat = (1, .5, .5)manovatest, test(xmat) ytransform(ymat)

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 23: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Multivariate Results in Stata

manova y1 y2 y3 y4 = a

/* multivariate test of a*b interaction */

matrix ymat = (1,0,0,-1\0,1,0,-1\0,0,1,-1)manovatest a, ytransform(ymat)

/* multivariate test of b main effect */

matrix xmat = (1, .5, .5)manovatest, test(xmat) ytransform(ymat)

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 24: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Multivariate Results in Stata

manova y1 y2 y3 y4 = a

/* multivariate test of a*b interaction */

matrix ymat = (1,0,0,-1\0,1,0,-1\0,0,1,-1)manovatest a, ytransform(ymat)

/* multivariate test of b main effect */

matrix xmat = (1, .5, .5)manovatest, test(xmat) ytransform(ymat)

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 25: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Downside of Wide

I Missing data can be a killer

I Manova analyses use listwise deletion for missing data

I If a single value for a subject is missing the whole subject isdeleted

I There are single imputation methods based on row andcolumn means

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 26: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Downside of Wide

I Missing data can be a killer

I Manova analyses use listwise deletion for missing data

I If a single value for a subject is missing the whole subject isdeleted

I There are single imputation methods based on row andcolumn means

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 27: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Downside of Wide

I Missing data can be a killer

I Manova analyses use listwise deletion for missing data

I If a single value for a subject is missing the whole subject isdeleted

I There are single imputation methods based on row andcolumn means

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 28: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Downside of Wide

I Missing data can be a killer

I Manova analyses use listwise deletion for missing data

I If a single value for a subject is missing the whole subject isdeleted

I There are single imputation methods based on row andcolumn means

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 29: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Long – Anova Models

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 30: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Anova Linear Model

Yijk = µ+ αj + πi(j) + βk + α ∗ βjk + β ∗ πki(j) + εijk

I This linear model is fixed-effects only, there are norandom-effects

I Can be more easily seen when expressed as a regression model,y = Xβ + ε

I Random effects are computed using different denominators forthe various F-ratios

I nonadditivity assumption - no block (subject) treatmentinteraction

I For this model εijk and β ∗ πki(j) are not separately estimable

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 31: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Anova Linear Model

Yijk = µ+ αj + πi(j) + βk + α ∗ βjk + β ∗ πki(j) + εijk

I This linear model is fixed-effects only, there are norandom-effects

I Can be more easily seen when expressed as a regression model,y = Xβ + ε

I Random effects are computed using different denominators forthe various F-ratios

I nonadditivity assumption - no block (subject) treatmentinteraction

I For this model εijk and β ∗ πki(j) are not separately estimable

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 32: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Anova Linear Model

Yijk = µ+ αj + πi(j) + βk + α ∗ βjk + β ∗ πki(j) + εijk

I This linear model is fixed-effects only, there are norandom-effects

I Can be more easily seen when expressed as a regression model,y = Xβ + ε

I Random effects are computed using different denominators forthe various F-ratios

I nonadditivity assumption - no block (subject) treatmentinteraction

I For this model εijk and β ∗ πki(j) are not separately estimable

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 33: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Anova Linear Model

Yijk = µ+ αj + πi(j) + βk + α ∗ βjk + β ∗ πki(j) + εijk

I This linear model is fixed-effects only, there are norandom-effects

I Can be more easily seen when expressed as a regression model,y = Xβ + ε

I Random effects are computed using different denominators forthe various F-ratios

I nonadditivity assumption - no block (subject) treatmentinteraction

I For this model εijk and β ∗ πki(j) are not separately estimable

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 34: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Anova Linear Model

Yijk = µ+ αj + πi(j) + βk + α ∗ βjk + β ∗ πki(j) + εijk

I This linear model is fixed-effects only, there are norandom-effects

I Can be more easily seen when expressed as a regression model,y = Xβ + ε

I Random effects are computed using different denominators forthe various F-ratios

I nonadditivity assumption - no block (subject) treatmentinteraction

I For this model εijk and β ∗ πki(j) are not separately estimable

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 35: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Anova Linear Model

Yijk = µ+ αj + πi(j) + βk + α ∗ βjk + β ∗ πki(j) + εijk

I This linear model is fixed-effects only, there are norandom-effects

I Can be more easily seen when expressed as a regression model,y = Xβ + ε

I Random effects are computed using different denominators forthe various F-ratios

I nonadditivity assumption - no block (subject) treatmentinteraction

I For this model εijk and β ∗ πki(j) are not separately estimable

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 36: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS convert wide to long

data long;set wide;y=y1; b=1; output;y=y2; b=2; output;y=y3; b=3; output;y=y4; b=4; output;drop y1 y2 y3 y4;run;

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 37: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS proc glm

proc glm data=long;class a b s;model y = a s(a) b a*b / ss3;test h=a e=s(a);run;quit;

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 38: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata convert wide to long

reshape long y, i(s) j(b)

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 39: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata anova

anova y a / s|a b a*b /, repeated(b)

/* inspect pooled-within covariance matrix */

matrix list e(Srep)

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 40: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata anova

anova y a / s|a b a*b /, repeated(b)

/* inspect pooled-within covariance matrix */

matrix list e(Srep)

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 41: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

anova repeated option

I Along with the e(Srep) matrix ...

I Allows evaluation of compound symmetry assumption

I Gives conservative p-values if assumption is not met

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 42: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata manova also works with long data

manova y = a / s|a b a*b /

I Does not have a repeated option

I Displays univariate F-ratios in multivariate format

I Output is a bit cluttered

I Useful for multivariate repeated measures

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 43: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata manova also works with long data

manova y = a / s|a b a*b /

I Does not have a repeated option

I Displays univariate F-ratios in multivariate format

I Output is a bit cluttered

I Useful for multivariate repeated measures

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 44: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata manova also works with long data

manova y = a / s|a b a*b /

I Does not have a repeated option

I Displays univariate F-ratios in multivariate format

I Output is a bit cluttered

I Useful for multivariate repeated measures

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 45: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata manova also works with long data

manova y = a / s|a b a*b /

I Does not have a repeated option

I Displays univariate F-ratios in multivariate format

I Output is a bit cluttered

I Useful for multivariate repeated measures

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 46: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

There is also a user written ado

wsanova y b, id(s) between(a) epsilon

I -wsanova- (John Gleason) – findit wsanova

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 47: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

There is also a user written ado

wsanova y b, id(s) between(a) epsilon

I -wsanova- (John Gleason) – findit wsanova

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 48: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Using regression

recode s 5=1 6=2 7=3 8=4, generate(ss)

xi3: regress y e.a*e.b [email protected]

test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

test2 _Ia_2 / _Iss2Wa1 _Iss2Wa2 _Iss3Wa1 ///_Iss3Wa2 _Iss4Wa1 _Iss4Wa2 _Iss4Wa2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 49: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Using regression

recode s 5=1 6=2 7=3 8=4, generate(ss)

xi3: regress y e.a*e.b [email protected]

test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

test2 _Ia_2 / _Iss2Wa1 _Iss2Wa2 _Iss3Wa1 ///_Iss3Wa2 _Iss4Wa1 _Iss4Wa2 _Iss4Wa2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 50: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Using regression

recode s 5=1 6=2 7=3 8=4, generate(ss)

xi3: regress y e.a*e.b [email protected]

test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

test2 _Ia_2 / _Iss2Wa1 _Iss2Wa2 _Iss3Wa1 ///_Iss3Wa2 _Iss4Wa1 _Iss4Wa2 _Iss4Wa2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 51: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Using regression

recode s 5=1 6=2 7=3 8=4, generate(ss)

xi3: regress y e.a*e.b [email protected]

test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

test2 _Ia_2 / _Iss2Wa1 _Iss2Wa2 _Iss3Wa1 ///_Iss3Wa2 _Iss4Wa1 _Iss4Wa2 _Iss4Wa2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 52: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Regression comments

I Don’t use dummy coded variables

I Use -xi3- or -desmat- to create effect coded variables

I -xi3- can create effect coding on the fly

I -desmat- (John Hendrickx) – findit desmat

I -xi3- (Mitchell & Ender) – findit xi3

I -test2- (Ender) – findit test2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 53: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Regression comments

I Don’t use dummy coded variables

I Use -xi3- or -desmat- to create effect coded variables

I -xi3- can create effect coding on the fly

I -desmat- (John Hendrickx) – findit desmat

I -xi3- (Mitchell & Ender) – findit xi3

I -test2- (Ender) – findit test2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 54: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Regression comments

I Don’t use dummy coded variables

I Use -xi3- or -desmat- to create effect coded variables

I -xi3- can create effect coding on the fly

I -desmat- (John Hendrickx) – findit desmat

I -xi3- (Mitchell & Ender) – findit xi3

I -test2- (Ender) – findit test2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 55: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Regression comments

I Don’t use dummy coded variables

I Use -xi3- or -desmat- to create effect coded variables

I -xi3- can create effect coding on the fly

I -desmat- (John Hendrickx) – findit desmat

I -xi3- (Mitchell & Ender) – findit xi3

I -test2- (Ender) – findit test2

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 56: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Dummy Coding versus Effect Coding

F-ratios

Dummy EffectA main effect 15.78 2.00B main effect 35.96 127.89A*B interaction 12.74 12.74

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 57: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Long again – Mixed Models

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 58: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Linear Mixed Model

y = Xβ + Zu + ε

wherey is the nx1 response vectorX is the nxp fixed-effects design matrixβ is the px1 vector of fixed effectsZ is the nxq random-effects design matrixu is the qx1 vector of random effectsε is the nx1 vector of errors

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 59: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The Linear Mixed Model

y = Xβ + Zu + εwherey is the nx1 response vectorX is the nxp fixed-effects design matrixβ is the px1 vector of fixed effectsZ is the nxq random-effects design matrixu is the qx1 vector of random effectsε is the nx1 vector of errors

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 60: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS proc mixed 1

proc mixed data=long;class a b;model y = a b a*b;random intercept / subject=s;run;

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 61: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS proc mixed 2

proc mixed data=long;class a b;model y = a b a*b;repeated b / subject=s type=cs;run;

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 62: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS Output

Type 3 Tests of Fixed Effects

Num DenEffect DF DF F Value Pr > F

a 1 6 2.00 0.2070b 3 18 127.89 <.0001a*b 3 18 12.74 0.0001

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 63: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata xtmixed

xi3 e.a*e.b

xtmixed y _Ia_2 _Ib_2 _Ib_3 _Ib_4 ///_Ia2Xb2 _Ia2Xb3 _Ia2Xb4 || s:

test _Ia_2test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 64: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata xtmixed

xi3 e.a*e.b

xtmixed y _Ia_2 _Ib_2 _Ib_3 _Ib_4 ///_Ia2Xb2 _Ia2Xb3 _Ia2Xb4 || s:

test _Ia_2test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 65: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata xtmixed

xi3 e.a*e.b

xtmixed y _Ia_2 _Ib_2 _Ib_3 _Ib_4 ///_Ia2Xb2 _Ia2Xb3 _Ia2Xb4 || s:

test _Ia_2test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 66: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata xtmixed comments

I Once again, don’t use dummy coding

I -xi3- does not work directly with -xtmixed-

I Test command displays results as chi-square

I F approximation equals χ2/df

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 67: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata xtmixed comments

I Once again, don’t use dummy coding

I -xi3- does not work directly with -xtmixed-

I Test command displays results as chi-square

I F approximation equals χ2/df

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 68: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata xtmixed comments

I Once again, don’t use dummy coding

I -xi3- does not work directly with -xtmixed-

I Test command displays results as chi-square

I F approximation equals χ2/df

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 69: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS Covariance Types

SAS allows for a number of covariance structures:

autoregressive, heterogeneous autoregressive,compound symmetry, heterogeneous CS,Toeplitz, unstructured, and over a dozen more

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 70: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

SAS proc mixed revisited

proc mixed data=long;class a b;model y = a b a*b;repeated b / subject=s type=ar(1);run;

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 71: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Stata xtregar

tsset s b

xi3: xtregar y e.a*e.b

test _Ia_2test _Ib_2 _Ib_3 _Ib_4test _Ia2Xb2 _Ia2Xb3 _Ia2Xb4

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 72: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Comparing proc mixed w/ ar(1) and xtregar

I Results are close but not identical

I proc mixed uses a REML estimator

I xtregar uses a GLS estimator

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 73: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Comparing proc mixed w/ ar(1) and xtregar

I Results are close but not identical

I proc mixed uses a REML estimator

I xtregar uses a GLS estimator

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 74: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Comparing proc mixed w/ ar(1) and xtregar

I Results are close but not identical

I proc mixed uses a REML estimator

I xtregar uses a GLS estimator

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 75: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

proc mixed w/ ar(1) vs xtregar

F-ratios

proc mixed xtregarA main effect 1.65 1.94B main effect 91.57 102.78333A*B interaction 14.69 13.866667

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 76: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Closing Comments

For balanced designs the repeated anova and mixed models yieldthe same results

Results are different for unbalanced designs

For missing data within subjects use mixed with FIML

Repeated measures anova is not necessarily the best way to studychange over time

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 77: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Closing Comments

For balanced designs the repeated anova and mixed models yieldthe same results

Results are different for unbalanced designs

For missing data within subjects use mixed with FIML

Repeated measures anova is not necessarily the best way to studychange over time

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 78: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Closing Comments

For balanced designs the repeated anova and mixed models yieldthe same results

Results are different for unbalanced designs

For missing data within subjects use mixed with FIML

Repeated measures anova is not necessarily the best way to studychange over time

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 79: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Closing Comments

For balanced designs the repeated anova and mixed models yieldthe same results

Results are different for unbalanced designs

For missing data within subjects use mixed with FIML

Repeated measures anova is not necessarily the best way to studychange over time

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 80: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

Web Page

A web page with all of the Stata commandsand complete output can be found at

http://www.ats.ucla.edu/stat/stata/library/2007wcsug.htm

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long

Page 81: Repeated Measures Anova: the Wide, the Long and … · Repeated Measures Anova Output I SAS includes two kinds of output: I Multivariate tests of b and a*b ... Phil Ender Repeated

Repeated Measures Anova

The End

Phil Ender Repeated Measures Anova: the Wide, the Long and the Long