Sunteți pe pagina 1din 5

StatisticsforHCIResearch:KruskalWallis

Login/Register Search:

KruskalWallisandFriedmantest
TableOfContents
1. Introduction
2. Effectsize
3. Rcodeexample(KruskalWallis)
4. Rcodeexample(Friedman)
5. Posthoctest
6. Howtoreport

Introduction
KruskalWallisisbasicallyanonparametricversionof ANOVA .Thus,ifyouhavethedatawhichcontainmorethantwogroupstocompare,
andyourdataareordinaloryourdatacannotassumethenormality,KruskalWallisisthewaytogo.Fortunately,inR,thewaytorunaKruskal
WallistestissimilartothewaytorunanANOVAtest.
ThereisalsoanonparametricversionofrepeatedmeasureANOVA,whichiscalledFriedmantest.Ifyouarecomparingthedataagainsta
betweensubjectfactor,youcanuseaKruskalWallistest.Otherwise,youneedtouseaFriedmantest.
Asyoucanseeintheexamplebelow,KruskalWallisandFriedmantestsonlysupportaonewayanalysis.Thismeansthatyoucancomparethe
dataonlyacrossonefactorandunfortunately,youcannoteasilyextendtheseteststotwowayormixeddesignaswecandowithANOVA.This
isoneofthecostsyouhavetopaywhenyouhavetouseanonparametrictest.Iwillpostnonparametricmethodsequivalenttotwoway
repeatedmeasureormixeddesignANOVAonceIfigurethemout.

Effectsize
Unfortunately,thereisnostraightwaytocalculatetheeffectsizeofKruskalWallistestorFriedmantest.Instead,youcancalculatetheeffectsize
intheposthoctestwithMannWhitneyorWilcoxontest.Theeffectsizeofthosetestsarecalculatedasfollows:

,
whereNisthetotalnumberofthesamples.Hereisthestandardvalueofrforsmall,medium,andlargesizes.
smallsize mediumsize largesize
abs(r) 0.1

0.3

0.5

KruskalWallisandFriedmantestsgiveyouachisquared.However,itsdegreeoffreedomismorethan1,andthusitisnotstraightforwardto
convertthechisquaredintotheeffectsize.Thus,wecalculatetheeffectsizefortheposthoccomparison.

Rcodeexample(KruskalWallis)
First,youneedtopreparethedata

> Value <- c(1,2,5,3,2,1,1,3,2,1,4,3,6,5,2,6,1,6,5,4,


+ 9,6,7,7,5,1,8,9,6,5)
> Group <- factor(c(rep(1,10),rep(2,10),rep(3,10)))

> data <- data.frame(Group, Value)

Then,runaKruskalWallistest.TheformatisprettymuchthesameasANOVA.

> kruskal.test(Value ~ Group, data=data)

Nowyougettheresult.

Kruskal-Wallis rank sum test


data: Value by Group
Kruskal-Wallis chi-squared = 13.6754, df = 2, p-value = 0.001073

So,wehaveasignificanteffectofGroup.

Rcodeexample(Friedman)
Let'susethesamedataasintheexampleofaKruskalWallistest.ButweneedtoformatthedatasothatGrouprepresentsawithinsubjectfactor.

> data2 <- cbind(data[data$Group==1,]$Value, data[data$Group==2,]$Value,


+ data[data$Group==3,]$Value)
> data2

[,1] [,2] [,3]


[1,]

[2,]

[3,]

[4,]

[5,]

[6,]

[7,]

[8,]

[9,]

[10,]

Therowsrepresentthevaluesfromeachparticipant.Now,yourunaFriedman"stest.

> friedman.test(data2)

Friedman rank sum test


data: data2
Friedman chi-squared = 15.6216, df = 2, p-value = 0.0004053

YouhaveasignificanteffectofGroup.

Posthoctest
SimilartoANOVA,youneedtodoaposthoctestafterKruskalWallisandFriedmanifyoufindasignificanteffect.Aswedomultiplettests
withBonferroniorHolmcorrection,wecandoMannWhitneyorWilcoxontestswiththesamecorrections.Ifyouhaveunpaired(factorial,or
nonrepeatedmeasure)data,youcandopairwisecomparisonwithaMannWhitneytest.First,takealookathowtodopairwisecomparisonwith
aMannWhitneytestwithBonferronicorrection.

> pairwise.wilcox.test(Value, Group, p.adj="bonferroni", exact=F)

Pairwise comparisons using Wilcoxon rank sum test


data: Value and Group
1

2 0.0418 3 0.0058 0.0791


P value adjustment method: bonferroni

Ifyouhaveanytiedvalueinyourdata,youcanonlycalculateanapproximatepvalue.(Youcantrytocalculatetheexactpvaluebychanging
theoptionto"exact=T",butwillgetwarningsifyouhaveties.)Unfortunately,itseemsthereisnowaytogetthisaround,butinmanycases,this
approximatepvalueiscloseenoughtotheexactpvalue,andwillnotcausealotoftroubles.Butifyoureallywanttobeveryprecise,youcan
calculatetheexactpvaluebyusingfunctionsincoinpackage,andmanuallyapplyBonferronicorrectionstothepvaluesyouhavegainedby
usingp.adjust()function.Fordoingthis,see MannWhitneypage or Wilcoxonpage .
InsteadofBonferronicorrection,youcanalsouseHolmcorrection.

> pairwise.wilcox.test(Value, Group, p.adj="holm", exact=F)

Pairwise comparisons using Wilcoxon rank sum test


data: Value and Group
1

2 0.0279 3 0.0058 0.0279


P value adjustment method: holm

Ifyouhaveawithinfactor(orrepeatedmeasuredata),youneedtospecifypairedsothatyouwilluseaWilcoxontest.

> pairwise.wilcox.test(Value, Group, p.adj="bonferroni", exact=F, paired=T)

Pairwise comparisons using Wilcoxon rank sum test


data: Value and Group

2 0.039 3 0.026 0.174


P value adjustment method: bonferroni

Forcalculatingtheeffectsize,youhavetodoaMannWhitneyorWilcoxontesttofindtheZvalue(whichisnecessaryforthecalculationofthe
effectsize).Inthisexample,wearegoingtouseaMannWhitneytest.IfyouneedtouseaWilcoxontest(i.e.,youhaveawithinsubjectfactor),
see thispage .

> library(coin)
> wilcox_test(Value ~ factor(Group), data=data[data$Group==1|data$Group==2,], distribution="exact")

Exact Wilcoxon Mann-Whitney Rank Sum Test


data: Value by factor(Group) (1, 2)
Z = -2.4975, p-value = 0.01177
alternative hypothesis: true mu is not equal to 0

Thus,theeffectsizeis

> 2.4975 / sqrt(20)

0.558458

Rememberthatyouhavetousethetotalsamplesize(10*2=20)tocalculatetheeffectsizer.

Howtoreport
YoucanreporttheresultsofKruskalWallisorFriedmantestasfollows:AKruskalWallistestrevealedasignificanteffectofGrouponValue(
(2)=13.7,p<0.01).AposthoctestusingMannWhitneytestswithBonferronicorrectionshowedthesignificantdifferencesbetween
GroupAandB(p<0.05,r=0.56)andbetweenGroupAandC(p<0.01,r=0.70).

Comments[Showthecommentform]
Couldyoumaybeaddthedateyouuploadedthisinformation,thenIcanusethisasareferenceinmypaper!
Anonymous(2013031603:52:04)

Iamgladtoknowthatyouarewillingtocitemywebsite.ButIdon'treallyrecommendanyonecitingawebsite(notjustmine)becauseitisnot
archivalinnature.
KruskalWallisandFriedmantestsarewellexplainedinmanyofentrylevelnonparametricstatisticalbooks.Justgraboneoftheminalibrary,and
makesurethatthecontenthereisnotwrong,andcitethatbookforyourpaper!
KojiYatani(2013031818:40:40)

Iwouldliketo,butI'musinginformationonthiswebsiteabouttheposthoctestsafterinvestigatedthatthenullhypethesisoftheFriedmanand

KruskalWallistestcanberejectedandtofindwhereexactlythedifferencescanbefound.Ihaven'tfoundanybooks/officialarticlesaboutposthoc
tests,that'swhyIneededthiswebsiteasareference.
Anonymous(2013032401:15:49)

Owner:KojiYatani

ValidXHTML1.0Transitional::ValidCSS::PoweredbyWikkaWiki

S-ar putea să vă placă și