Two-way ANOVA - Advanced Statistics using R
文章推薦指數: 80 %
Two-way analysis of variance (two-way ANOVA) is an extension of the one-way ANOVA to examine the influence of two different categorical independent ... Guest|Login|Register|Questions|TableofContents tTest(chapter) One-WayANOVA Two-wayANOVA Repeated-measuresANOVA SimpleRegression(chapter) Two-wayANOVA Two-wayanalysisofvariance(two-wayANOVA)isanextensionoftheone-wayANOVAto examinetheinfluenceoftwodifferentcategoricalindependentvariablesononecontinuousdependentvariable.Thetwo-wayANOVAcanevaluate notonlythemaineffectofeachindependentvariablebutalsothepotential interactionbetweenthem.Forexample,fortheACTIVEdata,wecantestwhetherthefourtraininggroupsandgenderarerelatedtothememorytestperformance. Typeofeffectsandhypotheses Intwo-wayANOVAwithtwofactors(independentvariables)AandB,wecantesttwomaineffectsandoneinteractioneffect: MaineffectofA:whetherthepopulationmeansarethesamefordifferentlevels(groups)ofA? Thenullhypothesis:thepopulationmeansarethesamefordifferentlevelsofA. MaineffectofA:whetherthepopulationmeansarethesamefordifferentlevels(groups)ofA? Thenullhypothesis:thepopulationmeansarethesamefordifferentlevelsofA. TheinteractioneffectofAandB:whetherthedifferenceinthepopulationmeansfordifferencelevelofAdependsonthelevelofBorvicevisa? Thenullhypothesis:theeffectofAorBontheoutcomedoesnotdependonBorA. Two-wayANOVAFtests Likeinone-wayANOVA,Ftestisusedinhypothesistesting.Thetestisconstructedbasedonthedecompositionofthesumofsquaresoftheoutcomevariables.Specifically,wehave \[SS_{T}=SS_{A}+SS_{B}+SS_{A\timesB}+SS_{W}\] $SS_T$or$SS_{total}$isthesumofsquaresfortheoutcomevariable. $SS_A$isthesumofsquaresattributestothefactorA. $SS_B$isthesumofsquaresattributestothefactorB. $SS_{A\timesB}$isthesumofsquaresattributestothejointeffectofAandB. $SS_{W}$or$SS_{within}$istheresidualsumofsquaresthatcannotbeexplainbyA,Bortheirinteraction. Let$N$bethesamplesize,$J$isthenumberoflevelsinfactorA,and$K$isthenumberoflevelsinfactorB.Withtheinformation,wecanconstructasourceofvariancetablebelow: Source Sumofsquares Degreeoffreedom Meansquare Fstatistic FactorA $SS_A$ $J-1$ $MS_A=\frac{SS_A}{J-1}$ $F_A=\frac{MS_A}{MS_W}$ FactorB $SS_B$ $K-1$ $MS_B=\frac{SS_B}{K-1}$ $F_B=\frac{MS_B}{MS_W}$ InteractionA*B $SS_{A\timesB}$ $(J-1)*(K-1)$ $MS_{A\timesB}=\frac{SS_{A\timesB}}{(J-1)\times(K-1)}$ $F_{A\timesB}=\frac{MS_{A\timesB}}{MS_W}$ Within $SS_W$ $N-(J\timesK)$ $MS_W=\frac{SS_W}{N-(J\timesK)}$ Total $SS_T$ $N-1$ Itiseasytoseethat$SS_T=SS_A+SS_B+SS_{A\timesB}+SS_W$.FortestingtheeffectofFactorA,wecomparethestatistic$F_A$toanFdistributionwithdegreesoffreedom$J-1$and$N-(J\timesK)$.FortestingtheeffectofFactorB,wecomparethestatistic$F_B$toanFdistributionwithdegreesoffreedom$K-1$and$N-(J\timesK)$.TotesttheinteractioneffectofFactorAandFactorB, wecomparethestatistic$F_{A\timesB}$toanFdistributionwithdegreesoffreedom$(J-1)*(K-1)$and$N-(J\timesK)$. Example:Effectsoftrainingandgenderonthememorytestperformance Asanexample,wetesttheeffectoftrainingandgenderonthememorytestperformanceusingtheACTIVEdata.Wewanttoanswerthefollowingquestions: Atthepopulationlevel,arethereanydifferenceinmemorytestperformanceforthe4traininggroups? Atthepopulationlevel, arethereanydifferenceinmemorytestperformanceformaleandfemaleparticipants? Dotheeffectsoftrainingonthememorytestperformancedifferacrossthetwogendergroups? TheRcodebelowcarriesoutthetwo-wayANOVAtoanswertheabovequestions. >usedata("active") >modelanova(model) AnalysisofVarianceTable Response:hvltt2 DfSumSqMeanSqFvaluePr(>F) factor(group)3859286.2010.24341.114e-06*** factor(sex)1919919.2832.90131.161e-08*** factor(group):factor(sex)33411.460.41020.7457 Residuals15674378327.94 --- Signif.codes:0'***'0.001'**'0.01'*'0.05'.'0.1''1 > Maineffectoftraininggroup Fromtheoutput,theF-statisticfortestingthemaineffectoftraininggroupis10.2434.BasedontheFdistributionwithdegreesoffreedom3and1567,thecorrespondingp-valueis1.114e-06,whichindicatesasignificantmaineffectfortraininggroup.Therefore,onemayconcludethereissignificantdifferenceinmemoryperformanceamongthefourgroups. Maineffectof sex Fromtheoutput,theF-statisticfortestingthemaineffectofsex is32.9013.BasedontheFdistributionwithdegreesoffreedom1and1567,thecorrespondingp-valueis1.161e-08,whichindicatesasignificantmaineffectsex.Therefore,onemayconcludethereissignificantdifferenceinmemoryperformancebetweenthemaleandfemaleparticipants. Interactioneffectbetweentraininggroupandsex Fromtheoutput,theF-statisticfortestingtheinteraction effect[factor(group):factor(sex)]is0.41.BasedontheFdistributionwithdegreesoffreedom3 and1567,thecorrespondingp-valueis0.7457,whichindicatesaninsignificantinteractioneffect.Therefore,onemayconcludethe differenceinmemoryperformance amongthefourtraininggroupdoesnotdependonsex. Plotdata Asinone-wayANOVA,wecanalsoplotdatawithtwofactorswitherrorbars.Thecodebelowcanbeused. >library(Rmisc) Loadingrequiredpackage:lattice Loadingrequiredpackage:plyr >library(ggplot2) > >usedata('active') >statsstats groupsexNhvltt2sdseci 1118524.529415.4129220.58711381.1675401 21230726.537465.1849200.29591900.5822937 3219223.347835.4539730.56861601.1294858 42229524.857635.2190190.30386310.5980225 5318423.785715.4773830.59763141.1886649 63232325.179574.9868100.27747350.5458900 74111222.544645.9500750.56222931.1140948 84227724.772565.3678700.32252400.6349197 > >ggplot(stats, +aes(x=factor(group),y=hvltt2,fill=factor(sex), +ymax=hvltt2+se,ymin=hvltt2-se))+ +geom_bar(stat="identity",position="dodge",width=0.7)+ +geom_bar(stat="identity",position="dodge", +colour="black",width=0.7)+ +geom_errorbar(position=position_dodge(width=0.7), +width=0.2,size=0.5,color="black")+ +labs(x="Group", +y="Memoryperformance")+ +scale_x_discrete(breaks=c("1","2","3","4"), +labels=c("Memory","Reasoning","Speed","Control")) > Tocitethebook,use: Zhang,Z.&Wang,L.(2017-2022).AdvancedstatisticsusingR.[https://advstats.psychstat.org].Granger,IN:ISDSAPress.ISBN:978-1-946728-01-2.Totakethefulladvantageofthebooksuchasrunninganalysiswithinyourwebbrowser,pleasesubscribe.
延伸文章資訊
- 1Chapter 27 Two-way ANOVA in R | APS 240
Carrying out a two-way ANOVA in R is really no different from one-way ANOVA. It still involves tw...
- 2Two-Way ANOVA Example in R-Quick Guide - R-bloggers
Two-Way ANOVA Example in R, the two-way ANOVA test is used to compare the effects of two grouping...
- 3Two-Way ANOVA Test in R - Easy Guides - Wiki - STHDA
Two-way ANOVA test is used to evaluate simultaneously the effect of two grouping variables (A and...
- 4ANOVA_2 - RPubs
Two-Way independent samples & Mixed design ANOVA with R Example. Data: WOW_data. 1.獨立樣本二因子變異數分析(T...
- 5Two-way Anova - R Companion
Two-way anova example · 1 male ff 1.884 · 2 male ff 2.283 · 3 male fs 2.396 · 4 female ff 2.838 ·...