# [R] kruskal.test followed by kruskalmc

peter dalgaard pdalgd at gmail.com
Fri Jul 5 16:04:25 CEST 2013

```On Jul 5, 2013, at 15:00 , Humber Andrade wrote:

> Thank you Prof. José Iparraguirre. Maybe I am wrong but I think the issues
> are not the same. His data doesn't showed significant differences after
> kruskal.test(), that was not my case. Anyway follow below my the results
> I've got and the database.
>

This can happen. It is a matter of probability theory, not of R. The following is a simplified paraphrase of what is going on:

# 15 random normals, compare range test to variance test
# Simulate everything for simplicity

# Null distribution
M0 <- replicate(10000, rnorm(15))
vv <- apply(M0,2,var)
rg <- apply(M0,2,range)
rr <- apply(rg,2,diff)
r.95  <- quantile(rr, .95)
v.95  <- quantile(vv, .95)
v.995 <- quantile(vv, .995)

M <- replicate(10000, rnorm(15,sd=2))
vv <- apply(M,2,var)
rg <- apply(M,2,range)
rr <- apply(rg,2,diff)
plot(rr,vv)
abline(h=c(v.95,v.995),v=r.95, col="red")

Notice that the two statistics are correlated, but not equivalent. There are cases where one value is beyond the .95 level and the other is not. Since it is theoretically optimal to use the variance as the test statistic in this model, there are quite a few more cases where  rr is below the cutoff and vv is above than the other way around. There are even a sizable number of cases where vv is beyond v.995 and rr does not reach r.95.

(The theoretical optimality applies only because I use an increased variance alternative. For specific alternatives, the picture can change. Try it, for instance with a single mean substantially different from the others:

M <- replicate(10000, rnorm(15,mean=rep(c(4,0),c(1,14))))

)

> Thank you,
>
> #################
>> kruskal.test(data\$resp,data\$group)
>
>    Kruskal-Wallis rank sum test
>
> data:  data\$resp and data\$group
> Kruskal-Wallis chi-squared = 32.3546, df = 14, p-value = 0.003566
> ################
>> kruskalmc(data\$resp,data\$group)
> Multiple comparison test after Kruskal-Wallis
> p.value: 0.05
> Comparisons
>       obs.dif critical.dif difference
> A-B  4.8303571     62.37688      FALSE
> A-C  3.8928571     62.37688      FALSE
> A-D  0.4821429     62.37688      FALSE
> .............................................................
> .............................................................
> .............................................................
> M-P 14.2500000     60.26179      FALSE
> N-O  1.3750000     60.26179      FALSE
> N-P  6.1250000     60.26179      FALSE
> O-P  4.7500000     60.26179      FALSE
>
> ############# database
>   group resp  A 0.1  A 581.8  A 90.5  A 70.1  A 820.1  A 1159.2  A 2478.1
> A 2475.3  B 351.8  B 370.1  B 326.1  B 751.9  B 931  B 588.2  B 70.1  B
> 1754.9  C 289.8  C 254.1  C 370.3  C 459.8  C 412.5  C 591.5  C 986.9  C 890
> D 425.6  D 397.4  D 464  D 370.9  D 417.3  D 455  D 568.2  D 599.4  E 405.1
> E 626.2  E 299  E 493.8  E 362.6  E 309.8  E 522.7  E 433.3  F 698.6  F 42.5
> F 7.4  F 10.6  F 95.8  F 497.5  F 987.9  F 925.1  G 492.9  G 376  G 413  G
> 278.3  G 344.2  G 292.2  G 429.4  G 368  H 241.6  H 230.5  H 310.4  H 372.5
> H 366.1  H 307.9  H 480  H 529.8  I 296  I 288.8  I 302.1  I 300.8  I 150.1
> I 381.9  I 583.1  I 489.4  J 1.2  J 18.6  J 7.7  J 11.6  J 48.1  J 121.8  J
> 1284.1  J 944.7  L 0.5  L 44.4  L 80.9  L 15.3  L 80  L 379.9  L 940.6  L
> 829.3  M 323.6  M 401.5  M 162.1  M 136.5  M 139.4  M 363.3  M 280.7  M
> 356.5  N 197.6  N 245.9  N 221.5  N 224.3  N 185.4  N 265.3  N 304.8  N
> 351.9  O 189.9  O 237.3  O 247.1  O 230.4  O 272.2  O 155.1  O 270.7  O
> 315.2  P 48.4  P 15.5  P 53.1  P 72.8  P 74.8  P 132.3  P 550  P 478.7
>
>
> On Fri, Jul 5, 2013 at 8:06 AM, Jose Iparraguirre <
> Jose.Iparraguirre at ageuk.org.uk> wrote:
>
>> Humber,
>> Have a look at this:
>> http://r.789695.n4.nabble.com/Multiple-Comparisons-Kruskal-Wallis-Test-kruskal-agricolae-and-kruskalmc-pgirmess-don-t-yield-the-sa-td4639004.html
>> Hope it helps.
>> Kind regards,
>>
>> José
>>
>> Prof. José Iparraguirre
>> Chief Economist
>> Age UK
>>
>>
>>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
>> On Behalf Of Humber Andrade
>> Sent: 05 July 2013 11:38
>> To: r-help at r-project.org
>> Subject: [R] kruskal.test followed by kruskalmc
>>
>> Hi all,
>>
>> After running kruskal.test I have got results (p<0,005) pointing to reject
>> the hypothesis that the samples were draw from the same population.
>> Howerver when I run the kruskalmc there are no significant differences in
>> any of the multiple comparisons. Is that possible? Some clarification?
>>
>> Thanks, Humber
>>
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> The Wireless from Age UK | Radio for grown-ups.
>>
>> www.ageuk.org.uk/thewireless
>>
>>
>> If you‚re looking for a radio station that offers real variety, tune in to
>> The Wireless from Age UK.
>> Whether you choose to listen through the website at
>> www.ageuk.org.uk/thewireless, on digital radio (currently available in
>> London and Yorkshire) or through our TuneIn Radio app, you can look forward
>> to an inspiring mix of music, conversation and useful information 24 hours
>> a day.
>>
>>
>>
>>
>> -------------------------------
>> Age UK is a registered charity and company limited by guarantee,
>> (registered charity number 1128267, registered company number 6825798).
>> Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.
>>
>> For the purposes of promoting Age UK Insurance, Age UK is an Appointed
>> Representative of Age UK Enterprises Limited, Age UK is an Introducer
>> Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth
>> Access for the purposes of introducing potential annuity and health
>> cash plans customers respectively.  Age UK Enterprises Limited, JLT
>> Benefit Solutions Limited and Simplyhealth Access are all authorised and
>> regulated by the Financial Services Authority.
>> ------------------------------
>>
>> This email and any files transmitted with it are confidential and intended
>> solely for the use of the individual or entity to whom they are
>> delete immediately.
>>
>> Except where this email is sent in the usual course of our business, any
>> opinions expressed in this email are those of the author and do not
>> necessarily reflect the opinions of Age UK or its subsidiaries and
>> associated companies. Age UK monitors all e-mail transmissions passing
>> through its network and may block or modify mails which are deemed to be
>> unsuitable.
>>
>> Age Concern England (charity number 261794) and Help the Aged (charity
>> number 272786) and their trading and other associated companies merged
>> on 1st April 2009.  Together they have formed the Age UK Group, dedicated
>> to improving the lives of people in later life.  The three national
>> Age Concerns in Scotland, Northern Ireland and Wales have also merged with
>> Help the Aged in these nations to form three registered charities:
>> Age Scotland, Age NI, Age Cymru.
>>
>>
>>
>>
>>
>
>
> --
> Universidade Federal Rural de Pernambuco - UFRPE
> Depto. Pesca e Aqüicultura - DEPAq
> Lab. Modelagem Estatística Aplicada - MOE
> Av. Dom Manoel de Medeiros s/n
> Dois Irmãos
> 52171-030    Recife-PE   Brazil
> Tel: (81) 3320-6530
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help