forked from saundersg/Statistics-Notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kruskal.html
685 lines (616 loc) · 24.2 KB
/
Kruskal.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Kruskal-Wallis Test</title>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cerulean.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/accessible-code-block-0.0.1/empty-anchor.js"></script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="styles.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
</style>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 51px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h1 {
padding-top: 56px;
margin-top: -56px;
}
.section h2 {
padding-top: 56px;
margin-top: -56px;
}
.section h3 {
padding-top: 56px;
margin-top: -56px;
}
.section h4 {
padding-top: 56px;
margin-top: -56px;
}
.section h5 {
padding-top: 56px;
margin-top: -56px;
}
.section h6 {
padding-top: 56px;
margin-top: -56px;
}
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #ffffff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script>
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark it active
menuAnchor.parent().addClass('active');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
background: white;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
</head>
<body>
<div class="container-fluid main-container">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Statistics Notebook</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
R Help
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="RCommands.html">R Commands</a>
</li>
<li>
<a href="RMarkdownHints.html">R Markdown Hints</a>
</li>
<li>
<a href="RCheatSheetsAndNotes.html">R Cheatsheets & Notes</a>
</li>
<li>
<a href="DataSources.html">Data Sources</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Describing Data
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="GraphicalSummaries.html">Graphical Summaries</a>
</li>
<li>
<a href="NumericalSummaries.html">Numerical Summaries</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Making Inference
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="MakingInference.html">Making Inference</a>
</li>
<li>
<a href="tTests.html">t Tests</a>
</li>
<li>
<a href="WilcoxonTests.html">Wilcoxon Tests</a>
</li>
<li>
<a href="ANOVA.html">ANOVA</a>
</li>
<li>
<a href="Kruskal.html">Kruskal-Wallis</a>
</li>
<li>
<a href="LinearRegression.html">Linear Regression</a>
</li>
<li>
<a href="LogisticRegression.html">Logistic Regression</a>
</li>
<li>
<a href="ChiSquaredTests.html">Chi Squared Tests</a>
</li>
<li>
<a href="PermutationTests.html">Randomization Testing</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Analyses
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="./Analyses/AnalysisRubric.html">Analysis Rubric</a>
</li>
<li>
<a href="./Analyses/StudentHousing.html">Good Example Analysis</a>
</li>
<li>
<a href="./Analyses/StudentHousingPOOR.html">Poor Example Analysis</a>
</li>
<li>
<a href="./Analyses/Rent.html">Rent</a>
</li>
<li>
<a href="./Analyses/Stephanie.html">Stephanie</a>
</li>
<li>
<a href="./Analyses/t Tests/HighSchoolSeniors.html">High School Seniors</a>
</li>
<li>
<a href="./Analyses/Wilcoxon Tests/RecallingWords.html">Recalling Words</a>
</li>
<li>
<a href="./Analyses/ANOVA/DayCare.html">Day Care</a>
</li>
<li>
<a href="./Analyses/Kruskal-Wallis/Food.html">Food</a>
</li>
<li>
<a href="./Analyses/Linear Regression/MySimpleLinearRegression.html">My Simple Linear Regression</a>
</li>
<li>
<a href="./Analyses/Linear Regression/CarPrices.html">Car Prices</a>
</li>
<li>
<a href="./Analyses/Logistic Regression/MyLogisticRegression.html">My Logistic Regression</a>
</li>
<li>
<a href="./Analyses/Chi Squared Tests/MyChiSquaredTest.html">My Chi-sqaured Test</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Kruskal-Wallis Test</h1>
</div>
<script type="text/javascript">
function showhide(id) {
var e = document.getElementById(id);
e.style.display = (e.style.display == 'block') ? 'none' : 'block';
}
</script>
<hr />
<p>The nonparametric equivalent to one-way <a href="ANOVA.html">ANOVA</a>.</p>
<hr />
<div id="kruskal-wallis-rank-sum-test" class="section level3 tabset tabset-fade tabset-pills">
<h3>Kruskal-Wallis Rank Sum Test</h3>
<div style="float:left;width:125px;" align="center">
<p><img src="Images/QuantYQualXg3plus.png" width=58px;></p>
</div>
<p>Allows for deciding if several samples come from the same population or if at least one sample comes from a different population.</p>
<div id="overview" class="section level4">
<h4>Overview</h4>
<div style="padding-left:125px;">
<p>It is assumed that the various populations are of approximately the same form, but are shifted or translated.</p>
<p>Can also be used when data is ordered (ordinal) but does not have an exact measurement.</p>
<p>Best used when the distribution of the data is not normal. ANOVA is appropriate when the data is normal.</p>
<p><strong>Hypotheses</strong></p>
<p>Typically, the hypotheses of the Kruskal-Wallis test are:</p>
<p><span class="math display">\[
H_0: \text{All samples are from the same distribution.}
\]</span> <span class="math display">\[
H_a: \text{At least one sample's distribution is stochastically different.}
\]</span></p>
<p>However, according to the original authors, what the alternative to the Kruskal-Wallis test really is, “is a tendency for observations in at least one of the populations to be larger (or smaller) than all the observations together, when paired randomly. In many cases, this is practically equivalent to the mean of at least one population differing from the others.” Thus, it could also be appropriate to use the ANOVA style hypotheses</p>
<p><span class="math display">\[
H_0: \mu_1 = \mu_2 = \ldots = \mu
\]</span> <span class="math display">\[
H_a: \mu_i \neq \mu \ \text{for at least one} \ i
\]</span></p>
<hr />
</div>
</div>
<div id="r-instructions" class="section level4">
<h4>R Instructions</h4>
<div style="padding-left:125px;">
<p><strong>Console</strong> Help Command: <code>?kruskal.test()</code></p>
<div style="padding-left:15px;">
<p><code>kruskal.test(x ~ g, data=YourDataSet)</code></p>
<ul>
<li><code>x</code> is a numeric vector of data values that represents the quantatitive response variable.</li>
<li><code>g</code> is a qualitative grouping variable defining which groups each value in <code>x</code> belongs to. It must either be a character vector or a factor vector.</li>
<li><code>YourDataSet</code> is the name of your data set.</li>
</ul>
<p><strong>Example Code</strong></p>
<p>Hover your mouse over the example codes to learn more.</p>
<a href="javascript:showhide('kruskal')">
<div class="hoverchunk">
<p><span class="tooltipr"> kruskal.test( <span class="tooltiprtext">The function that performs a Kruskal-Wallis rank sum test.</span> </span><span class="tooltipr"> weight <span class="tooltiprtext">‘weight’ is a numeric variable from the chickwts dataset that represents the quantatitive response variable.</span> </span><span class="tooltipr"> ~ <span class="tooltiprtext">‘~’ is the tilde symbol used to separate the left- and right-hand side in a model formula.</span> </span><span class="tooltipr"> feed, <span class="tooltiprtext"> ‘feed’ is a qualitative grouping variable in the chickwts dataset. </span> </span><span class="tooltipr"> data = chickwts) <span class="tooltiprtext"> ‘chickwts’ is a dataset in R.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code if you have typed it in yourself. You can also click here to view the output.</span> </span><span class="tooltipr" style="float:right;font-size:.8em;"> Click to View Output <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="kruskal" style="display:none;">
<pre><code>##
## Kruskal-Wallis rank sum test
##
## data: weight by feed
## Kruskal-Wallis chi-squared = 37.343, df = 5, p-value = 5.113e-07</code></pre>
</div>
<p><br></p>
<p>Alternatively, you could use the following approach as well.</p>
<p><code>kruskal.test(list(x, y, z))</code></p>
<ul>
<li><code>x</code> is a numeric vector of data values that represents the quantatitive response variable for the first group.</li>
<li><code>y</code> is a numeric vector of data values that represents the quantatitive response variable for the second group.</li>
<li><code>z</code> is a numeric vector of data values that represents the quantatitive response variable for the third group.</li>
<li>Note that more than three vectors of data could be included inside of <code>list()</code>.</li>
</ul>
<p><strong>Example Code</strong></p>
<p>Hover your mouse over the example codes to learn more.</p>
<a href="javascript:showhide('kruskal2')">
<div class="hoverchunk">
<p><span class="tooltipr"> feed1 <- filter(chickwts, feed == “horsebean”) <span class="tooltiprtext"> This splits out the first group of feed (horsebean) from the chickwts dataset. </span> </span><br><span class="tooltipr"> feed2 <- filter(chickwts, feed == “linseed”) <span class="tooltiprtext"> This splits out the second group of feed (linseed) from the chickwts dataset. </span> </span><br><span class="tooltipr"> feed3 <- filter(chickwts, feed == “soybean”) <span class="tooltiprtext"> This splits out the third group of feed (soybean) from the chickwts dataset. </span> </span><br><span class="tooltipr"> feed4 <- filter(chickwts, feed == “sunflower”) <span class="tooltiprtext"> This splits out the fourth group of feed (sunflower) from the chickwts dataset. </span> </span><br><span class="tooltipr"> feed5 <- filter(chickwts, feed == “meatmeal”) <span class="tooltiprtext"> This splits out the fifth group of feed (meatmeal) from the chickwts dataset. </span> </span><br><span class="tooltipr"> feed6 <- filter(chickwts, feed == “casein”) <span class="tooltiprtext"> This splits out the sixth group of feed (casein) from the chickwts dataset. </span> </span><br><span class="tooltipr"> kruskal.test( <span class="tooltiprtext">The function that performs a Kruskal-Wallis rank sum test.</span> </span><span class="tooltipr"> list(feed1$weight,feed2$weight,feed3$weight,feed4$weight,feed5$weight,feed6$weight)) <span class="tooltiprtext">A list of numeric vecotrs that represent the quantitative response variable for each group.</span> </span> </span><span class="tooltipr" style="float:right;font-size:.8em;"> Click to View Output <span class="tooltiprtext">Click to View Output. Load library(tidyverse) to run this code in R.</span> </span></p>
</div>
</a>
<div id="kruskal2" style="display:none;">
<pre><code>##
## Kruskal-Wallis rank sum test
##
## data: list(feed1$weight, feed2$weight, feed3$weight, feed4$weight, feed5$weight, feed6$weight)
## Kruskal-Wallis chi-squared = 37.343, df = 5, p-value = 5.113e-07</code></pre>
</div>
<hr />
</div>
</div>
<div id="explanation" class="section level4">
<h4>Explanation</h4>
<div style="padding-left:125px;">
<p>In many cases it is of interest to perform a hypothesis test about whether or not several samples come from the same population.</p>
<p>The Kruskal-Wallis Rank Sum Test allows for this by extending the idea behind the Wilcoxon Rank Sum Test to allow for more than two samples.</p>
<p>The following explanation of how the test works comes mainly from the original 1952 article, <a href="http://www.jstor.org/stable/2280779?seq=1#page_scan_tab_contents">Use of Ranks in One-Criterion Variance Analysis, 1952</a>, but is expanded here for increased clarity.</p>
<h4 id="calculating-the-test-statistic">Calculating the Test Statistic</h4>
<p>The following artificial data will be used to demonstrate how the Kruskal-Wallis Test statistic is calculated. (Taken from the original article.)</p>
<div style="color:#a8a8a8;">
<center>
<p><strong>Daily Bottle-Cap Production of Three Machines</strong></p>
<p>(Artificial data.)</p>
<table>
<thead>
<tr class="header">
<th>Standard</th>
<th>Modification1</th>
<th>Modification2</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>340</td>
<td>339</td>
<td>347</td>
</tr>
<tr class="even">
<td>345</td>
<td>333</td>
<td>343</td>
</tr>
<tr class="odd">
<td>330</td>
<td>344</td>
<td>349</td>
</tr>
<tr class="even">
<td>342</td>
<td></td>
<td>355</td>
</tr>
<tr class="odd">
<td>338</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</center>
</div>
<p><strong>Step 1</strong>: Obtain <span class="math inline">\(C\)</span> samples, each of size <span class="math inline">\(n_i\)</span>. Note that the notation <span class="math inline">\(n_i\)</span> allows for each sample to be a different size.</p>
<div style="padding-left:30px; color:#a8a8a8;">
<p>In the bottle-cap data, <span class="math inline">\(C=3\)</span> and <span class="math inline">\(n_1 = 5\)</span>, <span class="math inline">\(n_2 = 3\)</span>, and <span class="math inline">\(n_3 = 4\)</span>.</p>
</div>
<p><strong>Step 2</strong>: Order the <span class="math inline">\(N=n_1 + \cdots + n_C\)</span> values from all samples from smallest to largest. Rank the values from smallest to largest with the ranks <span class="math inline">\(1,\ldots,N\)</span>. Award any tied values the average of the ranks of those values that are tied.</p>
<div style="padding-left:30px; color:#a8a8a8;">
<p>In the bottle-cap data we have the following.</p>
<table>
<thead>
<tr class="header">
<th>Rank</th>
<th align="right">1</th>
<th align="right">2</th>
<th align="right">3</th>
<th align="right">4</th>
<th align="right">5</th>
<th align="right">6</th>
<th align="right">7</th>
<th align="right">8</th>
<th align="right">9</th>
<th align="right">10</th>
<th align="right">11</th>
<th align="right">12</th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Value</td>
<td align="right">330</td>
<td align="right">333</td>
<td align="right">338</td>
<td align="right">339</td>
<td align="right">340</td>
<td align="right">342</td>
<td align="right">343</td>
<td align="right">344</td>
<td align="right">345</td>
<td align="right">347</td>
<td align="right">349</td>
<td align="right">355</td>
<td></td>
</tr>
<tr class="even">
<td>Machine</td>
<td align="right">S</td>
<td align="right">M1</td>
<td align="right">S</td>
<td align="right">M1</td>
<td align="right">S</td>
<td align="right">S</td>
<td align="right">M2</td>
<td align="right">M1</td>
<td align="right">S</td>
<td align="right">M2</td>
<td align="right">M2</td>
<td align="right">M2</td>
<td></td>
</tr>
</tbody>
</table>
</div>
<p><strong>Step 3</strong>: Sum the ranks for each sample. Denote the sum of the ranks for sample <span class="math inline">\(i\)</span> by <span class="math inline">\(R_i\)</span>.</p>
<div style="padding-left:30px; color:#a8a8a8;">
<p>In the bottle-cap data,</p>
<p><span class="math inline">\(R_1 = 1 + 3 + 5 + 6 + 9 = 24\)</span></p>
<p><span class="math inline">\(R_2 = 2 + 4 + 8 = 14\)</span></p>
<p><span class="math inline">\(R_3 = 7 + 10 + 11 + 12 = 40\)</span></p>
</div>
<p><strong>Step 4</strong>: Compute the mean rank for each sample, <span class="math inline">\(\bar{R_i} = \frac{R_i}{n_i}\)</span>.</p>
<div style="padding-left:30px; color:#a8a8a8;">
<p>In the bottle-cap data,</p>
<p><span class="math inline">\(\bar{R}_1 = \frac{R_1}{n_1} = \frac{24}{5} = 4.8\)</span></p>
<p><span class="math inline">\(\bar{R}_2 = \frac{R_2}{n_2} = \frac{14}{3} = 4.667\)</span></p>
<p><span class="math inline">\(\bar{R}_3 = \frac{R_3}{n_3} = \frac{40}{4} = 10.0\)</span></p>
</div>
<p><strong>Step 5</strong>: If there are no ties, calculate the test statistic <span class="math inline">\(H\)</span> by the formula <span class="math display">\[
H = \frac{N-1}{N}\sum_{i=1}^C \frac{n_i[\bar{R}_i-\frac{1}{2}(N+1)]^2}{\frac{1}{12}(N^2-1)}
\]</span></p>
<p>See the original article for the formula to use when there are ties present in the data.</p>
<div style="padding-left:30px; color:#a8a8a8;">
<p>In the bottle-cap data, <span class="math inline">\(H = 5.656\)</span>.</p>
</div>
<p>To understand the logic behind the test statistic <span class="math inline">\(H\)</span>, note that the null hypothesis assumes that each of the <span class="math inline">\(C\)</span> samples are taken from the same population. Under this assumption, the ranks assigned to each sample should represent a uniform sample of the ranks <span class="math inline">\(1,\ldots,N\)</span>. If the null hypothesis were true, we would expect the average of the ranks from each group, the <span class="math inline">\(\bar{R}_i\)</span>, to be roughly about the same. More precisely, using the properties of the <em>discrete uniform distribution</em> (<a href="https://en.wikipedia.org/wiki/Uniform_distribution_(discrete)">see wikipedia</a>), we expect each <span class="math inline">\(\bar{R}_i\)</span> to be close to <span class="math inline">\(\frac{1}{2}(N+1)\)</span>, which is the mean of the discrete uniform distribution. That <span class="math inline">\(\bar{R}_i\)</span> should be close to this value comes from the fact that the mean of a distribution of means is equal to the population mean. Further, the variance of <span class="math inline">\(\bar{R}_i\)</span> is given by the population variance, <span class="math inline">\(\frac{1}{12}(N^2-1)\)</span> in this case, divided by the sample size <span class="math inline">\(n_i\)</span>. Finally, the <span class="math inline">\(\frac{N-1}{N}\)</span> is a correction factor that will not be explained here. The full article explains the details about how a multivariate normal distribution is used to uncover the formula for <span class="math inline">\(H\)</span>. Thus, understanding <span class="math inline">\(H\)</span> completely will require an advanced degree in statistical theory. However, the short story is that the distribution of the test statistic <span class="math inline">\(H\)</span> is approximately a chi squared distribution with <span class="math inline">\(C-1\)</span> degrees of freedom and has the form of a sum of values consisting of the (observed mean - expected mean)^2/(variance of the observed mean).</p>
<p><strong>Step 6</strong>: Calculate the p-value of <span class="math inline">\(H\)</span> using a <a href="MakingInference.html#chisquared">chi squared distribution</a> with <span class="math inline">\(C-1\)</span> degrees of freedom. <span class="math display">\[
H = \frac{N-1}{N}\sum_{i=1}^C \frac{n_i[\bar{R}_i-\frac{1}{2}(N+1)]^2}{\frac{1}{12}(N^2-1)}
\]</span></p>
<div style="padding-left:30px; color:#a8a8a8;">
<p>In the bottle-cap data, <span class="math inline">\(p = 0.059\)</span>, which represents the probability of <span class="math inline">\(H\)</span> being as extreme or more extreme than the observed value of 5.656, assuming the null hypothesis is true.</p>
</div>
<hr />
</div>
</div>
</div>
<div id="section" class="section level3">
<h3></h3>
<div style="padding-left:125px;">
<p><strong>Examples:</strong> <a href="./Analyses/Kruskal-Wallis%20Test/Examples/wagesKruskal.html">wages</a>, <a href="./Analyses/Kruskal-Wallis%20Test/Examples/pigweightsKruskal.html">pigweights</a></p>
</div>
<hr />
<footer>
</footer>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open')
});
});
</script>
<!-- code folding -->
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>