R Handbook: Repeated Measures ANOVA

文章推薦指數: 80 %
投票人數:10人

Repeated Measures ANOVA ... When an experimental design takes measurements on the same experimental unit over time, the analysis of the data must take into ... SummaryandAnalysisofExtensionProgramEvaluationinR SalvatoreS.Mangiafico SearchRcompanion.org   Contents   Introduction PurposeofthisBook AuthorofthisBookandVersionNotes UsingR StatisticsTextbooksandOtherResources PrivacyPolicyforAdvertisements   StatisticsforEducationalProgramEvaluation WhyStatistics? EvaluationToolsandSurveys   Variables,DescriptiveStatistics,andPlots TypesofVariables DescriptiveStatistics ConfidenceIntervals BasicPlots   UnderstandingStatisticsandHypothesisTesting HypothesisTestingandp-values ReportingResultsofDataandAnalyses ChoosingaStatisticalTest IndependentandPairedValues   LikertData IntroductiontoLikertData DescriptiveStatisticsforLikertData DescriptiveStatisticswiththelikertPackage ConfidenceIntervalsforMedians ConvertingNumericDatatoCategories   TraditionalNonparametricTests IntroductiontoTraditionalNonparametricTests One-sampleWilcoxonSigned-rankTest SignTestforOne-sampleData Two-sampleMann–WhitneyUTest Mood’sMedianTestforTwo-sampleData Two-samplePairedSigned-rankTest SignTestforTwo-samplePairedData Kruskal–WallisTest Mood’sMedianTest FriedmanTest QuadeTest Scheirer–Ray–HareTest AlignedRanksTransformationANOVA NonparametricRegression NonparametricRegressionforTimeSeries   PermutationTests   IntroductiontoPermutationTests One-wayPermutationTestofIndependenceforOrdinalData One-wayPermutationTestofSymmetryforOrdinalData PermutationTestsforMediansandPercentiles   TestsforOrdinalDatainTables AssociationTestsforOrdinalTables MeasuresofAssociationforOrdinalTables   ConceptsforLinearModels IntroductiontoLinearModels UsingRandomEffectsinModels WhatareEstimatedMarginalMeans? EstimatedMarginalMeansforMultipleComparisons FactorialANOVA:MainEffects,InteractionEffects,andInteractionPlots p-valuesandR-squareValuesforModels AccuracyandErrorsforModels   OrdinalTestswithCumulativeLinkModels IntroductiontoCumulativeLinkModels(CLM)forOrdinalData Two-sampleOrdinalTestwithCLM Two-samplePairedOrdinalTestwithCLMM One-wayOrdinalRegressionwithCLM One-wayRepeatedOrdinalRegressionwithCLMM Two-wayOrdinalRegressionwithCLM Two-wayRepeatedOrdinalRegressionwithCLMM   TestsforNominalData IntroductiontoTestsforNominalVariables ConfidenceIntervalsforProportions Goodness-of-FitTestsforNominalVariables AssociationTestsforNominalVariables MeasuresofAssociationforNominalVariables TestsforPairedNominalData Cochran–Mantel–HaenszelTestfor3-DimensionalTables Cochran’sQTestforPairedNominalData ModelsforNominalData   ParametricTests IntroductiontoParametricTests One-samplet-test Two-samplet-test Pairedt-test One-wayANOVA One-wayANOVAwithBlocks One-wayANOVAwithRandomBlocks Two-wayANOVA RepeatedMeasuresANOVA CorrelationandLinearRegression AdvancedParametricMethods TransformingData NormalScoresTransformation   AnalysisofCountDataandPercentageData RegressionforCountData BetaRegressionforPercentandProportionData   OtherBooks AnRCompanionfortheHandbookofBiologicalStatistics     Advertisement RepeatedMeasuresANOVA   Advertisement Whenanexperimentaldesigntakesmeasurementsonthesame experimentalunitovertime,theanalysisofthedatamusttakeintoaccount theprobabilitythatmeasurementsforagivenexperimentalunitwillbe correlatedinsomeway. Forexample,ifweweremeasuringcalorieintakefor students,wewouldexpectthatifonestudenthadahigherintakeatTime1, thatthatstudentwouldhaveahigherintakeothersatTime2,andsoon.   Inpreviouschapters,ourapproachtodealwith non-independentobservationswastotreatStudentasablockingvariable orasarandom(blocking)variable.   Theapproachinthischapteristoincludean autocorrelationstructureinthemodelusingthenmlepackage.   Packagesusedinthischapter   Thepackagesusedinthischapterinclude: • psych • nlme • car • multcompView • lsmeans • ggplot2 • rcompanion   Thefollowingcommandswillinstallthesepackagesifthey arenotalreadyinstalled: if(!require(psych)){install.packages("psych")} if(!require(nlme)){install.packages("nlme")} if(!require(car)){install.packages("car")} if(!require(multcompView)){install.packages("multcompView")} if(!require(lsmeans)){install.packages("lsmeans")} if(!require(ggplot2)){install.packages("ggplot2")} if(!require(rcompanion)){install.packages("rcompanion")} RepeatedmeasuresANOVAexample   Inthisexample,studentswereaskedtodocumenttheirdaily caloricintakeonceamonthforsixmonths. Studentsweredividedintothree groupswitheachreceivinginstructioninnutritioneducationusingoneof threecurricula.   Therearedifferentwayswemightapproachthisproblem. If wesimplywantedtoseeifonecurriculumwasbetteratdecreasingcaloric intakeinstudents,wemightdoasimpleanalysisofvarianceonthedifference betweeneachstudent’sfinalandinitialintake.   Intheapproachherewewillusearepeatedmeasures analysiswithallthemeasurements,treatingStudentasarandom variabletotakeintoaccountnativedifferencesamongstudents,andincluding anautocorrelationstructure. Input=(" Instruction       Student Month  Calories.per.day 'CurriculumA'    a       1      2000 'CurriculumA'    a       2      1978 'CurriculumA'    a       3      1962 'CurriculumA'    a       4      1873 'CurriculumA'    a       5      1782 'CurriculumA'    a       6      1737 'CurriculumA'    b       1      1900 'CurriculumA'    b       2      1826 'CurriculumA'    b       3      1782 'CurriculumA'    b       4      1718 'CurriculumA'    b       5      1639 'CurriculumA'    b       6      1644 'CurriculumA'    c       1      2100 'CurriculumA'    c       2      2067 'CurriculumA'    c       3      2065 'CurriculumA'    c       4      2015 'CurriculumA'    c       5      1994 'CurriculumA'    c       6      1919 'CurriculumA'    d       1      2000 'CurriculumA'    d       2      1981 'CurriculumA'    d       3      1987 'CurriculumA'    d       4      2016 'CurriculumA'    d       5      2010 'CurriculumA'    d       6      1946 'CurriculumB'    e       1      2100 'CurriculumB'    e       2      2004 'CurriculumB'    e       3      2027 'CurriculumB'    e       4      2109 'CurriculumB'    e       5      2197 'CurriculumB'    e       6      2294 'CurriculumB'    f       1      2000 'CurriculumB'    f       2      2011 'CurriculumB'    f       3      2089 'CurriculumB'    f       4      2124 'CurriculumB'    f       5      2199 'CurriculumB'    f       6      2234 'CurriculumB'    g       1      2000 'CurriculumB'    g       2      2074 'CurriculumB'    g       3      2141 'CurriculumB'    g       4      2199 'CurriculumB'    g       5      2265 'CurriculumB'    g       6      2254 'CurriculumB'    h       1      2000 'CurriculumB'    h       2      1970 'CurriculumB'    h       3      1951 'CurriculumB'    h       4      1981 'CurriculumB'    h       5      1987 'CurriculumB'    h       6      1969 'CurriculumC'    i       1      1950 'CurriculumC'    i       2      2007 'CurriculumC'    i       3      1978 'CurriculumC'    i       4      1965 'CurriculumC'    i       5      1984 'CurriculumC'    i       6      2020 'CurriculumC'    j       1      2000 'CurriculumC'    j       2      2029 'CurriculumC'    j       3      2033 'CurriculumC'    j       4      2050 'CurriculumC'    j       5      2001 'CurriculumC'    j       6      1988 'CurriculumC'    k       1      2000 'CurriculumC'    k       2      1976 'CurriculumC'    k       3      2025 'CurriculumC'    k       4      2047 'CurriculumC'    k       5      2033 'CurriculumC'    k       6      1984 'CurriculumC'    l       1      2000 'CurriculumC'    l       2      2020 'CurriculumC'    l       3      2009 'CurriculumC'    l       4      2017 'CurriculumC'    l       5      1989 'CurriculumC'    l       6      2020 ") Data=read.table(textConnection(Input),header=TRUE) ### Orderfactorsbytheorderindataframe ### Otherwise,Rwillalphabetizethem Data$Instruction=factor(Data$Instruction,                         levels=unique(Data$Instruction)) ### Checkthedataframe library(psych) headTail(Data) str(Data) summary(Data) ###Removeunnecessaryobjects rm(Input) Definemodelandconductanalysisofdeviance Thisexamplewilluseamixedeffectsmodeltodescribethe repeatedmeasuresanalysis,usingthelmefunctioninthenlme package. Studentistreatedasarandomvariableinthemodel.   Theautocorrelationstructureisdescribedwiththecorrelation statement. Inthiscase,corAR1isusedtoindicateatemporalautocorrelation structureoforderone,oftenabbreviatedasAR(1). Thisstatementtakesthe form: correlation=Structure(form =~time|subjvar) where: • Structureistheautocorrelationstructure. Options arelistedinlibrary(nlme);?corClasses • timeisthevariableindicatingtime. Inthiscase,Month.  ForthecorAR1structure,thetimevariablemustbeanintegervariable. • subjvarindicatesthevariableforexperimental units,inthiscaseStudent. Autocorrelationismodeledwithinlevels ofthesubjvar,andnotbetweenthem.   ForthecorAR1structure,avalueforthefirstorder correlationcanbespecified. Inthiscase,thevalueof0.429isfoundusing theACFfunctioninthe“Optionalanalysis:determiningautocorrelation inresiduals”sectionbelow.   Autocorrelationstructurescanbechosenbyeitheroftwo methods. Thefirstistochooseastructurebasedontheoreticalexpectations ofhowthedatashouldbecorrelated. Thesecondistotryvarious autocorrelationstructuresandcomparetheresultingmodelswithacriterion likeAIC,AICc,orBICtochoosethestructurethatbestmodelsthedata.   Optionaltechnicalnote: Inthiscase,itisn’tnecessarytouseamixedeffects model. Thatis,it’snotnecessarytoincludeStudentasarandom variable. Asimilaranalysiscouldbeconductedbyusingthegls functioninthenlmepackage,andincludingthecorrelation option,butexcludingtherandomoption,asfollowsinblack.   library(nlme) model=gls(Calories.per.day~Instruction+Month+Instruction*Month,            correlation=corAR1(form=~Month|Student,                                 value=0.8990),            data=Data,            method="REML") library(car) Anova(model) Codeforanalysis library(nlme) model=lme(Calories.per.day~Instruction+Month+Instruction*Month,            random=~1|Student,            correlation=corAR1(form=~Month|Student,                                 value=0.4287),            data=Data,            method="REML") library(car) Anova(model) AnalysisofDevianceTable(TypeIItests) Response:Calories.per.day                    ChisqDfPr(>Chisq)    Instruction      10.4221 2  0.005456** Month             0.0198 1  0.888045    Instruction:Month38.6045 2 4.141e-09*** Testtherandomeffectsinthemodel Therandomeffectsinthemodelcanbetestedbycomparing themodeltoamodelfittedwithjustthefixedeffectsandexcludingthe randomeffects. Becausetherearenotrandomeffectsinthissecondmodel,the glsfunctioninthenlmepackageisusedtofitthismodel. model.fixed=gls(Calories.per.day~Instruction+Month+Instruction*Month,                  data=Data,                  method="REML") anova(model,      model.fixed)            Modeldf     AIC     BIC   logLik  TestL.Ratiop-value model          1 9716.9693736.6762-349.4847                       model.fixed    2 7813.6213828.9489-399.81061vs2100.652 <.0001 p-valueandpseudor-squaredformodel thenagelkerkefunctioncanbeusedtocalculateap-value andpseudor-squaredvalueforthemodel. oneapproachistodefinethenullmodelasonewithno fixedeffectsexceptforanintercept sideofthe library model.null="lme(Calories.per.day~1," nagelkerke mcfadden coxandsnell anotherapproachtodeterminingthep-valueand pseudor-squaredforanlmemodelistocomparethemodeltoa nullmodelwithonlyaninterceptandneitherthefixednortherandomeffects. toaccomplishthis function. model.null.2="gls(Calories.per.day~1," post-hocanalysis thelsmeanspackageisabletohandlelme objects. meanseparationtestsandleastsquaremeans leastsquaremeans comparisons theone-wayanovachapter. becausemonthisanintegervariable variable only. marginal="lsmeans(model," cld lettersfor.group instruction confidencelevelused:0.95 conf-leveladjustment:sidakmethodfor3estimates pvalueadjustment:tukeymethodforcomparingafamilyof3estimates significancelevelused:alpha="0.05.05" interactionplot forthisplot functiontocalculatethenaturalmeanofeachinstructionxmonth combination percentilemethod. sum="groupwiseMean(Calories.per.day~Instruction+Month,                   data  =Data," pd="position_dodge(.2)" ggplot histogramofresiduals residualsfromamixedmodelfitwithnlmeshouldbe normallydistributed. homoscedasticityandindependence x="residuals(model)" plotnormalhistogram plot optionalanalysis:determiningautocorrelationin residuals theacffunctioninthenlmepackagewill indicatetheautocorrelationforlagsinthetimevariable. glsmodel foranlmemodel equallyspacedintervals. model.a="gls(Calories.per.day~Instruction+Month+Instruction*Month," acf model.b="lme(Calories.per.day~Instruction+Month+Instruction*Month," optionaldiscussiononspecifyingformulaefor repeatedmeasuresanalysis specifyingrandomeffectsinmodels thegeneralschemaforspecifyingrandomeffectsinris: formula.for.random.effects sothat intercept interceptanditsownslopeforrep willhaveitsownintercept indicatingtimeandsubjectvariables asimplerepeatedanalysisstatementinprocmixedin sascouldbespecifiedwith: repeateddate asimilarspecificationinwiththeglsfunctioninnlme packageinrwouldbe: correlation="corAR1(form=~date|id)" likewise inprocmixedinsascouldbespecifiedwith: randomid asimilarspecificationinwiththelmefunctioninnlme random="~1|id," specifyingnestedeffects inrepeatedmeasuresanalysis effects. insas: treatment isequivalentto blockblock inr: block cooperativeextension non-commercialreproductionofthiscontent attribution isprohibited. ifyouusethecodeorinformationinthissitein apublishedwork mycontactinformationisonthe abouttheauthorof thisbookpage. thissiteusesadvertisingfrommedia.net.formoreinformation ourprivacypolicypage. proceedsfrom theseadsgotosupporteducationandresearchactivities includingtheimprovementofthissite. citation mangiafico programevaluationinr rcompanion.org>



請為這篇文章評分?