3 Introduction of Repeated Measures ANOVA Jia Chen
4 What is it ?Definition: - It is a technique used to test the equality of means.
5 When To Use It?It is used when all members of a random sample are measured under a number of different conditions.As the sample is exposed to each condition in turn, the measurement of dependent variable is repeated.
6 Introduction of One-Way Repeated Measures ANOVA Che-Wei, LuProfessor:Wei Zhu
7 One-Way Repeated Measures ANOVA DefinitionA one-way repeated measures ANOVA instead of having one score per subject, experiments are frequently conducted in which multiple score are gathered for each case.Concept of Repeated Measures ANOVAOne factor with at least two levels, levels are dependent.Dependent means that they share variability in some way.The Repeated Measures ANOVA is extended from standard ANOVA.
8 One-Way Repeated Measures ANOVA When to UseMeasuring performance on the same variable over timefor example looking at changes in performance during training or before and after a specific treatmentThe same subject is measured multiple times under different conditionsfor example performance when taking Drug A and performance when taking Drug BThe same subjects provide measures/ratings on different characteristicsfor example the desirability of red cars, green cars and blue carsNote how we could do some RM as regular between subjects designsFor example, Randomly assign to drug A or B
9 One-Way Repeated Measures ANOVA Source of Variance in Repeated Measures ANOVASStotalDeviation of each individual score from the grand meanSSb/t subjectsDeviation of subjects' individual means (across treatments) from the grand mean.In the RM setting, this is largely uninteresting, as we can pretty much assume that ‘subjects differ’SSw/in subjects: How Ss vary about their own mean, breaks down into:SStreatmentAs in between subjects ANOVA, is the comparison of treatment means to each other (by examining their deviations from the grand mean)However this is now a partition of the within subjects variationSSerrorVariability of individuals’ scores about their treatment mean
10 One-Way Repeated Measures ANOVA Partition of Sum of Square𝑆𝑆 𝑡𝑜𝑡𝑎𝑙𝑆𝑆 𝑏/𝑡𝑠𝑢𝑏𝑗𝑒𝑐𝑡𝑠𝑆𝑆 𝑤/𝑖𝑛𝑠𝑢𝑏𝑗𝑒𝑐𝑡𝑠𝑆𝑆 𝑡𝑟𝑒𝑎𝑚𝑒𝑚𝑡𝑆𝑆 𝑒𝑟𝑟𝑜𝑟Repeated Measures ANOVA𝑆𝑆 𝑡𝑜𝑡𝑎𝑙𝑆𝑆 𝑏/𝑡𝑡𝑟𝑒𝑎𝑚𝑒𝑛𝑡𝑆𝑆 𝑤/𝑖𝑛𝑒𝑟𝑟𝑜𝑟Standard ANOVA
12 One-Way Repeated Measures ANOVA Example:Researchers want to test a new anti-anxiety medication. They measure the anxiety of 7 participants three times: once before taking the medication, once one week after taking the medication, and once two weeks after taking medication. Anxiety is rated on a scale of 1-10,with 10 being ”high anxiety” and 1 being “low anxiety”. Are there any difference between the three condition using significant level 𝛼=0.05?ParticipantsBeforeWeek1Week2197428635
18 One-Way Repeated Measures ANOVA SAS CodeDATA REPEAT;INPUT SUBJ BEFORE WEEK1 WEEK2;DATALINES;;PROC ANOVA DATA=REPEAT;TITLE "One-Way ANOVA using the repeated Statment";MODEL BEFORE WEEK1 WEEK2= / NOUNI;REPEATED TIME 3 (1 2 3);RUN;The Before, Week1, and Week2 are the time level at each participants.The NOUNI(no univariate) is a request not to conduct a separate analysis for each of the three times variables.In here, we don’t have CLASS statement because our data set does not have an independent variableThis indicates the labels we want to printed for each level of times
24 ANOVA TABLE Source DF SS MS F Factor A a-1 SSA SSA/(a-1) MSA/MSWA ～ F(a-1),n(a-1)Factor Bb-1SSBSSB/(b-1)MSB/MSE ～ F(b-1),n(a-1)(b-1)AB Interaction(a-1)(b-1)SSABSSAB/(a-1)(b-1)MSAB/MSE ～ F(a-1)(b-1,n(a-1)(b-1)Subjects within A(n-1)aSSWASSWA/(n-1)aError(n-1)a(b-1)SSESSE/((n-1)a(b-1)Totalnab-1SST
25 ExampleThe shape variable is the repeated variable. This produces an ANOVA with one between-subjects factor. If you were to examine the expected mean squares for this setup, you would find that the appropriate error term for the test of calib is subject|calib. The appropriate error term for shape and shape#calib is shape#subject|calib (which is the residual error since we do not include the term in the model).
26 SAS Code Data Q1; set pre.Q1; run; proc anova data=Q1; title' Two-way Anova with a Repeated Measure on One Factor';class calib;model shape_1 shape_2 shape_3 shape_4 = calib/nouni;repeated shape 4;means calib;
27 Analysis of SAS OutputMANOVA Test Criteria and Exact F Statistics for the Hypothesis of no shape Effect H = Anova SSCP Matrix for shape E = Error SSCP Matrix S=1 M=0.5 N=0StatisticValueF ValueNum DFDen DFPr > FWilks' Lambda25.69320.0377Pillai's TraceHotelling-Lawley TraceRoy's Greatest RootAt α=0.05,we reject the hypothesis and conclude that there is shape EffectMANOVA Test Criteria and Exact F Statistics for the Hypothesis of no shape*calib Effect H = Anova SSCP Matrix for shape*calib E = Error SSCP Matrix S=1 M=0.5 N=0StatisticValueF ValueNum DFDen DFPr > FWilks' Lambda3.31320.2404Pillai's TraceHotelling-Lawley TraceRoy's Greatest RootAt α=0.05,we cannot reject the hypothesis and conclude that there is noshape*calib Effect
28 Tests of Hypotheses for Between Subjects Effects SourceDFAnova SSMean SquareF ValuePr > Fcalib111.890.0261Error4Univariate Tests of Hypotheses for Within Subject EffectsSourceDFAnova SSMean SquareF ValuePr > FAdj Pr > FG - GH - Fshape312.800.00050.00990.0011shape*calib2.010.16620.21520.1791Error(shape)12
29 Two-Factor ANOVA with Repeated Measures on both Factors
30 ANOVA TABLE Source DF SS MS F Subjects n-1 SSS SSS/I-1 MSS/MSE Factor Aa-1SSASSA/(a-1)MSA/MSA*S ～ F(a-1),(n-1)(a-1)Factor Bb-1SSBSSB/(b-1)MSB/MSB*S ～ F(b-1),(n-1)(b-1)AB Interaction(a-1)(b-1)SSABSSAB/((a-1)(b-1))MSAB/MSE～F(a-1)(b-1),(n-1)(a-1)(b-1)A*Subjects(n-1)(a-1)SSA*SSSWA/((n-1)a)SSA*S/MSEF(a-1)(n-1),(n-1)(a-1)(b-1)B*Subjects(n-1)(b-1)SSB*SSSWB/((n-1)b)F(n-1)(b-1),(n-1)(a-1)(b-1)Error(n-a)(a-1)(b-1)SSESSE/((n-1)(a-1)(b-1))Totalnab-1SST
31 ExampleThree subjects, each with nine accuracy scores on all combinations of the three different dials and three different periods. With subject a random factor and both dial and period fixed factors, the appropriate error term for the test of dial is the dial#subject interaction. Likewise, period#subject is the correct error term for period, and period#dial#subject (which we will drop so that it becomes residual error) is the appropriate error term for period#dial.
32 SAS Code Data Q2; Input Mins1-Mins9; Datalines; ;ODS RTF STYLE=BarrettsBlue;Proc anova data=Q2;Model Mins1-Mins9=/nouni;Repeated period 3, dail 3/nom;Run;ods rtf close;
33 SAS Output Univariate Tests of Hypotheses for Within Subject Effects SourceDFAnova SSMean SquareF ValuePr > FAdj Pr > FG - GH - Fperiod214.450.01480.05630.0394Error(period)4Greenhouse-Geisser Epsilon0.5364Huynh-Feldt Epsilon0.6569At α=0.05,we reject the hypothesis and conclude that there is period EffectSourceDFAnova SSMean SquareF ValuePr > FAdj Pr > FG - GH - Fdail250.910.00140.01690.0115Error(dail)4Greenhouse-Geisser Epsilon0.5227Huynh-Feldt Epsilon0.5952At α=0.05,we reject the hypothesis and conclude that there is dail EffectSourceDFAnova SSMean SquareF ValuePr > FAdj Pr > FG - GH - Fperiod*dail40.300.87150.66030.7194Error(period*dail)8Greenhouse-Geisser Epsilon0.2827Huynh-Feldt Epsilon0.4006At α=0.05,we cannot reject the hypothesis and conclude the there is no period*dail Effect
34 Three-factor Experiments with a repeated measure T. Sakamoto
35 Example of a marketing experiment Case of this exampleA company which produces some Liquid Crystal Display wants to examine the characteristics of its prototype products.ExperimentThe subjects who belong to a region X or Y see the Liquid Crystal Display A, B, or C.Each type of LCD is seen twice; once in the light and the other in the dark.The preferences of the LCD are measured by the subjects, on a scale from 1 to 5 (1= lowest, 5=highest).
36 Experimental Design and Data Three factorsType of LCDRegions to which the specimens belongIn the light / In the darkRepeted measure factor : In the light / In the darkType of LCDABCsubjlightdarkREGIONX15411212126223132314241525Y1626717278182891929102030
37 SAS PROGRAM data lcd; input subj type $ region $ light dark @@; datalines;1 a a a a a 5 36 a a a a a 5 411 b b b b b 4 616 b b b b b 4 421 c c c c c 4 326 c c c c c 4 3;run;proc anova data=lcd;title ’Three-way ANOVA with a Repeated Measure';class type region;model light dark = type | region /nouni;repeated light_dark;means type | region;
43 Mixed ModelsWhen we have a model that contains random effect as well as fixed effect, then we are dealing with a mixed model.From the above definition, we see that mixed models must contain at least two factors. One having fixed effect and one having random effect.
44 Why use mixed models?When repeated measurements are made on the same statistical units, it would not be realistic to assume that these measurements are independent.We can take this dependence into account by specifying covariance structures using a mixed model
45 Definition A mixed model can be represented in matrix notation by: 𝑦= 𝛽 0 𝑋+ 𝛽 1 𝑍+𝜀𝑦 is the vector of observations𝛽 0 is the vector of fixed effects𝛽 1 is the vector of random effects𝜀 is the vector of I.I.D. error terms𝑋 and 𝑍 are matrices relating 𝛽 0 and 𝛽 1 to 𝑦
46 Assumptions 𝛽 1 ~Normal 0,G 𝜀~Normal 0,R R and G are constants We also assume that 𝛽 1 and 𝜀 are independentWe get V = ZGZ' + R, where V is the variance of y
47 How to estimate 𝛽 0 and 𝛽 1 ?If R and G are given: Using Henderson’s Mixed Model equation, we have: 𝑋 ′ 𝑅 −1 𝑋 𝑋 ′ 𝑅 −1 𝑍 𝑍 ′ 𝑅 −1 𝑋 𝑍 ′ 𝑅 −1 𝑍+ 𝐺 −1 𝛽 0 𝛽 1 = 𝑋 ′ 𝑅 −1 𝑦 𝑍 ′ 𝑅 −1 𝑦 So 𝛽 0 = (𝑋 ′ 𝑉 −1 𝑋 ) −1 X′ 𝑉 y And 𝛽 1 = 𝐺𝑍′ 𝑉 −1 (y−X 𝛽 0 )
48 What if G and R are unknown? We know that both 𝛽 1 and 𝜀 are normally distributed, so the best approach is to use likelihood based methodsThere are two methods used by SAS:1)Maximum likelihood (ML)2)Restricted/residual maximum likelihood (REML)
49 ExampleBelow is a table of growth measurements for 11 girls and 16 boys at ages 8, 10, 12, 14: Person gender age8 age10 age12 age14 1 F F F F F F F F F F F M M MPerson gender age8 age10 age12 age14 15 M M M M M M M M M M M M M
50 Using SASdata pr; input Person Gender $ y1 y2 y3 y4; y=y1; Age=8; output; y=y2; Age=10; output; y=y3; Age=12; output; y=y4; Age=14; output; drop y1-y4; datalines; 1 F F … ; Run;
51 Using SASproc mixed data=pr method=ml covtest; class Person Gender; model y = Gender Age Gender*Age / s; repeated / type=un subject=Person r; run;
52 Class Level Information ResultsModel InformationData SetWORK.PRDependent VariableyCovariance StructureUnstructuredSubject EffectPersonEstimation MethodMLResidual Variance MethodNoneFixed Effects SE MethodModel-BasedDegrees of Freedom MethodBetween-WithinAs one can see, the covariance matrix is unstructured, as we are going to estimate it using the maximum likelihood methodClass Level InformationClassLevelsValuesPerson27Gender2F M
53 Number of Observations Convergence criteria met. DimensionsCovariance Parameters10Columns in X6Columns in ZSubjects27Max Obs Per Subject4As one can see, we do not have a Z matrix for this modelNumber of ObservationsNumber of Observations Read108Number of Observations UsedNumber of Observations Not UsedIteration HistoryIterationEvaluations-2 Log LikeCriterion12Convergence criteria met.the convergence of the Newton-Raphson algorithm means that we have found the maximum likelihood estimates
54 Covariance Parameter Estimates Cov ParmSubjectEstimateStandard ErrorZ ValuePr ZUN(1,1)Person5.11921.41693.610.0002UN(2,1)2.44090.98352.480.0131UN(2,2)3.92791.08243.630.0001UN(3,1)3.61051.27672.830.0047UN(3,2)2.71751.07402.530.0114UN(3,3)5.97981.62793.67UN(4,1)2.52221.06492.370.0179UN(4,2)3.06241.01353.020.0025UN(4,3)3.82351.25083.060.0022UN(4,4)4.61801.2573The table lists the 10 estimated covariance parameters in order. In other words, these are the estimates for R, the variance of 𝜀
55 Solution for Fixed Effects GenderEstimateStandard ErrorDFt ValuePr > |t|Intercept0.93562516.93<.0001F1.58311.46581.080.2904M.Age0.826810.45Age*Gender0.1239-2.830.0091From this table, we see that the boys intercept is at , whole the girls intercept is at =17.42.The estimate of the boys’ slope is at 0.827, while the girls’ slpe is at =0.477So the girls’ starting point is higher than the girls but their growth rate is only about half of that of the boys
56 Type 3 Tests of Fixed Effects Num DFDen DFF ValuePr > FGender1251.170.2904Age110.54<.0001Age*Gender7.990.0091This is probably the most important table from our results:The gender row tests the null hypothesis that girls and boys have a common intercept.As we can see we cannot reject that hypothesisThe Age tests the null hypothesis that age does not affect the growth rate.As we can see, we reject the null hypothesis as the F-value is large.The Age*gender tests reveals that there is a difference in slope at the 1% significance level.
57 Repeated Measures ANOVA vs. Independent Measures ANOVA Magarate Brown
58 Can we just use standard ANOVA with repeated measures data? No, Independent Measures (standard) ANOVA assumes the data are independent.Data from a repeated measures experiment not independent
59 How are standard ANOVA and repeated measures ANOVA the same? Independent measures ANOVA: an extension of the pooled variance t-testRepeated Measures ANOVA: an extension of the paired sample t-test
60 How are standard ANOVA and repeated measures ANOVA the same? Independent measures ANOVA: assumes the population variances are equal (homogeneity of variance)Repeated Measures ANOVA: sphericity assumption that the population variances of all the differences are equal
61 How are standard ANOVA and repeated measures ANOVA the same? Both assume Normality of the population
62 Advantages to using Repeated Measures instead of Independent Measures Limited number of subjects availablePrefer to limit the number of subjectsLess variability (finger tapping with caffeine example)Can examine effects over time
63 Drawbacks Practice effect Example: subjects get better at performing a task each time with “practice”Differential transfer: “This occurs when the effects of one condition persist and affect participants’ experiences during subsequent conditions.” (format:Example: medical treatments