Repository navigation
Expand file tree
/
Copy path14_ChiSquare.html
More file actions
2889 lines (2791 loc) · 299 KB
/
Copy path14_ChiSquare.html
File metadata and controls
2889 lines (2791 loc) · 299 KB
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.43">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Topic 14: Inference for One or More Categorical Variables With Many Levels</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="14_ChiSquare_files/libs/clipboard/clipboard.min.js"></script>
<script src="14_ChiSquare_files/libs/quarto-html/quarto.js"></script>
<script src="14_ChiSquare_files/libs/quarto-html/popper.min.js"></script>
<script src="14_ChiSquare_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="14_ChiSquare_files/libs/quarto-html/anchor.min.js"></script>
<link href="14_ChiSquare_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="14_ChiSquare_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="14_ChiSquare_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="14_ChiSquare_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="14_ChiSquare_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script src="14_ChiSquare_files/libs/quarto-contrib/live-runtime/live-runtime.js" type="module"></script>
<link href="14_ChiSquare_files/libs/quarto-contrib/live-runtime/live-runtime.css" rel="stylesheet">
<script type="module" src="14_ChiSquare_files/libs/quarto-ojs/quarto-ojs-runtime.js"></script>
<link href="14_ChiSquare_files/libs/quarto-ojs/quarto-ojs.css" rel="stylesheet">
<style>
.btn-exercise-solution { display: none !important; }
.exercise-editor-body { max-height: 300px; overflow-y: auto; }
</style>
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
<script type="text/javascript">
const typesetMath = (el) => {
if (window.MathJax) {
// MathJax Typeset
window.MathJax.typeset([el]);
} else if (window.katex) {
// KaTeX Render
var mathElements = el.getElementsByClassName("math");
var macros = [];
for (var i = 0; i < mathElements.length; i++) {
var texText = mathElements[i].firstChild;
if (mathElements[i].tagName == "SPAN") {
window.katex.render(texText.data, mathElements[i], {
displayMode: mathElements[i].classList.contains('display'),
throwOnError: false,
macros: macros,
fleqn: false
});
}
}
}
}
window.Quarto = {
typesetMath
};
</script>
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Topic 14: Inference for One or More Categorical Variables With Many Levels</h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<div class="cell" data-edit="false">
<div>
<div id="webr-1" class="exercise-cell">
</div>
<script type="webr-1-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsIm91dHB1dCI6ZmFsc2UsImV2YWwiOnRydWUsImVkaXQiOmZhbHNlfSwiY29kZSI6IndlYnI6Omluc3RhbGwoXCJncmFkZXRoaXNcIiwgcXVpZXQgPSBUUlVFKVxubGlicmFyeShncmFkZXRoaXMpXG5vcHRpb25zKHdlYnIuZXhlcmNpc2UuY2hlY2tlciA9IGZ1bmN0aW9uKFxuICBsYWJlbCwgdXNlcl9jb2RlLCBzb2x1dGlvbl9jb2RlLCBjaGVja19jb2RlLCBlbnZpcl9yZXN1bHQsIGV2YWx1YXRlX3Jlc3VsdCxcbiAgZW52aXJfcHJlcCwgbGFzdF92YWx1ZSwgZW5naW5lLCBzdGFnZSwgLi4uXG4pIHtcbiAgaWYgKGlzLm51bGwoY2hlY2tfY29kZSkpIHtcbiAgICAjIE5vIGdyYWRpbmcgY29kZSwgc28ganVzdCBza2lwIGdyYWRpbmdcbiAgICBpbnZpc2libGUoTlVMTClcbiAgfSBlbHNlIGlmIChpcy5udWxsKGxhYmVsKSkge1xuICAgIGxpc3QoXG4gICAgICBjb3JyZWN0ID0gRkFMU0UsXG4gICAgICB0eXBlID0gXCJ3YXJuaW5nXCIsXG4gICAgICBtZXNzYWdlID0gXCJBbGwgZXhlcmNpc2VzIG11c3QgaGF2ZSBhIGxhYmVsLlwiXG4gICAgKVxuICB9IGVsc2UgaWYgKGlzLm51bGwoc29sdXRpb25fY29kZSkpIHtcbiAgICBsaXN0KFxuICAgICAgY29ycmVjdCA9IEZBTFNFLFxuICAgICAgdHlwZSA9IFwid2FybmluZ1wiLFxuICAgICAgbWVzc2FnZSA9IGh0bWx0b29sczo6dGFncyRkaXYoXG4gICAgICAgIGh0bWx0b29sczo6dGFncyRwKFwiQSBwcm9ibGVtIG9jY3VycmVkIGdyYWRpbmcgdGhpcyBleGVyY2lzZS5cIiksXG4gICAgICAgIGh0bWx0b29sczo6dGFncyRwKFxuICAgICAgICAgIFwiTm8gc29sdXRpb24gY29kZSB3YXMgZm91bmQuIE5vdGUgdGhhdCBncmFkaW5nIGV4ZXJjaXNlcyB1c2luZyB0aGUgXCIsXG4gICAgICAgICAgaHRtbHRvb2xzOjp0YWdzJGNvZGUoXCJncmFkZXRoaXNcIiksXG4gICAgICAgICAgXCJwYWNrYWdlIHJlcXVpcmVzIGEgbW9kZWwgc29sdXRpb24gdG8gYmUgaW5jbHVkZWQgaW4gdGhlIGRvY3VtZW50LlwiXG4gICAgICAgIClcbiAgICAgIClcbiAgICApXG4gIH0gZWxzZSB7XG4gICAgZ3JhZGV0aGlzOjpncmFkZXRoaXNfZXhlcmNpc2VfY2hlY2tlcihcbiAgICAgIGxhYmVsID0gbGFiZWwsIHNvbHV0aW9uX2NvZGUgPSBzb2x1dGlvbl9jb2RlLCB1c2VyX2NvZGUgPSB1c2VyX2NvZGUsXG4gICAgICBjaGVja19jb2RlID0gY2hlY2tfY29kZSwgZW52aXJfcmVzdWx0ID0gZW52aXJfcmVzdWx0LFxuICAgICAgZXZhbHVhdGVfcmVzdWx0ID0gZXZhbHVhdGVfcmVzdWx0LCBlbnZpcl9wcmVwID0gZW52aXJfcHJlcCxcbiAgICAgIGxhc3RfdmFsdWUgPSBsYXN0X3ZhbHVlLCBzdGFnZSA9IHN0YWdlLCBlbmdpbmUgPSBlbmdpbmUpXG4gIH1cbn0pIn0=
</script>
</div>
</div>
<div class="cell" data-edit="false" data-define="ok_response">
<div>
<div id="webr-2" class="exercise-cell">
</div>
<script type="webr-2-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImVkaXQiOmZhbHNlLCJvdXRwdXQiOmZhbHNlLCJkZWZpbmUiOlsib2tfcmVzcG9uc2UiXX0sImNvZGUiOiJcbmxpYnJhcnkoaHRtbHRvb2xzKVxub2tfcmVzcG9uc2UgPC0gZnVuY3Rpb24ocmVzcG9uc2UsIG4pIHtcbiAgaWYgKGlzLm5hKHJlc3BvbnNlKSkgZGl2KEhUTUwoXCJZb3UgaGF2ZW4ndCBhbnN3ZXJlZCB5ZXQuXCIpLCBzdHlsZSA9IFwiY29sb3I6IHB1cnBsZVwiKVxuICBlbHNlIGlmIChyZXNwb25zZSA9PSBuKSBkaXYoSFRNTChcIkNvcnJlY3Qg4pyTXCIpLCBzdHlsZSA9IFwiY29sb3I6IGdyZWVuXCIpXG4gIGVsc2UgZGl2KEhUTUwoXCJJbmNvcnJlY3Qg4pyXXCIpLCBzdHlsZSA9IFwiY29sb3I6IHJlZFwiKVxufSJ9
</script>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code hidden" id="cb1" data-startfrom="42" data-source-offset="0"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 41;"><span id="cb1-42"><a href="#cb1-42" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">ok_checkbox</span>(response<span class="op">,</span> n) {</span>
<span id="cb1-43"><a href="#cb1-43" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (<span class="op">!</span>response <span class="op">||</span> response<span class="op">.</span><span class="at">length</span> <span class="op">===</span> <span class="dv">0</span>) </span>
<span id="cb1-44"><a href="#cb1-44" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="fu">html</span><span class="vs">`<span style="color:purple">You haven't answered yet.</span>`</span><span class="op">;</span></span>
<span id="cb1-45"><a href="#cb1-45" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (response<span class="op">.</span><span class="fu">toString</span>() <span class="op">===</span> n) </span>
<span id="cb1-46"><a href="#cb1-46" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="fu">html</span><span class="vs">`<span style="color:green">Correct ✓</span>`</span><span class="op">;</span></span>
<span id="cb1-47"><a href="#cb1-47" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="fu">html</span><span class="vs">`<span style="color:red">Not Yet! ✗</span>`</span><span class="op">;</span></span>
<span id="cb1-48"><a href="#cb1-48" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">
</div>
</div>
</div>
<div class="cell" data-context="setup">
<div>
<div id="webr-3" class="exercise-cell">
</div>
<script type="webr-3-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImNvbnRleHQiOiJzZXR1cCIsIm91dHB1dCI6ZmFsc2UsImVkaXQiOmZhbHNlLCJlY2hvIjpmYWxzZX0sImNvZGUiOiJcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KGdncGxvdDIpXG5saWJyYXJ5KGpzb25saXRlKVxubGlicmFyeShiYXNlNjRlbmMpXG5cbnRoZW1lX3NldCh0aGVtZV9idyhiYXNlX3NpemUgPSAxMikpXG5cbnNldC5zZWVkKDI0MSlcblxuaW5jb21lTGV2ZWwgPC0gc2FtcGxlKFxuICBjKFwiUG92ZXJ0eVwiLCBcIkxvd0luY29tZVwiLCBcIk1pZGRsZUluY29tZVwiLCBcIkhpZ2hJbmNvbWVcIiksXG4gIHNpemUgPSAyNTAwLCByZXBsYWNlID0gVFJVRSxcbiAgcHJvYiA9IGMoMC4xNiwgMC4zOCwgMC4zNSwgMC4xMSlcbilcblxuQlJGU1NzaW0gPC0gZGF0YS5mcmFtZShcbiAgSW5jb21lTGV2ZWwgPSBpbmNvbWVMZXZlbCxcbiAgRHJ1Z1VzZSA9IHJlcChOQSwgbGVuZ3RoKGluY29tZUxldmVsKSlcbilcblxuQlJGU1NzaW0kRHJ1Z1VzZVtCUkZTU3NpbSRJbmNvbWVMZXZlbCA9PSBcIlBvdmVydHlcIl0gPC0gc2FtcGxlKFxuICBjKFwibm9cIiwgXCJ5ZXNcIiksXG4gIHNpemUgPSBzdW0oaW5jb21lTGV2ZWwgPT0gXCJQb3ZlcnR5XCIpLFxuICByZXBsYWNlID0gVFJVRSwgcHJvYiA9IGMoMC44LCAwLjIpXG4pXG5CUkZTU3NpbSREcnVnVXNlW0JSRlNTc2ltJEluY29tZUxldmVsID09IFwiTG93SW5jb21lXCJdIDwtIHNhbXBsZShcbiAgYyhcIm5vXCIsIFwieWVzXCIpLFxuICBzaXplID0gc3VtKGluY29tZUxldmVsID09IFwiTG93SW5jb21lXCIpLFxuICByZXBsYWNlID0gVFJVRSwgcHJvYiA9IGMoMC44NCwgMC4xNilcbilcbkJSRlNTc2ltJERydWdVc2VbQlJGU1NzaW0kSW5jb21lTGV2ZWwgPT0gXCJNaWRkbGVJbmNvbWVcIl0gPC0gc2FtcGxlKFxuICBjKFwibm9cIiwgXCJ5ZXNcIiksXG4gIHNpemUgPSBzdW0oaW5jb21lTGV2ZWwgPT0gXCJNaWRkbGVJbmNvbWVcIiksXG4gIHJlcGxhY2UgPSBUUlVFLCBwcm9iID0gYygwLjg4LCAwLjEyKVxuKVxuQlJGU1NzaW0kRHJ1Z1VzZVtCUkZTU3NpbSRJbmNvbWVMZXZlbCA9PSBcIkhpZ2hJbmNvbWVcIl0gPC0gc2FtcGxlKFxuICBjKFwibm9cIiwgXCJ5ZXNcIiksXG4gIHNpemUgPSBzdW0oaW5jb21lTGV2ZWwgPT0gXCJIaWdoSW5jb21lXCIpLFxuICByZXBsYWNlID0gVFJVRSwgcHJvYiA9IGMoMC44MiwgMC4xOClcbilcblxudGFibGVTaW0gPC0gdGFibGUoQlJGU1NzaW0kRHJ1Z1VzZSwgQlJGU1NzaW0kSW5jb21lTGV2ZWwpXG5vYnNlcnZlZEluZCA8LSBjKDM0MSwgNzUyLCA3OTYsIDIyMSwgNzgsIDE1MywgMTE2LCA0MylcblxuZXhlcmNpc2VfcmVzdWx0cyA8LSBsaXN0KFxuICBub3RlYm9vayAgICAgICAgICA9IFwiVG9waWMgMTQ6IEluZmVyZW5jZSBmb3IgT25lIG9yIE1vcmUgQ2F0ZWdvcmljYWwgVmFyaWFibGVzIFdpdGggTWFueSBMZXZlbHNcIixcbiAgZXhwX3doaXRlICAgICAgICAgPSBcInVuYXR0ZW1wdGVkXCIsXG4gIGV4cF9ibGFjayAgICAgICAgID0gXCJ1bmF0dGVtcHRlZFwiLFxuICBleHBfaGlzcGFuaWMgICAgICA9IFwidW5hdHRlbXB0ZWRcIixcbiAgZXhwX290aGVyICAgICAgICAgPSBcInVuYXR0ZW1wdGVkXCIsXG4gIHRlc3Rfc3RhdCAgICAgICAgID0gXCJ1bmF0dGVtcHRlZFwiLFxuICBkZiAgICAgICAgICAgICAgICA9IFwidW5hdHRlbXB0ZWRcIixcbiAgY29tcHV0ZV9wICAgICAgICAgPSBcInVuYXR0ZW1wdGVkXCIsXG4gIHBvdmVydHlfZHJ1Z191c2UgID0gXCJ1bmF0dGVtcHRlZFwiLFxuICBsb3dJbmNfZHJ1Z191c2UgICA9IFwidW5hdHRlbXB0ZWRcIixcbiAgbWlkZGxlSW5jX2RydWdfdXNlID0gXCJ1bmF0dGVtcHRlZFwiLFxuICBoaWdoSW5jX2RydWdfdXNlICA9IFwidW5hdHRlbXB0ZWRcIixcbiAgY2hpX3NxX2luZCAgICAgICAgPSBcInVuYXR0ZW1wdGVkXCIsXG4gIGRmX2luZCAgICAgICAgICAgID0gXCJ1bmF0dGVtcHRlZFwiLFxuICBjb21wdXRlX3BfaW5kZXAgICA9IFwidW5hdHRlbXB0ZWRcIlxuKSJ9
</script>
</div>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
About
</div>
</div>
<div class="callout-body-container callout-body">
<p>This activity introduces <span class="math inline">\(\chi^2\)</span> (Chi-Squared) tests for Goodness of Fit and Independence — two methods for testing claims involving categorical data with more than two levels. Data used in this activity is simulated, based on the US Census Bureau, The Sentencing Project, and the 2019 Behavioral Risk Factor Surveillance System.</p>
<div class="cell">
<div class="sourceCode cell-code hidden" id="cb2" data-startfrom="170" data-source-offset="0"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 169;"><span id="cb2-170"><a href="#cb2-170" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb2-171"><a href="#cb2-171" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> btn <span class="op">=</span> <span class="fu">html</span><span class="vs">`<button style="</span></span>
<span id="cb2-172"><a href="#cb2-172" aria-hidden="true" tabindex="-1"></a><span class="vs"> background: #436b95;</span></span>
<span id="cb2-173"><a href="#cb2-173" aria-hidden="true" tabindex="-1"></a><span class="vs"> color: white;</span></span>
<span id="cb2-174"><a href="#cb2-174" aria-hidden="true" tabindex="-1"></a><span class="vs"> border: none;</span></span>
<span id="cb2-175"><a href="#cb2-175" aria-hidden="true" tabindex="-1"></a><span class="vs"> padding: 8px 16px;</span></span>
<span id="cb2-176"><a href="#cb2-176" aria-hidden="true" tabindex="-1"></a><span class="vs"> border-radius: 4px;</span></span>
<span id="cb2-177"><a href="#cb2-177" aria-hidden="true" tabindex="-1"></a><span class="vs"> cursor: pointer;</span></span>
<span id="cb2-178"><a href="#cb2-178" aria-hidden="true" tabindex="-1"></a><span class="vs"> font-size: 0.9em;</span></span>
<span id="cb2-179"><a href="#cb2-179" aria-hidden="true" tabindex="-1"></a><span class="vs"> ">🔄 Reset My Responses</button>`</span><span class="op">;</span></span>
<span id="cb2-180"><a href="#cb2-180" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-181"><a href="#cb2-181" aria-hidden="true" tabindex="-1"></a> btn<span class="op">.</span><span class="at">onclick</span> <span class="op">=</span> () <span class="kw">=></span> {</span>
<span id="cb2-182"><a href="#cb2-182" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (<span class="fu">confirm</span>(<span class="st">'Reset all responses for this activity? This cannot be undone.'</span>)) {</span>
<span id="cb2-183"><a href="#cb2-183" aria-hidden="true" tabindex="-1"></a> <span class="bu">Object</span><span class="op">.</span><span class="fu">keys</span>(localStorage)</span>
<span id="cb2-184"><a href="#cb2-184" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">filter</span>(k <span class="kw">=></span> k<span class="op">.</span><span class="fu">endsWith</span>(<span class="st">'_selected_t14'</span>) <span class="op">||</span> k<span class="op">.</span><span class="fu">endsWith</span>(<span class="st">'_correct_t14'</span>) <span class="op">||</span> k<span class="op">.</span><span class="fu">endsWith</span>(<span class="st">'_result_t14'</span>))</span>
<span id="cb2-185"><a href="#cb2-185" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">forEach</span>(k <span class="kw">=></span> localStorage<span class="op">.</span><span class="fu">removeItem</span>(k))<span class="op">;</span></span>
<span id="cb2-186"><a href="#cb2-186" aria-hidden="true" tabindex="-1"></a> location<span class="op">.</span><span class="fu">reload</span>()<span class="op">;</span></span>
<span id="cb2-187"><a href="#cb2-187" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb2-188"><a href="#cb2-188" aria-hidden="true" tabindex="-1"></a> }<span class="op">;</span></span>
<span id="cb2-189"><a href="#cb2-189" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-190"><a href="#cb2-190" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> btn<span class="op">;</span></span>
<span id="cb2-191"><a href="#cb2-191" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="expression">
</div>
</div>
</div>
<p><em>Note.</em> The button above resets multiple choice and checkbox questions. Currently, resetting code cells must be done manually via hitting the <em>Start Over</em> button on each individual interactive cell.</p>
</div>
</div>
<section id="chi-squared-tests-for-goodness-of-fit-and-independence" class="level2">
<h2 class="anchored" data-anchor-id="chi-squared-tests-for-goodness-of-fit-and-independence">Chi-Squared Tests for Goodness of Fit and Independence</h2>
<p>In this activity, we consider two methods for testing claims corresponding to categorical data with possibly more than two levels. The first is called the <span class="math inline">\(\chi^2\)</span> <strong>Goodness of Fit Test</strong>, used to test whether a sample provides evidence that an assumed discrete distribution is not an appropriate model for a categorical variable. The second is called the <span class="math inline">\(\chi^2\)</span> <strong>Test of Independence</strong>, used to test whether two categorical variables are associated with one another. You’ll be exposed to video explanations and worked examples before trying problems on your own.</p>
</section>
<section id="chi-squared-goodness-of-fit" class="level2">
<h2 class="anchored" data-anchor-id="chi-squared-goodness-of-fit">Chi-Squared Goodness of Fit</h2>
<p>Consider a sociologist interested in better understanding incarceration rates in the state of New Hampshire. The researcher wants to determine whether minority populations are disproportionately represented in State Penitentiaries. Using estimates from the <a href="https://www.census.gov/quickfacts/NH" target="_blank">United States Census Bureau</a>, the population of New Hampshire had the following racial breakdown as of 2019: white (89.8%), Black (1.8%), Hispanic (4.0%), other (4.4%). A reasonable expectation is that the incarcerated population in state prisons should roughly reflect this same distribution.</p>
<p>The researcher took a random sample of 300 inmates in State Penitentiaries across New Hampshire and observed the following results: 243 inmates were white, 24 were Black, 15 were Hispanic, and 18 were of another race. The researcher wants to determine whether this sample provides evidence that the state prison population does <em>not</em> reflect the racial demographics of the State.</p>
<p>We’ll come back to this example shortly, but first let’s watch Dr. Çetinkaya-Rundel introduce the <span class="math inline">\(\chi^2\)</span> Goodness of Fit Test.</p>
<center>
<iframe width="560" height="315" src="https://www.youtube.com/embed/Uk36WGxujkc" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
</center>
<p>Dr. Çetinkaya-Rundel discussed an example of racial bias in jury selection. Before applying these techniques to our New Hampshire example, let’s recap a few key ideas.</p>
<p>The <span class="math inline">\(\chi^2\)</span> test statistic does not follow a normal distribution — instead, it follows a <span class="math inline">\(\chi^2\)</span>-distribution. Although this is a new distribution, the principles remain familiar. The test statistic measures how far our sample falls from what was expected under the null hypothesis, and the <span class="math inline">\(p\)</span>-value is the corresponding tail probability. Since the <span class="math inline">\(\chi^2\)</span> test statistic is always non-negative, we are always interested in the <em>upper</em> tail.</p>
<p>Running a <span class="math inline">\(\chi^2\)</span> Goodness of Fit test requires the following conditions:</p>
<ul>
<li>The sample must be taken randomly.</li>
<li>If sampling without replacement, the sample should include less than 10% of the entire population.</li>
<li>The sample must be large enough that each group has an expected count of at least 5 observations.</li>
</ul>
<p>Now, back to our application. As a reminder, New Hampshire is estimated to be 89.8% white, 1.8% Black, 4.0% Hispanic, and 4.4% of other races. We have a sample of 300 inmates: 243 white, 24 Black, 15 Hispanic, and 18 of another race. We want to know whether this sample provides evidence that the prison population does not reflect the State’s racial demographics.</p>
<div class="callout callout-style-default callout-caution callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Check Your Understanding: Goodness of Fit I
</div>
</div>
<div class="callout-body-container callout-body">
<p>What is the variable of interest in this study?</p>
<div class="cell">
<div class="sourceCode cell-code hidden" id="cb3" data-startfrom="239" data-source-offset="-1"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 238;"><span id="cb3-239"><a href="#cb3-239" aria-hidden="true" tabindex="-1"></a>mutable ok_response <span class="op">=</span> (response<span class="op">,</span> n) <span class="kw">=></span> { <span class="cf">return</span> <span class="fu">html</span><span class="vs">`Loading...`</span> }<span class="op">;</span></span>
<span id="cb3-240"><a href="#cb3-240" aria-hidden="true" tabindex="-1"></a>viewof q1 <span class="op">=</span> Inputs<span class="op">.</span><span class="fu">radio</span>(</span>
<span id="cb3-241"><a href="#cb3-241" aria-hidden="true" tabindex="-1"></a> <span class="kw">new</span> <span class="bu">Map</span>([</span>
<span id="cb3-242"><a href="#cb3-242" aria-hidden="true" tabindex="-1"></a> [<span class="st">"The racial demographics of the state prison population in New Hampshire."</span><span class="op">,</span> <span class="dv">1</span>]<span class="op">,</span></span>
<span id="cb3-243"><a href="#cb3-243" aria-hidden="true" tabindex="-1"></a> [<span class="st">"The racial demographics of the population of the state of New Hampshire."</span><span class="op">,</span> <span class="dv">2</span>]<span class="op">,</span></span>
<span id="cb3-244"><a href="#cb3-244" aria-hidden="true" tabindex="-1"></a> [<span class="st">"The number of people belonging to each race within the state prison population in New Hampshire."</span><span class="op">,</span> <span class="dv">3</span>]<span class="op">,</span></span>
<span id="cb3-245"><a href="#cb3-245" aria-hidden="true" tabindex="-1"></a> [<span class="st">"The average length of prison sentences in New Hampshire."</span><span class="op">,</span> <span class="dv">4</span>]</span>
<span id="cb3-246"><a href="#cb3-246" aria-hidden="true" tabindex="-1"></a> ])<span class="op">,</span></span>
<span id="cb3-247"><a href="#cb3-247" aria-hidden="true" tabindex="-1"></a> {<span class="dt">value</span><span class="op">:</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">parse</span>(localStorage<span class="op">.</span><span class="fu">getItem</span>(<span class="st">"q1_selected_t14"</span>) <span class="op">??</span> <span class="st">"null"</span>)}</span>
<span id="cb3-248"><a href="#cb3-248" aria-hidden="true" tabindex="-1"></a>)<span class="op">;</span></span>
<span id="cb3-249"><a href="#cb3-249" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-250"><a href="#cb3-250" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb3-251"><a href="#cb3-251" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q1_selected_t14"</span><span class="op">,</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">stringify</span>(q1))<span class="op">;</span></span>
<span id="cb3-252"><a href="#cb3-252" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q1_correct_t14"</span><span class="op">,</span> <span class="st">"1"</span>)<span class="op">;</span></span>
<span id="cb3-253"><a href="#cb3-253" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q1_result_t14"</span><span class="op">,</span> q1 <span class="op">===</span> <span class="kw">null</span> <span class="op">?</span> <span class="st">"unattempted"</span> <span class="op">:</span> (q1 <span class="op">==</span> <span class="dv">1</span> <span class="op">?</span> <span class="st">"correct"</span> <span class="op">:</span> <span class="st">"incorrect"</span>))<span class="op">;</span></span>
<span id="cb3-254"><a href="#cb3-254" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-1" data-nodetype="declaration">
</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-2" data-nodetype="declaration">
</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-3" data-nodetype="expression">
</div>
</div>
</div>
<div class="sourceCode cell-code hidden" id="cb4" data-startfrom="255" data-source-offset="-759"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 254;"><span id="cb4-255"><a href="#cb4-255" aria-hidden="true" tabindex="-1"></a><span class="fu">ok_response</span>(q1<span class="op">,</span> <span class="st">"1"</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-4" data-nodetype="expression">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="callout callout-style-default callout-caution callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Check Your Understanding: Goodness of Fit II
</div>
</div>
<div class="callout-body-container callout-body">
<p>The variable of interest in this study is:</p>
<div class="cell">
<div class="sourceCode cell-code hidden" id="cb5" data-startfrom="268" data-source-offset="-1"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 267;"><span id="cb5-268"><a href="#cb5-268" aria-hidden="true" tabindex="-1"></a>viewof q2 <span class="op">=</span> Inputs<span class="op">.</span><span class="fu">radio</span>(</span>
<span id="cb5-269"><a href="#cb5-269" aria-hidden="true" tabindex="-1"></a> <span class="kw">new</span> <span class="bu">Map</span>([</span>
<span id="cb5-270"><a href="#cb5-270" aria-hidden="true" tabindex="-1"></a> [<span class="st">"numerical."</span><span class="op">,</span> <span class="dv">1</span>]<span class="op">,</span></span>
<span id="cb5-271"><a href="#cb5-271" aria-hidden="true" tabindex="-1"></a> [<span class="st">"categorical."</span><span class="op">,</span> <span class="dv">2</span>]<span class="op">,</span></span>
<span id="cb5-272"><a href="#cb5-272" aria-hidden="true" tabindex="-1"></a> [<span class="st">"both numerical and categorical."</span><span class="op">,</span> <span class="dv">3</span>]</span>
<span id="cb5-273"><a href="#cb5-273" aria-hidden="true" tabindex="-1"></a> ])<span class="op">,</span></span>
<span id="cb5-274"><a href="#cb5-274" aria-hidden="true" tabindex="-1"></a> {<span class="dt">value</span><span class="op">:</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">parse</span>(localStorage<span class="op">.</span><span class="fu">getItem</span>(<span class="st">"q2_selected_t14"</span>) <span class="op">??</span> <span class="st">"null"</span>)}</span>
<span id="cb5-275"><a href="#cb5-275" aria-hidden="true" tabindex="-1"></a>)<span class="op">;</span></span>
<span id="cb5-276"><a href="#cb5-276" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-277"><a href="#cb5-277" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb5-278"><a href="#cb5-278" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q2_selected_t14"</span><span class="op">,</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">stringify</span>(q2))<span class="op">;</span></span>
<span id="cb5-279"><a href="#cb5-279" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q2_correct_t14"</span><span class="op">,</span> <span class="st">"2"</span>)<span class="op">;</span></span>
<span id="cb5-280"><a href="#cb5-280" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q2_result_t14"</span><span class="op">,</span> q2 <span class="op">===</span> <span class="kw">null</span> <span class="op">?</span> <span class="st">"unattempted"</span> <span class="op">:</span> (q2 <span class="op">==</span> <span class="dv">2</span> <span class="op">?</span> <span class="st">"correct"</span> <span class="op">:</span> <span class="st">"incorrect"</span>))<span class="op">;</span></span>
<span id="cb5-281"><a href="#cb5-281" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-1" data-nodetype="declaration">
</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-2" data-nodetype="expression">
</div>
</div>
</div>
<div class="sourceCode cell-code hidden" id="cb6" data-startfrom="282" data-source-offset="-435"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 281;"><span id="cb6-282"><a href="#cb6-282" aria-hidden="true" tabindex="-1"></a><span class="fu">ok_response</span>(q2<span class="op">,</span> <span class="st">"2"</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-3" data-nodetype="expression">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="callout callout-style-default callout-caution callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Check Your Understanding: Goodness of Fit III
</div>
</div>
<div class="callout-body-container callout-body">
<p>How many measured levels of the variable of interest are there?</p>
<div class="cell">
<div class="sourceCode cell-code hidden" id="cb7" data-startfrom="295" data-source-offset="-1"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 294;"><span id="cb7-295"><a href="#cb7-295" aria-hidden="true" tabindex="-1"></a>viewof q3 <span class="op">=</span> Inputs<span class="op">.</span><span class="fu">radio</span>(</span>
<span id="cb7-296"><a href="#cb7-296" aria-hidden="true" tabindex="-1"></a> <span class="kw">new</span> <span class="bu">Map</span>([</span>
<span id="cb7-297"><a href="#cb7-297" aria-hidden="true" tabindex="-1"></a> [<span class="st">"1"</span><span class="op">,</span> <span class="dv">1</span>]<span class="op">,</span></span>
<span id="cb7-298"><a href="#cb7-298" aria-hidden="true" tabindex="-1"></a> [<span class="st">"2"</span><span class="op">,</span> <span class="dv">2</span>]<span class="op">,</span></span>
<span id="cb7-299"><a href="#cb7-299" aria-hidden="true" tabindex="-1"></a> [<span class="st">"3"</span><span class="op">,</span> <span class="dv">3</span>]<span class="op">,</span></span>
<span id="cb7-300"><a href="#cb7-300" aria-hidden="true" tabindex="-1"></a> [<span class="st">"4"</span><span class="op">,</span> <span class="dv">4</span>]<span class="op">,</span></span>
<span id="cb7-301"><a href="#cb7-301" aria-hidden="true" tabindex="-1"></a> [<span class="st">"5"</span><span class="op">,</span> <span class="dv">5</span>]</span>
<span id="cb7-302"><a href="#cb7-302" aria-hidden="true" tabindex="-1"></a> ])<span class="op">,</span></span>
<span id="cb7-303"><a href="#cb7-303" aria-hidden="true" tabindex="-1"></a> {<span class="dt">value</span><span class="op">:</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">parse</span>(localStorage<span class="op">.</span><span class="fu">getItem</span>(<span class="st">"q3_selected_t14"</span>) <span class="op">??</span> <span class="st">"null"</span>)}</span>
<span id="cb7-304"><a href="#cb7-304" aria-hidden="true" tabindex="-1"></a>)<span class="op">;</span></span>
<span id="cb7-305"><a href="#cb7-305" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-306"><a href="#cb7-306" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb7-307"><a href="#cb7-307" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q3_selected_t14"</span><span class="op">,</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">stringify</span>(q3))<span class="op">;</span></span>
<span id="cb7-308"><a href="#cb7-308" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q3_correct_t14"</span><span class="op">,</span> <span class="st">"4"</span>)<span class="op">;</span></span>
<span id="cb7-309"><a href="#cb7-309" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q3_result_t14"</span><span class="op">,</span> q3 <span class="op">===</span> <span class="kw">null</span> <span class="op">?</span> <span class="st">"unattempted"</span> <span class="op">:</span> (q3 <span class="op">==</span> <span class="dv">4</span> <span class="op">?</span> <span class="st">"correct"</span> <span class="op">:</span> <span class="st">"incorrect"</span>))<span class="op">;</span></span>
<span id="cb7-310"><a href="#cb7-310" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-1" data-nodetype="declaration">
</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-2" data-nodetype="expression">
</div>
</div>
</div>
<div class="sourceCode cell-code hidden" id="cb8" data-startfrom="311" data-source-offset="-413"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 310;"><span id="cb8-311"><a href="#cb8-311" aria-hidden="true" tabindex="-1"></a><span class="fu">ok_response</span>(q3<span class="op">,</span> <span class="st">"4"</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-3" data-nodetype="expression">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="callout callout-style-default callout-caution callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Check Your Understanding: Goodness of Fit IV
</div>
</div>
<div class="callout-body-container callout-body">
<p>In order to answer the question as posed, we should:</p>
<div class="cell">
<div class="sourceCode cell-code hidden" id="cb9" data-startfrom="324" data-source-offset="-1"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 323;"><span id="cb9-324"><a href="#cb9-324" aria-hidden="true" tabindex="-1"></a>viewof q4 <span class="op">=</span> Inputs<span class="op">.</span><span class="fu">radio</span>(</span>
<span id="cb9-325"><a href="#cb9-325" aria-hidden="true" tabindex="-1"></a> <span class="kw">new</span> <span class="bu">Map</span>([</span>
<span id="cb9-326"><a href="#cb9-326" aria-hidden="true" tabindex="-1"></a> [<span class="st">"Construct a confidence interval."</span><span class="op">,</span> <span class="dv">1</span>]<span class="op">,</span></span>
<span id="cb9-327"><a href="#cb9-327" aria-hidden="true" tabindex="-1"></a> [<span class="st">"Conduct a hypothesis test."</span><span class="op">,</span> <span class="dv">2</span>]<span class="op">,</span></span>
<span id="cb9-328"><a href="#cb9-328" aria-hidden="true" tabindex="-1"></a> [<span class="st">"Compute a required sample size."</span><span class="op">,</span> <span class="dv">3</span>]<span class="op">,</span></span>
<span id="cb9-329"><a href="#cb9-329" aria-hidden="true" tabindex="-1"></a> [<span class="st">"Find a probability."</span><span class="op">,</span> <span class="dv">4</span>]</span>
<span id="cb9-330"><a href="#cb9-330" aria-hidden="true" tabindex="-1"></a> ])<span class="op">,</span></span>
<span id="cb9-331"><a href="#cb9-331" aria-hidden="true" tabindex="-1"></a> {<span class="dt">value</span><span class="op">:</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">parse</span>(localStorage<span class="op">.</span><span class="fu">getItem</span>(<span class="st">"q4_selected_t14"</span>) <span class="op">??</span> <span class="st">"null"</span>)}</span>
<span id="cb9-332"><a href="#cb9-332" aria-hidden="true" tabindex="-1"></a>)<span class="op">;</span></span>
<span id="cb9-333"><a href="#cb9-333" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-334"><a href="#cb9-334" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb9-335"><a href="#cb9-335" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q4_selected_t14"</span><span class="op">,</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">stringify</span>(q4))<span class="op">;</span></span>
<span id="cb9-336"><a href="#cb9-336" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q4_correct_t14"</span><span class="op">,</span> <span class="st">"2"</span>)<span class="op">;</span></span>
<span id="cb9-337"><a href="#cb9-337" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q4_result_t14"</span><span class="op">,</span> q4 <span class="op">===</span> <span class="kw">null</span> <span class="op">?</span> <span class="st">"unattempted"</span> <span class="op">:</span> (q4 <span class="op">==</span> <span class="dv">2</span> <span class="op">?</span> <span class="st">"correct"</span> <span class="op">:</span> <span class="st">"incorrect"</span>))<span class="op">;</span></span>
<span id="cb9-338"><a href="#cb9-338" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-1" data-nodetype="declaration">
</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-2" data-nodetype="expression">
</div>
</div>
</div>
<div class="sourceCode cell-code hidden" id="cb10" data-startfrom="339" data-source-offset="-503"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 338;"><span id="cb10-339"><a href="#cb10-339" aria-hidden="true" tabindex="-1"></a><span class="fu">ok_response</span>(q4<span class="op">,</span> <span class="st">"2"</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-3" data-nodetype="expression">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="callout callout-style-default callout-caution callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Check Your Understanding: Goodness of Fit V
</div>
</div>
<div class="callout-body-container callout-body">
<p>Which of the following are the correct hypotheses associated with this test? Select all that apply.</p>
<div class="cell">
<div class="sourceCode cell-code hidden" id="cb11" data-startfrom="352" data-source-offset="-1"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 351;"><span id="cb11-352"><a href="#cb11-352" aria-hidden="true" tabindex="-1"></a>viewof q5 <span class="op">=</span> Inputs<span class="op">.</span><span class="fu">checkbox</span>(</span>
<span id="cb11-353"><a href="#cb11-353" aria-hidden="true" tabindex="-1"></a> <span class="kw">new</span> <span class="bu">Map</span>([</span>
<span id="cb11-354"><a href="#cb11-354" aria-hidden="true" tabindex="-1"></a> [<span class="st">"H₀: p_white = p_Black; Hₐ: The distribution is different."</span><span class="op">,</span> <span class="dv">1</span>]<span class="op">,</span></span>
<span id="cb11-355"><a href="#cb11-355" aria-hidden="true" tabindex="-1"></a> [<span class="st">"H₀: p_white = 0.898, p_Black = 0.018, p_Hispanic = 0.040, p_other = 0.044; Hₐ: The distribution is different."</span><span class="op">,</span> <span class="dv">2</span>]<span class="op">,</span></span>
<span id="cb11-356"><a href="#cb11-356" aria-hidden="true" tabindex="-1"></a> [<span class="st">"H₀: p_white = p_Black = p_Hispanic = p_other = 0.25; Hₐ: The distribution is different."</span><span class="op">,</span> <span class="dv">3</span>]<span class="op">,</span></span>
<span id="cb11-357"><a href="#cb11-357" aria-hidden="true" tabindex="-1"></a> [<span class="st">"H₀: The distribution is uniform; Hₐ: The distribution is different."</span><span class="op">,</span> <span class="dv">4</span>]<span class="op">,</span></span>
<span id="cb11-358"><a href="#cb11-358" aria-hidden="true" tabindex="-1"></a> [<span class="st">"H₀: The racial demographics of the NH state prison population match those of the State; Hₐ: The distribution is different."</span><span class="op">,</span> <span class="dv">5</span>]</span>
<span id="cb11-359"><a href="#cb11-359" aria-hidden="true" tabindex="-1"></a> ])<span class="op">,</span></span>
<span id="cb11-360"><a href="#cb11-360" aria-hidden="true" tabindex="-1"></a> {<span class="dt">value</span><span class="op">:</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">parse</span>(localStorage<span class="op">.</span><span class="fu">getItem</span>(<span class="st">"q5_selected_t14"</span>) <span class="op">??</span> <span class="st">"[]"</span>) <span class="op">??</span> []}</span>
<span id="cb11-361"><a href="#cb11-361" aria-hidden="true" tabindex="-1"></a>)<span class="op">;</span></span>
<span id="cb11-362"><a href="#cb11-362" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-363"><a href="#cb11-363" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb11-364"><a href="#cb11-364" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q5_selected_t14"</span><span class="op">,</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">stringify</span>(q5))<span class="op">;</span></span>
<span id="cb11-365"><a href="#cb11-365" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q5_correct_t14"</span><span class="op">,</span> <span class="st">"2,5"</span>)<span class="op">;</span></span>
<span id="cb11-366"><a href="#cb11-366" aria-hidden="true" tabindex="-1"></a> localStorage<span class="op">.</span><span class="fu">setItem</span>(<span class="st">"q5_result_t14"</span><span class="op">,</span> (<span class="op">!</span>q5 <span class="op">||</span> q5<span class="op">.</span><span class="at">length</span> <span class="op">===</span> <span class="dv">0</span>) <span class="op">?</span> <span class="st">"unattempted"</span> <span class="op">:</span> (q5<span class="op">.</span><span class="fu">toString</span>() <span class="op">===</span> <span class="st">"2,5"</span> <span class="op">?</span> <span class="st">"correct"</span> <span class="op">:</span> <span class="st">"incorrect"</span>))<span class="op">;</span></span>
<span id="cb11-367"><a href="#cb11-367" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-7-1" data-nodetype="declaration">
</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-7-2" data-nodetype="expression">
</div>
</div>
</div>
<div class="sourceCode cell-code hidden" id="cb12" data-startfrom="368" data-source-offset="-888"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 367;"><span id="cb12-368"><a href="#cb12-368" aria-hidden="true" tabindex="-1"></a><span class="fu">ok_checkbox</span>(q5<span class="op">.</span><span class="fu">toString</span>()<span class="op">,</span> <span class="st">"2,5"</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-7-3" data-nodetype="expression">
</div>
</div>
</div>
</div>
</div>
</div>
<p>Now compute the expected counts for each racial group in the sample of 300 inmates.</p>
<p><strong>Expected count — white inmates:</strong></p>
<div class="cell" data-exercise="exp-white">
<div>
<div id="webr-4" class="exercise-cell">
</div>
<script type="webr-4-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImVkaXQiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLXdoaXRlIn0sImNvZGUiOiJfX19fX18ifQ==
</script>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-white">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-7-contents" aria-controls="callout-7" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 1
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-7" class="callout-7-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>What proportion of New Hampshire’s population is white?</p>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-white">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-8-contents" aria-controls="callout-8" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 2
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-8" class="callout-8-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>The expected count is the total number of prisoners multiplied by the proportion of the State’s population in that racial group.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>___ <span class="sc">*</span> ___</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-white">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-9-contents" aria-controls="callout-9" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 3
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-9" class="callout-9-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>The expected count is the total number of prisoners multiplied by the proportion of the State’s population in that racial group.</p>
<ul>
<li>There are 300 inmates in the sample.</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="dv">300</span> <span class="sc">*</span> ___</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-white">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-10-contents" aria-controls="callout-10" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 4 (Solved)
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-10" class="callout-10-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>The expected count is the total number of prisoners multiplied by the proportion of the State’s population in that racial group.</p>
<ul>
<li>There are 300 inmates in the sample.</li>
<li>According to the US Census Bureau, the proportion of white residents in NH was about 0.898.</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="dv">300</span> <span class="sc">*</span> <span class="fl">0.898</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="cell" data-exercise="exp-white" data-solution="true">
<div class="webr-ojs-exercise exercise-solution d-none" data-exercise="exp-white">
<code id="interpolate-6" class="solution-code d-none">
300 * 0.898</code>
<div class="sourceCode cell-code" id="interpolate-7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="interpolate-7-1"><a href="#interpolate-7-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="interpolate-7-2"><a href="#interpolate-7-2" aria-hidden="true" tabindex="-1"></a><span class="dv">300</span> <span class="sc">*</span> <span class="fl">0.898</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
<div class="cell" data-exercise="exp-white" data-check="true">
<script type="exercise-check-exp-white-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLXdoaXRlIiwiZWRpdCI6dHJ1ZSwiY2hlY2siOnRydWV9LCJjb2RlIjoiXG5leGVyY2lzZV9yZXN1bHRzJGV4cF93aGl0ZSA8PC0gXCJmYWlsXCJcbmdyYWRldGhpczo6Z3JhZGVfdGhpcyh7XG4gIGlmIChhYnMoLnJlc3VsdCAtIDMwMCAqIDAuODk4KSA8IDAuMDEpIHtcbiAgICBleGVyY2lzZV9yZXN1bHRzJGV4cF93aGl0ZSA8PC0gXCJwYXNzXCJcbiAgICBwYXNzKHJhbmRvbV9wcmFpc2UoKSlcbiAgfVxuICBmYWlsKHJhbmRvbV9lbmNvdXJhZ2VtZW50KCkpXG59KSJ9
</script>
</div>
<p><strong>Expected count — Black inmates:</strong></p>
<div class="cell" data-exercise="exp-black">
<div>
<div id="webr-9" class="exercise-cell">
</div>
<script type="webr-9-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImVkaXQiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLWJsYWNrIn0sImNvZGUiOiJfX19fX18ifQ==
</script>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-black">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-11-contents" aria-controls="callout-11" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 1
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-11" class="callout-11-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>Use the same approach as the previous question. What proportion of New Hampshire residents are Black?</p>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-black">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-12-contents" aria-controls="callout-12" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 2 (Solved)
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-12" class="callout-12-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>Use the same approach as the previous question. What proportion of New Hampshire residents are Black?</p>
<p>There are still 300 inmates in the sample and the proportion of black residents in NH, according to the US Census Bureau in 2019, was about 0.018.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="dv">300</span> <span class="sc">*</span> <span class="fl">0.018</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="cell" data-exercise="exp-black" data-solution="true">
<div class="webr-ojs-exercise exercise-solution d-none" data-exercise="exp-black">
<code id="interpolate-11" class="solution-code d-none">
300 * 0.018</code>
<div class="sourceCode cell-code" id="interpolate-12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="interpolate-12-1"><a href="#interpolate-12-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="interpolate-12-2"><a href="#interpolate-12-2" aria-hidden="true" tabindex="-1"></a><span class="dv">300</span> <span class="sc">*</span> <span class="fl">0.018</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
<div class="cell" data-exercise="exp-black" data-check="true">
<script type="exercise-check-exp-black-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLWJsYWNrIiwiZWRpdCI6dHJ1ZSwiY2hlY2siOnRydWV9LCJjb2RlIjoiXG5leGVyY2lzZV9yZXN1bHRzJGV4cF9ibGFjayA8PC0gXCJmYWlsXCJcbmdyYWRldGhpczo6Z3JhZGVfdGhpcyh7XG4gIGlmIChhYnMoLnJlc3VsdCAtIDMwMCAqIDAuMDE4KSA8IDAuMDEpIHtcbiAgICBleGVyY2lzZV9yZXN1bHRzJGV4cF9ibGFjayA8PC0gXCJwYXNzXCJcbiAgICBwYXNzKHJhbmRvbV9wcmFpc2UoKSlcbiAgfVxuICBmYWlsKHJhbmRvbV9lbmNvdXJhZ2VtZW50KCkpXG59KSJ9
</script>
</div>
<p><strong>Expected count — Hispanic inmates:</strong></p>
<div class="cell" data-exercise="exp-hispanic">
<div>
<div id="webr-14" class="exercise-cell">
</div>
<script type="webr-14-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImVkaXQiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLWhpc3BhbmljIn0sImNvZGUiOiJfX19fX18ifQ==
</script>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-hispanic">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-13-contents" aria-controls="callout-13" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 1
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-13" class="callout-13-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>Same approach again. What proportion of New Hampshire residents are Hispanic?</p>
</div>
</div>
</div>
</div>
<div class="cell" data-exercise="exp-hispanic" data-solution="true">
<div class="webr-ojs-exercise exercise-solution d-none" data-exercise="exp-hispanic">
<code id="interpolate-16" class="solution-code d-none">
300 * 0.040</code>
<div class="sourceCode cell-code" id="interpolate-17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="interpolate-17-1"><a href="#interpolate-17-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="interpolate-17-2"><a href="#interpolate-17-2" aria-hidden="true" tabindex="-1"></a><span class="dv">300</span> <span class="sc">*</span> <span class="fl">0.040</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
<div class="cell" data-exercise="exp-hispanic" data-check="true">
<script type="exercise-check-exp-hispanic-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLWhpc3BhbmljIiwiZWRpdCI6dHJ1ZSwiY2hlY2siOnRydWV9LCJjb2RlIjoiXG5leGVyY2lzZV9yZXN1bHRzJGV4cF9oaXNwYW5pYyA8PC0gXCJmYWlsXCJcbmdyYWRldGhpczo6Z3JhZGVfdGhpcyh7XG4gIGlmIChhYnMoLnJlc3VsdCAtIDMwMCAqIDAuMDQwKSA8IDAuMDEpIHtcbiAgICBleGVyY2lzZV9yZXN1bHRzJGV4cF9oaXNwYW5pYyA8PC0gXCJwYXNzXCJcbiAgICBwYXNzKHJhbmRvbV9wcmFpc2UoKSlcbiAgfVxuICBmYWlsKHJhbmRvbV9lbmNvdXJhZ2VtZW50KCkpXG59KSJ9
</script>
</div>
<p><strong>Expected count — inmates of other races:</strong></p>
<div class="cell" data-exercise="exp-other">
<div>
<div id="webr-19" class="exercise-cell">
</div>
<script type="webr-19-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImVkaXQiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLW90aGVyIn0sImNvZGUiOiJfX19fX18ifQ==
</script>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="exp-other">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-14-contents" aria-controls="callout-14" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 1
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-14" class="callout-14-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>Same approach. What proportion of New Hampshire residents identify as another race?</p>
</div>
</div>
</div>
</div>
<div class="cell" data-exercise="exp-other" data-solution="true">
<div class="webr-ojs-exercise exercise-solution d-none" data-exercise="exp-other">
<code id="interpolate-21" class="solution-code d-none">
300 * 0.044</code>
<div class="sourceCode cell-code" id="interpolate-22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="interpolate-22-1"><a href="#interpolate-22-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="interpolate-22-2"><a href="#interpolate-22-2" aria-hidden="true" tabindex="-1"></a><span class="dv">300</span> <span class="sc">*</span> <span class="fl">0.044</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
<div class="cell" data-exercise="exp-other" data-check="true">
<script type="exercise-check-exp-other-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZXhwLW90aGVyIiwiZWRpdCI6dHJ1ZSwiY2hlY2siOnRydWV9LCJjb2RlIjoiXG5leGVyY2lzZV9yZXN1bHRzJGV4cF9vdGhlciA8PC0gXCJmYWlsXCJcbmdyYWRldGhpczo6Z3JhZGVfdGhpcyh7XG4gIGlmIChhYnMoLnJlc3VsdCAtIDMwMCAqIDAuMDQ0KSA8IDAuMDEpIHtcbiAgICBleGVyY2lzZV9yZXN1bHRzJGV4cF9vdGhlciA8PC0gXCJwYXNzXCJcbiAgICBwYXNzKHJhbmRvbV9wcmFpc2UoKSlcbiAgfVxuICBmYWlsKHJhbmRvbV9lbmNvdXJhZ2VtZW50KCkpXG59KSJ9
</script>
</div>
<p>Now we’re ready to compute the test statistic. Recall from Dr. Çetinkaya-Rundel’s video that the <span class="math inline">\(\chi^2\)</span> statistic is:</p>
<p><span class="math display">\[\chi^2 = \sum_{i = 1}^{k}{\frac{\left(\text{observed} - \text{expected}\right)^2}{\text{expected}}}\]</span></p>
<p>where <span class="math inline">\(k\)</span> is the number of groups. As a reminder, the <span class="math inline">\(\Sigma\)</span> symbol is used to indicate that we should add terms together. You’ll calculate <span class="math inline">\(\displaystyle{\frac{\left(\text{observed} - \text{ expected}\right)^2}{\text{expected}}}\)</span> for each group (White, Black, Hispanic, and other) and add those quantities together.</p>
<p>Use the code block below to compute the <span class="math inline">\(\chi^2\)</span> test statistic. The block is pre-populated to get you started.</p>
<div class="cell" data-exercise="test-stat">
<div>
<div id="webr-24" class="exercise-cell">
</div>
<script type="webr-24-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImVkaXQiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoidGVzdC1zdGF0In0sImNvZGUiOiJcbiMgRGVmaW5lIHRoZSBvYnNlcnZlZCB2YWx1ZXNcbm9ic2VydmVkIDwtIGMoMjQzLCAyNCwgMTUsIDE4KVxuXG4jIERlZmluZSB0aGUgZXhwZWN0ZWQgdmFsdWVzIChzYW1lIG9yZGVyIGFzIG9ic2VydmVkKVxuZXhwZWN0ZWQgPC0gYyhfX18pXG5cbiMgQ29tcHV0ZSB0aGUgY2hpLXNxdWFyZWQgdGVzdCBzdGF0aXN0aWNcbnRlc3Rfc3RhdCA8LSBzdW0oKG9ic2VydmVkIC0gZXhwZWN0ZWQpXjIgLyBleHBlY3RlZClcbnRlc3Rfc3RhdCJ9
</script>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="test-stat">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-15-contents" aria-controls="callout-15" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 1
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-15" class="callout-15-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>Fill in the <code>expected</code> vector with the four expected counts you just computed — in the same order as the observed counts: White, Black, Hispanic, other.</p>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="test-stat">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-16-contents" aria-controls="callout-16" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 2 (Solved)
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-16" class="callout-16-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>The expected counts are 269.4, 5.4, 12.0, and 13.2 for White, Black, Hispanic, and other respectively.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>observed <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">243</span>, <span class="dv">24</span>, <span class="dv">15</span>, <span class="dv">18</span>)</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>expected <span class="ot"><-</span> <span class="fu">c</span>(<span class="fl">269.4</span>, <span class="fl">5.4</span>, <span class="fl">12.0</span>, <span class="fl">13.2</span>)</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>test_stat <span class="ot"><-</span> <span class="fu">sum</span>((observed <span class="sc">-</span> expected)<span class="sc">^</span><span class="dv">2</span> <span class="sc">/</span> expected)</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>test_stat</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="cell" data-exercise="test-stat" data-solution="true">
<div class="webr-ojs-exercise exercise-solution d-none" data-exercise="test-stat">
<code id="interpolate-26" class="solution-code d-none">
observed <- c(243, 24, 15, 18)
expected <- c(269.4, 5.4, 12.0, 13.2)
test_stat <- sum((observed - expected)^2 / expected)
test_stat</code>
<div class="sourceCode cell-code" id="interpolate-27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="interpolate-27-1"><a href="#interpolate-27-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="interpolate-27-2"><a href="#interpolate-27-2" aria-hidden="true" tabindex="-1"></a>observed <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">243</span>, <span class="dv">24</span>, <span class="dv">15</span>, <span class="dv">18</span>)</span>
<span id="interpolate-27-3"><a href="#interpolate-27-3" aria-hidden="true" tabindex="-1"></a>expected <span class="ot"><-</span> <span class="fu">c</span>(<span class="fl">269.4</span>, <span class="fl">5.4</span>, <span class="fl">12.0</span>, <span class="fl">13.2</span>)</span>
<span id="interpolate-27-4"><a href="#interpolate-27-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="interpolate-27-5"><a href="#interpolate-27-5" aria-hidden="true" tabindex="-1"></a>test_stat <span class="ot"><-</span> <span class="fu">sum</span>((observed <span class="sc">-</span> expected)<span class="sc">^</span><span class="dv">2</span> <span class="sc">/</span> expected)</span>
<span id="interpolate-27-6"><a href="#interpolate-27-6" aria-hidden="true" tabindex="-1"></a>test_stat</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
<div class="cell" data-exercise="test-stat" data-check="true">
<script type="exercise-check-test-stat-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoidGVzdC1zdGF0IiwiZWRpdCI6dHJ1ZSwiY2hlY2siOnRydWV9LCJjb2RlIjoiXG5leGVyY2lzZV9yZXN1bHRzJHRlc3Rfc3RhdCA8PC0gXCJmYWlsXCJcbmdyYWRldGhpczo6Z3JhZGVfdGhpcyh7XG4gIG9ic2VydmVkIDwtIGMoMjQzLCAyNCwgMTUsIDE4KVxuICBleHBlY3RlZCA8LSBjKDI2OS40LCA1LjQsIDEyLjAsIDEzLjIpXG4gIGlmIChhYnMoLnJlc3VsdCAtIHN1bSgob2JzZXJ2ZWQgLSBleHBlY3RlZCleMiAvIGV4cGVjdGVkKSkgPCAwLjAxKSB7XG4gICAgZXhlcmNpc2VfcmVzdWx0cyR0ZXN0X3N0YXQgPDwtIFwicGFzc1wiXG4gICAgcGFzcyhyYW5kb21fcHJhaXNlKCkpXG4gIH1cbiAgZmFpbChyYW5kb21fZW5jb3VyYWdlbWVudCgpKVxufSkifQ==
</script>
</div>
<p>Now compute the degrees of freedom for the <span class="math inline">\(\chi^2\)</span>-distribution associated with this test.</p>
<div class="cell" data-exercise="df">
<div>
<div id="webr-29" class="exercise-cell">
</div>
<script type="webr-29-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImVkaXQiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZGYifSwiY29kZSI6Il9fX19fXyJ9
</script>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="df">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-17-contents" aria-controls="callout-17" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 1
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-17" class="callout-17-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>For a Goodness of Fit test, how are the degrees of freedom related to the number of groups?</p>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="df">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-18-contents" aria-controls="callout-18" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 2
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-18" class="callout-18-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>The degrees of freedom for a Goodness of Fit test is one less than the number of groups.</p>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="df">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-19-contents" aria-controls="callout-19" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 3 (Solved)
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-19" class="callout-19-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>There are 4 racial groups, so the degrees of freedom is <span class="math inline">\(4 - 1 = 3\)</span>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="dv">4</span> <span class="sc">-</span> <span class="dv">1</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="cell" data-exercise="df" data-solution="true">
<div class="webr-ojs-exercise exercise-solution d-none" data-exercise="df">
<code id="interpolate-31" class="solution-code d-none">
4 - 1</code>
<div class="sourceCode cell-code" id="interpolate-32"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="interpolate-32-1"><a href="#interpolate-32-1" aria-hidden="true" tabindex="-1"></a></span>
<span id="interpolate-32-2"><a href="#interpolate-32-2" aria-hidden="true" tabindex="-1"></a><span class="dv">4</span> <span class="sc">-</span> <span class="dv">1</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
<div class="cell" data-exercise="df" data-check="true">
<script type="exercise-check-df-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiZGYiLCJlZGl0Ijp0cnVlLCJjaGVjayI6dHJ1ZX0sImNvZGUiOiJcbmV4ZXJjaXNlX3Jlc3VsdHMkZGYgPDwtIFwiZmFpbFwiXG5ncmFkZXRoaXM6OmdyYWRlX3RoaXMoe1xuICBpZiAoLnJlc3VsdCA9PSAzKSB7XG4gICAgZXhlcmNpc2VfcmVzdWx0cyRkZiA8PC0gXCJwYXNzXCJcbiAgICBwYXNzKHJhbmRvbV9wcmFpc2UoKSlcbiAgfVxuICBmYWlsKHJhbmRvbV9lbmNvdXJhZ2VtZW50KCkpXG59KSJ9
</script>
</div>
<p>Use the code block below to compute the <span class="math inline">\(p\)</span>-value. The function <code>pchisq(q, df)</code> returns the probability to the <em>left</em> of the boundary value <code>q</code> under a <span class="math inline">\(\chi^2\)</span> distribution with <code>df</code> degrees of freedom.</p>
<div class="cell" data-exercise="compute-p">
<div>
<div id="webr-34" class="exercise-cell">
</div>
<script type="webr-34-contents">
eyJhdHRyIjp7InBlcnNpc3QiOnRydWUsImVkaXQiOnRydWUsImV2YWwiOnRydWUsImV4ZXJjaXNlIjoiY29tcHV0ZS1wIn0sImNvZGUiOiJfX19fX18ifQ==
</script>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="compute-p">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-20-contents" aria-controls="callout-20" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 1
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-20" class="callout-20-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>Use your test statistic and degrees of freedom with <code>pchisq()</code>. Which tail are you interested in?</p>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="compute-p">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-21-contents" aria-controls="callout-21" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 2
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-21" class="callout-21-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>The <span class="math inline">\(p\)</span>-value is the area to the <em>right</em> of the test statistic. Since <code>pchisq()</code> gives the left-tail area, how do you obtain the right-tail area?</p>
</div>
</div>
</div>
</div>
<div class="hint webr-ojs-exercise exercise-hint d-none" data-exercise="compute-p">
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-22-contents" aria-controls="callout-22" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Hint 3
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-22" class="callout-22-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p>Just like with <code>pnorm()</code>, to obtain the area to the right of a boundary value in the <span class="math inline">\(\chi^2\)</span> distribution, we’ll subtract from 1.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="dv">1</span> <span class="sc">-</span> <span class="fu">pchisq</span>(___, <span class="at">df =</span> ___)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</div>
</div>
</div>