Repeated Measures Analysis of Variance Using R
文章推薦指數: 80 %
I should point out that there are a number of different ways of performing ... R for repeated measures # One within subject measure and no ... RepeatedMeasuresAnalysisofVarianceUsingR RunningarepeatedmeasuresanalysisofvarianceinRcanbeabitmoredifficultthanrunningastandardbetween-subjectsanova.Thispageisintendedtosimplyshowanumberofdifferentprograms,varyinginthenumberandtypeofvariables.InanothersectionIhavegonetoextendthistorandomizationtestswithrepeatedmeasures,andyoucanfindthatpageatwww.uvm.edu/~dhowell/StatPages/R/RandomRepeatedMeasuresAnovaR.html IshouldpointoutthatthereareanumberofdifferentwaysofperformingthisanalysiswithinR,andsettingthemupisnotalwaysobvious.ButIstronglyrecommendthatyoudoasearchunder"RepeatedmeasuresanalysisofvarianceusingR."Ithinkthatyouwillbesurprisedatthequalityofthediscussionsyouwillfind.IparticularlylikethissitebyRudolfCardinalatCambridge.Butthereareawholebunchofreallygoodsitesoutthere.(IlookupRstuffsooftenthatGoogledefaultstothatifIjusttype"R".Yourmightbewisetouse"R-project"forawhileuntilitgetstheidea.Otherwiseyoumightjustgetabunchofstuffaboutthealphabet.) Anexamplewith1repeatedmeasure ThefollowingexampleislooselybasedonastudybyNolen-Hoeksemaand Morrow(1991).Theauthorshadthegoodfortunetohavemeasureddepressionin collegestudentstwoweeksbeforetheLomaPrietaearthquakeinCaliforniain 1987.Aftertheearthquaketheywentbackandtrackedchangesindepressionin thesesamestudentsovertime.Thefollowingexampleisbasedontheirwork,and assumesthatparticipantswereassessedeverythreeweeksforfivemeasurement sessions. IhavechangedthedatafromtheonesthatIhaveusedelsewheretobuildin aviolationofourstandardassumptionofsphericity.Ihavemademeasurements closeintimecorrelatehighly,butmeasurementsseparatedby9or12weeks correlatelesswell.Thisisprobablyaveryreasonablethingtoexpect,butit doesviolateourassumptionofsphericity. Ifweranatraditionalrepeated-measuresanalysisofvarianceonthesedata wewouldfind NoticethatFobt=2.726,whichissignificant,basedon unadjusteddf,withp=.034.GreenhouseandGeisser'scorrection factoris0.617,whileHuynhandFeldt'sis0.693.Bothoftheseleadtoan increaseinthevalueofp,andneitherissignificantatα =.05.(TheFfromamultivariateanalysisofvariance,whichdoesnot requiresphericityhasp=.037.) RCodeforOneWithinSubjectVariable #Rforrepeatedmeasures #Onewithinsubjectmeasureandnobetweensubjectmeasures #Besuretorunthisfromthebeginningbecause #otherwisevectorsbecomelongerandlonger. library(car) rm(list=ls()) ##Youwanttoclearoutoldvariables--with"rm(list=ls())"-- ##beforebuildingnewones. data Error:factor(Subject) DfSumSqMeanSqFvaluePr(>F) Residuals24953.739.74 Error:Within DfSumSqMeanSqFvaluePr(>F) factor(time)494.323.5722.7260.0337* Residuals96830.18.647 --- Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1 ----------------------------- Anexamplewithtworepeatedmeasures Havingtworepeatedmeasuresisnotreallymuchdifferentthanhavingone.Insteadofeachsubject'sdataacrosstheonemeasure,wewillrandomizeitacrossthesecondmeasureaswell.Forexample,ifwehada2X5design,bothmeasuresbeingrepeated,eachsubjectwouldhave10scoresandthose10scoreswouldberandomized. ThedataaretakenfromastudybyBoutonandSwartzentruber(1985)onconditionedsuppression,butIhaveonlyusedthedatafromGroup2.(ThisstudyisdiscussedinmybookonStatisticalMethodsforPsychologists,8thed.)onpage484ff.Inthisstudyeachof8subjectswasmeasuredacrosstwocyclesoneachof4phases,soCycleandPhasearerepeatedmeasures.Thecodeisshownbelow. ###TestforTwoWithin-SubjectRepeatedMeasures ###OnetrickypartofthiscodecamefromBenBauerattheUniv.ofTrent,Canada. ###HewritescodethatismoreR-likethanIdo.Infact,heknowsmoreaboutRthan ###Ido. #Twowithinsubjectvariables,1:8 #DatafromBouton&Schwartzentruber(1985)--Group2 #Methods8,p.486 dataelsewhereexceptwitharandomizationapproach. #Theresutsfollow_____________________________________________________ Error:Subj DfSumSqMeanSqFvaluePr(>F) Residuals784111202 Error:Subj:Cycle DfSumSqMeanSqFvaluePr(>F) Cycle1110.2110.252.8770.134 Residuals7268.238.32 Error:Subj:Phase DfSumSqMeanSqFvaluePr(>F) Phase3283.494.461.0290.4 Residuals211928.191.82 Error:Subj:Cycle:Phase DfSumSqMeanSqFvaluePr(>F) Cycle:Phase3147.649.210.7280.547 Residuals211418.967.57 OneBetweenSubjectVariable,OneWithinSubjectVariable. Iamgoingtouseanexampleofastudywithonebetweensubjectmeasureandonewithinsubjectmeasure,ThedataarefromastudybyKing(1986)onmotoractivityinratsfollowingtheadministrationofmidazolamunderthreedifferentconditions. #ThiscodewasoriginallywrittenbyJoshuaWiley,inthePsychologyDepartmentatUCLA. #ModifiedforonebetweenandonewithinforKing.datbydch ###HowellTable14.4### ##RepeatedMeasuresANOVAwith2variables ##Readindata,convertto'long'format,andfactor() dat Error:subject DfSumSqMeanSqFvaluePr(>F) Group22858151429087.8010.00293** Residuals2138472218320 Error:subject:Interval DfSumSqMeanSqFvaluePr(>F) Interval53997377994729.852<2e-16*** Group:Interval108082080823.0180.00216** Residuals1052811992678 --- TwoBetweenandOneWithin #Twobetweensubjectvariables,onewithin #DatafromSt.Lawrenceetal.(1995) #Methods8,p.479 #Note:IndatafileeachsubjectiscalledaPerson,andIconvertthattoafactor. #Inreshape,itcreatesavariablecalled"subject,"butthatisnotwhatIwanttouse. #InaovthemodelisbasedonPerson,notsubject. rm(list=ls()) dataF) Condition11071070.2150.6457 Sex1335833586.7310.0136* Condition:Sex164640.1280.7228 Residuals3617961499 --- Error:Person:Time DfSumSqMeanSqFvaluePr(>F) factor(Time)327491.40.8960.4456 Condition:factor(Time)31378459.34.5070.0051** Sex:factor(Time)3780260.02.5510.0594. Condition:Sex:factor(Time)3476158.81.5580.2037 Residuals10811006101.9 ... TwoWithin-SubjectRepeatedMeasures andOneBetween-subjectsMeasure ThesedataarefromthesameBoutenandSwartzentrubstudyusedabove.ThedifferenceisthatIhaveusedallthreegroups. rm(list=ls()) dataF) Group246172308.43.0830.067. Residuals2115723748.7 --- Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1 Error:Subj:Cycle DfSumSqMeanSqFvaluePr(>F) Cycle32727909.012.0272.53e-06*** Group:Cycle61047174.52.3090.0445* Residuals63476175.6 --- Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1 Error:Subj:Phase DfSumSqMeanSqFvaluePr(>F) Phase11170311703129.851.88e-10*** Group:Phase24054202722.496.01e-06*** Residuals21189390 --- Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1 Error:Subj:Cycle:Phase DfSumSqMeanSqFvaluePr(>F) Cycle:Phase3742247.174.0350.01090* Group:Cycle:Phase61274212.303.4660.00505** Residuals63385961.26 --- Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1 Lastrevised:6/26/2015
延伸文章資訊
- 1Repeated Measures of ANOVA in R Complete Tutorial
The two-way repeated measures ANOVA can be performed in order to determine whether there is a sig...
- 2Repeated Measures ANOVA in R: The Ultimate Guide
- 3How to Perform a Repeated Measures ANOVA in R - Statology
A repeated measures ANOVA is used to determine whether or not there is a statistically significan...
- 4R Handbook: Repeated Measures ANOVA
Repeated Measures ANOVA ... When an experimental design takes measurements on the same experiment...
- 5One-way Repeated Measure ANOVA - RPubs
Introduction. The repeated measures ANOVA makes the following assumptions about the data: No sign...