-
Notifications
You must be signed in to change notification settings - Fork 0
/
probability_theory_3.html
2337 lines (2292 loc) · 175 KB
/
probability_theory_3.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
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.6.1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>12 Probability Theory, Part 3 – Resampling statistics</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; }
}
/* CSS for citations */
div.csl-bib-body { }
div.csl-entry {
clear: both;
margin-bottom: 0em;
}
.hanging-indent div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}</style>
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./probability_theory_4_finite.html" rel="next">
<link href="./probability_theory_2_compound.html" rel="prev">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "sidebar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "start",
"type": "textbox",
"limit": 50,
"keyboard-shortcut": [
"f",
"/",
"s"
],
"show-item-context": false,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-text-placeholder": "",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
<script type="text/javascript">
$(document).ready(function() {
$("table").addClass('lightable-paper lightable-striped lightable-hover')
});
</script>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="font-awesome.min.css">
</head>
<body class="nav-sidebar floating">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="quarto-secondary-nav">
<div class="container-fluid d-flex">
<button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<i class="bi bi-layout-text-sidebar-reverse"></i>
</button>
<nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./probability_theory_3.html"><span class="chapter-number">12</span> <span class="chapter-title">Probability Theory, Part 3</span></a></li></ol></nav>
<a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
</a>
<button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
<i class="bi bi-search"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto">
<div class="pt-lg-2 mt-2 text-left sidebar-header">
<div class="sidebar-title mb-0 py-0">
<a href="./">Resampling statistics</a>
</div>
</div>
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">
<span class="menu-text">Python version</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./preface_third.html" class="sidebar-item-text sidebar-link">
<span class="menu-text">Preface to the third edition</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./preface_second.html" class="sidebar-item-text sidebar-link">
<span class="menu-text">Preface to the second edition</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./intro.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">1</span> <span class="chapter-title">Introduction</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./resampling_method.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span> <span class="chapter-title">The resampling method</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./what_is_probability.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">3</span> <span class="chapter-title">What is probability?</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./about_technology.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">4</span> <span class="chapter-title">Introducing Python and the Jupyter notebook</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./resampling_with_code.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">5</span> <span class="chapter-title">Resampling with code</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./resampling_with_code2.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">6</span> <span class="chapter-title">More resampling with code</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./sampling_tools.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">7</span> <span class="chapter-title">Tools for samples and sampling</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./probability_theory_1a.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">8</span> <span class="chapter-title">Probability Theory, Part 1</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./probability_theory_1b.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">9</span> <span class="chapter-title">Probability Theory Part I (continued)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./more_sampling_tools.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">10</span> <span class="chapter-title">Two puzzles and more tools</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./probability_theory_2_compound.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">11</span> <span class="chapter-title">Probability Theory, Part 2: Compound Probability</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./probability_theory_3.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">12</span> <span class="chapter-title">Probability Theory, Part 3</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./probability_theory_4_finite.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">13</span> <span class="chapter-title">Probability Theory, Part 4: Estimating Probabilities from Finite Universes</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./sampling_variability.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">14</span> <span class="chapter-title">On Variability in Sampling</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./monte_carlo.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">15</span> <span class="chapter-title">The Procedures of Monte Carlo Simulation (and Resampling)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./standard_scores.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">16</span> <span class="chapter-title">Ranks, Quantiles and Standard Scores</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./inference_ideas.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">17</span> <span class="chapter-title">The Basic Ideas in Statistical Inference</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./inference_intro.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">18</span> <span class="chapter-title">Introduction to Statistical Inference</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./point_estimation.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">19</span> <span class="chapter-title">Point Estimation</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./framing_questions.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">20</span> <span class="chapter-title">Framing Statistical Questions</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./testing_counts_1.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">21</span> <span class="chapter-title">Hypothesis-Testing with Counted Data, Part 1</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./significance.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">22</span> <span class="chapter-title">The Concept of Statistical Significance in Testing Hypotheses</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./testing_counts_2.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">23</span> <span class="chapter-title">The Statistics of Hypothesis-Testing with Counted Data, Part 2</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./testing_measured.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">24</span> <span class="chapter-title">The Statistics of Hypothesis-Testing With Measured Data</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./testing_procedures.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">25</span> <span class="chapter-title">General Procedures for Testing Hypotheses</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./confidence_1.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">26</span> <span class="chapter-title">Confidence Intervals, Part 1: Assessing the Accuracy of Samples</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./confidence_2.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">27</span> <span class="chapter-title">Confidence Intervals, Part 2: The Two Approaches to Estimating Confidence Intervals</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./reliability_average.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">28</span> <span class="chapter-title">Some Last Words About the Reliability of Sample Averages</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./correlation_causation.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">29</span> <span class="chapter-title">Correlation and Causation</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./how_big_sample.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">30</span> <span class="chapter-title">How Large a Sample?</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./bayes_simulation.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">31</span> <span class="chapter-title">Bayesian Analysis by Simulation</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./references.html" class="sidebar-item-text sidebar-link">
<span class="menu-text">References</span></a>
</div>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
<span class="menu-text">Appendices</span></a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./exercise_solutions.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">A</span> <span class="chapter-title">Exercise Solutions</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./technical_note.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">B</span> <span class="chapter-title">Technical Note to the Professional Reader</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./acknowlegements.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">C</span> <span class="chapter-title">Acknowledgements</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./code_topics.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">D</span> <span class="chapter-title">Code topics</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./errors_suggestions.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">E</span> <span class="chapter-title">Errors and suggestions</span></span></a>
</div>
</li>
</ul>
</li>
</ul>
</div>
</nav>
<div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#sec-birthday-problem" id="toc-sec-birthday-problem" class="nav-link active" data-scroll-target="#sec-birthday-problem"><span class="header-section-number">12.1</span> Example: The Birthday Problem</a></li>
<li><a href="#example-three-daughters-among-four-children" id="toc-example-three-daughters-among-four-children" class="nav-link" data-scroll-target="#example-three-daughters-among-four-children"><span class="header-section-number">12.2</span> Example: Three Daughters Among Four Children</a></li>
<li><a href="#and-the-probp-argument" id="toc-and-the-probp-argument" class="nav-link" data-scroll-target="#and-the-probp-argument"><span class="header-section-number">12.3</span> <code>rnd.choice</code> and the <span class="python"><code>p</code></span> argument</a></li>
<li><a href="#the-daughters-problem-with-more-accurate-probabilities" id="toc-the-daughters-problem-with-more-accurate-probabilities" class="nav-link" data-scroll-target="#the-daughters-problem-with-more-accurate-probabilities"><span class="header-section-number">12.4</span> The daughters problem with more accurate probabilities</a></li>
<li><a href="#a-note-on-clarifying-and-labeling-problems" id="toc-a-note-on-clarifying-and-labeling-problems" class="nav-link" data-scroll-target="#a-note-on-clarifying-and-labeling-problems"><span class="header-section-number">12.5</span> A note on clarifying and labeling problems</a></li>
<li><a href="#binomial-trials" id="toc-binomial-trials" class="nav-link" data-scroll-target="#binomial-trials"><span class="header-section-number">12.6</span> Binomial trials</a></li>
<li><a href="#example-three-or-more-successful-basketball-shots-in-five-attempts" id="toc-example-three-or-more-successful-basketball-shots-in-five-attempts" class="nav-link" data-scroll-target="#example-three-or-more-successful-basketball-shots-in-five-attempts"><span class="header-section-number">12.7</span> Example: Three or More Successful Basketball Shots in Five Attempts</a></li>
<li><a href="#note-to-the-student-of-analytic-probability-theory" id="toc-note-to-the-student-of-analytic-probability-theory" class="nav-link" data-scroll-target="#note-to-the-student-of-analytic-probability-theory"><span class="header-section-number">12.8</span> Note to the student of analytic probability theory</a></li>
<li><a href="#sec-one-black-archery" id="toc-sec-one-black-archery" class="nav-link" data-scroll-target="#sec-one-black-archery"><span class="header-section-number">12.9</span> Example: One in Black, Two in White, No Misses in Three Archery Shots</a></li>
<li><a href="#example-two-groups-of-heart-patients" id="toc-example-two-groups-of-heart-patients" class="nav-link" data-scroll-target="#example-two-groups-of-heart-patients"><span class="header-section-number">12.10</span> Example: Two Groups of Heart Patients</a></li>
<li><a href="#example-dispersion-of-a-sum-of-random-variables-hammer-lengths-heads-and-handles" id="toc-example-dispersion-of-a-sum-of-random-variables-hammer-lengths-heads-and-handles" class="nav-link" data-scroll-target="#example-dispersion-of-a-sum-of-random-variables-hammer-lengths-heads-and-handles"><span class="header-section-number">12.11</span> Example: Dispersion of a Sum of Random Variables — Hammer Lengths — Heads and Handles</a></li>
<li><a href="#example-the-product-of-random-variables-theft-by-employees" id="toc-example-the-product-of-random-variables-theft-by-employees" class="nav-link" data-scroll-target="#example-the-product-of-random-variables-theft-by-employees"><span class="header-section-number">12.12</span> Example: The Product of Random Variables — Theft by Employees</a></li>
<li><a href="#example-flipping-pennies-to-the-end" id="toc-example-flipping-pennies-to-the-end" class="nav-link" data-scroll-target="#example-flipping-pennies-to-the-end"><span class="header-section-number">12.13</span> Example: Flipping Pennies to the End</a></li>
<li><a href="#example-a-drunks-random-walk" id="toc-example-a-drunks-random-walk" class="nav-link" data-scroll-target="#example-a-drunks-random-walk"><span class="header-section-number">12.14</span> Example: A Drunk’s Random Walk</a></li>
<li><a href="#sec-public-liquor" id="toc-sec-public-liquor" class="nav-link" data-scroll-target="#sec-public-liquor"><span class="header-section-number">12.15</span> Example: public and private liquor pricing</a>
<ul class="collapse">
<li><a href="#sec-concatenate" id="toc-sec-concatenate" class="nav-link" data-scroll-target="#sec-concatenate"><span class="header-section-number">12.15.1</span> Concatenating arrays</a></li>
<li><a href="#sec-on-histograms" id="toc-sec-on-histograms" class="nav-link" data-scroll-target="#sec-on-histograms"><span class="header-section-number">12.15.2</span> Plotting histograms</a></li>
<li><a href="#price-simulation" id="toc-price-simulation" class="nav-link" data-scroll-target="#price-simulation"><span class="header-section-number">12.15.3</span> Price simulation</a></li>
</ul></li>
<li><a href="#the-general-procedure" id="toc-the-general-procedure" class="nav-link" data-scroll-target="#the-general-procedure"><span class="header-section-number">12.16</span> The general procedure</a></li>
</ul>
</nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title"><span id="sec-infinite-universes" class="quarto-section-identifier"><span class="chapter-number">12</span> <span class="chapter-title">Probability Theory, Part 3</span></span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>This chapter discusses problems whose appropriate concept of a universe is not finite, whereas <a href="probability_theory_4_finite.html" class="quarto-xref"><span>Chapter 13</span></a> discusses problems whose appropriate concept of a universe is finite.</p>
<p>How can a universe be infinite yet known? Consider, for example, the possible flips with a given coin; the number is not limited in any meaningful sense, yet we understand the properties of the coin and the probabilities of a head and a tail.</p>
<section id="sec-birthday-problem" class="level2" data-number="12.1">
<h2 data-number="12.1" class="anchored" data-anchor-id="sec-birthday-problem"><span class="header-section-number">12.1</span> Example: The Birthday Problem</h2>
<p>This examples illustrates the probability of duplication in a multi-outcome sample from an infinite universe.</p>
<p>As an indication of the power <em>and</em> simplicity of resampling methods, consider this famous examination question used in probability courses: What is the probability that two or more people among a roomful of (say) twenty-five people will have the same birthday? To obtain an answer we need simply examine the first twenty-five numbers from the random-number table that fall between “001” and “365” (the number of days in the year), record whether or not there is a duplication among the twenty-five, and repeat the process often enough to obtain a reasonably stable probability estimate.</p>
<p>Pose the question to a mathematical friend of yours, then watch her or him sweat for a while, and afterwards compare your answer to hers/his. I think you will find the correct answer very surprising. It is not unheard of for people who know how this problem works to take advantage of their knowledge by making and winning big bets on it. (See how a bit of knowledge of probability can immediately be profitable to you by avoiding such unfortunate occurrences?)</p>
<p>More specifically, these steps answer the question for the case of twenty-five people in the room:</p>
<ul>
<li><strong>Step 1.</strong> Let three-digit random numbers 1-365 stand for the 365 days in the year. (Ignore leap year for simplicity.)</li>
<li><strong>Step 2.</strong> Examine for duplication among the first twenty-five random numbers chosen “001-365.” (Triplicates or higher-order repeats are counted as duplicates here.) If there is one or more duplicate, record “yes.” Otherwise record “no.”</li>
<li><strong>Step 3.</strong> Repeat perhaps a thousand times, and calculate the proportion of a duplicate birthday among twenty-five people.</li>
</ul>
<p>You would probably use the computer to generate the initial random numbers.</p>
<p>Now try the program written as follows.</p>
<div id="nte-birthday_problem" 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">
Note 12.1: Notebook: The Birthday Problem
</div>
</div>
<div class="callout-body-container callout-body">
<div class="nb-links">
<p><a class="notebook-link" href="notebooks/birthday_problem.ipynb">Download notebook</a> <a class="interact-button" href="./interact/lab/index.html?path=birthday_problem.ipynb">Interact</a></p>
</div>
</div>
</div>
<div class="nb-start" name="birthday_problem" title="The Birthday Problem">
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>rnd <span class="op">=</span> np.random.default_rng()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>n_with_same_birthday <span class="op">=</span> np.zeros(<span class="dv">10000</span>)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>days_of_year <span class="op">=</span> np.arange(<span class="dv">1</span>, <span class="dv">366</span>) <span class="co"># 1 through 365</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Do 10000 trials (experiments)</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">10000</span>):</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># Generate 25 numbers randomly between "1" and "365" put them in a.</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> a <span class="op">=</span> rnd.choice(days_of_year, size<span class="op">=</span><span class="dv">25</span>)</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="co"># Looking in a, count the number of multiples and put the result in</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="co"># b. We request multiples > 1 because we are interested in any multiple,</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="co"># whether it is a duplicate, triplicate, etc. Had we been interested only</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> <span class="co"># in duplicates, we would have put in np.sum(counts == 2).</span></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> counts <span class="op">=</span> np.bincount(a)</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> n_duplicates <span class="op">=</span> np.<span class="bu">sum</span>(counts <span class="op">></span> <span class="dv">1</span>)</span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> <span class="co"># Score the result of each trial to our store</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a> n_with_same_birthday[i] <span class="op">=</span> n_duplicates</span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a> <span class="co"># End the loop for the trial, go back and repeat the trial until all 10000</span></span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> <span class="co"># are complete, then proceed.</span></span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a><span class="co"># Determine how many trials had at least one multiple.</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a>k <span class="op">=</span> np.<span class="bu">sum</span>(n_with_same_birthday)</span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a><span class="co"># Convert to a proportion.</span></span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a>kk <span class="op">=</span> k <span class="op">/</span> <span class="dv">10000</span></span>
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-29"><a href="#cb2-29" aria-hidden="true" tabindex="-1"></a><span class="co"># Print the result.</span></span>
<span id="cb2-30"><a href="#cb2-30" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(kk)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>0.7799</code></pre>
</div>
</div>
<div class="nb-end">
</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">
End of notebook: The Birthday Problem
</div>
</div>
<div class="callout-body-container callout-body">
<p><code>birthday_problem</code> starts at <a href="#nte-birthday_problem" class="quarto-xref">Note <span>12.1</span></a>.</p>
</div>
</div>
<p>We have dealt with this example in a rather intuitive and unsystematic fashion. From here on, we will work in a more systematic, step-by-step manner. And from here on the problems form an orderly sequence of the classical types of problems in probability theory (<a href="#sec-infinite-universes" class="quarto-xref"><span>Chapter 12</span></a> and <a href="probability_theory_4_finite.html" class="quarto-xref"><span>Chapter 13</span></a>), and inferential statistics (<a href="framing_questions.html" class="quarto-xref"><span>Chapter 20</span></a> to <a href="reliability_average.html" class="quarto-xref"><span>Chapter 28</span></a>.)</p>
</section>
<section id="example-three-daughters-among-four-children" class="level2" data-number="12.2">
<h2 data-number="12.2" class="anchored" data-anchor-id="example-three-daughters-among-four-children"><span class="header-section-number">12.2</span> Example: Three Daughters Among Four Children</h2>
<p>This problem illustrates a problem with two outcomes (Binomial<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>) and sampling with Replacement Among Equally Likely Outcomes.</p>
<p>What is the probability that exactly three of the four children in a four-child family will be daughters?<a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a></p>
<p>The first step is to state that the approximate probability that a single birth will produce a daughter is 50-50 (1 in 2). This estimate is not strictly correct, because there are roughly 106 male children born to each 100 female children. But the approximation is close enough for most purposes, and the 50-50 split simplifies the job considerably. (Such “false” approximations are part of the everyday work of the scientist. The appropriate question is not whether or not a statement is “only” an approximation, but whether or not it is a <em>good enough</em> approximation for your purposes.)</p>
<p>The probability that a fair coin will turn up heads is .50 or 50-50, close to the probability of having a daughter. Therefore, flip a coin in groups of four flips, and count how often three of the flips produce <em>heads</em>. (You must decide in <em>advance</em> whether three heads means three girls or three boys.) It is as simple as that.</p>
<p>In resampling estimation it is of the highest importance to work in a careful, step-by-step fashion — to write down the steps in the estimation, and then to do the experiments just as described in the steps. Here are a set of steps that will lead to a correct answer about the probability of getting three daughters among four children:</p>
<ul>
<li><strong>Step 1.</strong> Using coins, let “heads” equal “girl” and “tails” equal “boy.”</li>
<li><strong>Step 2.</strong> Throw four coins.</li>
<li><strong>Step 3.</strong> Examine whether the four coins fall with exactly three heads up. If so, write “yes” on a record sheet; otherwise write “no.”</li>
<li><strong>Step 4.</strong> Repeat step 2 perhaps two hundred times.</li>
<li><strong>Step 5.</strong> Count the proportion “yes.” This proportion is an estimate of the probability of obtaining exactly 3 daughters in 4 children.</li>
</ul>
<p>The first few experimental trials might appear in the record sheet as follows (<a href="#tbl-coins-girls" class="quarto-xref">Table <span>12.1</span></a>):</p>
<div id="tbl-coins-girls" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-coins-girls-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table 12.1: Example trials from the three-girls problem
</figcaption>
<div aria-describedby="tbl-coins-girls-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="caption-top table">
<thead>
<tr class="header">
<th>Number of Heads</th>
<th>Yes or No</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>1</td>
<td>No</td>
</tr>
<tr class="even">
<td>0</td>
<td>No</td>
</tr>
<tr class="odd">
<td>3</td>
<td>Yes</td>
</tr>
<tr class="even">
<td>2</td>
<td>No</td>
</tr>
<tr class="odd">
<td>1</td>
<td>No</td>
</tr>
<tr class="even">
<td>2</td>
<td>No</td>
</tr>
<tr class="odd">
<td>…</td>
<td>…</td>
</tr>
<tr class="even">
<td>…</td>
<td>…</td>
</tr>
<tr class="odd">
<td>…</td>
<td>…</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
<p>The probability of getting three daughters in four births could also be found with a deck of cards, a random number table, a die, or with Python. For example, half the cards in a deck are black, so the probability of getting a black card (“daughter”) from a full deck is 1 in 2. Therefore, deal a card, record “daughter” or “son,” <em>replace</em> the card, shuffle, deal again, and so forth for 200 sets of four cards. Then count the proportion of groups of four cards in which you got four daughters.</p>
<div id="nte-three_girls" 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">
Note 12.2: Notebook: Three Girls
</div>
</div>
<div class="callout-body-container callout-body">
<div class="nb-links">
<p><a class="notebook-link" href="notebooks/three_girls.ipynb">Download notebook</a> <a class="interact-button" href="./interact/lab/index.html?path=three_girls.ipynb">Interact</a></p>
</div>
</div>
</div>
<div class="nb-start" name="three_girls" title="Three Girls">
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>rnd <span class="op">=</span> np.random.default_rng()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>girl_counts <span class="op">=</span> np.zeros(<span class="dv">10000</span>)</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Do 10000 trials</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">10000</span>):</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># Select 'girl' or 'boy' at random, four times.</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> children <span class="op">=</span> rnd.choice([<span class="st">'girl'</span>, <span class="st">'boy'</span>], size<span class="op">=</span><span class="dv">4</span>)</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># Count the number of girls and put the result in b.</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> b <span class="op">=</span> np.<span class="bu">sum</span>(children <span class="op">==</span> <span class="st">'girl'</span>)</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a> <span class="co"># Keep track of each trial result in z.</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a> girl_counts[i] <span class="op">=</span> b</span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a> <span class="co"># End this trial, repeat the experiment until 10000 trials are complete,</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a> <span class="co"># then proceed.</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a><span class="co"># Count the number of experiments where we got exactly 3 girls, and put this</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a><span class="co"># result in k.</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a>n_three_girls <span class="op">=</span> np.<span class="bu">sum</span>(girl_counts <span class="op">==</span> <span class="dv">3</span>)</span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a><span class="co"># Convert to a proportion.</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a>three_girls_prop <span class="op">=</span> n_three_girls <span class="op">/</span> <span class="dv">10000</span></span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true" tabindex="-1"></a><span class="co"># Print the results.</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(three_girls_prop)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>0.2502</code></pre>
</div>
</div>
<div class="nb-end">
</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">
End of notebook: Three Girls
</div>
</div>
<div class="callout-body-container callout-body">
<p><code>three_girls</code> starts at <a href="#nte-three_girls" class="quarto-xref">Note <span>12.2</span></a>.</p>
</div>
</div>
<p>Notice that the procedure outlined in the steps above would have been different (though almost identical) if we asked about the probability of <em>three or more</em> daughters rather than <em>exactly three</em> daughters among four children. For <em>three or more</em> daughters we would have scored “yes” on our score-keeping pad for <em>either</em> three or four heads, rather than for just three heads. Likewise, in the computer solution we would have used the statement <span class="python"><code>n_three_girls = np.sum(girl_counts >= 3)</code></span> .</p>
<p>It is important that, in this case, in contrast to what we did in the example from <a href="probability_theory_2_compound.html#sec-one-pair" class="quarto-xref"><span>Section 11.2</span></a> (the introductory poker example), the card is <em>replaced</em> each time so that each card is dealt from a full deck. This method is known as <em>sampling with replacement</em>. One samples with replacement whenever the successive events are <em>independent</em> ; in this case we assume that the chance of having a daughter remains the same (1 girl in 2 births) no matter what sex the previous births were<a href="#fn3" class="footnote-ref" id="fnref3" role="doc-noteref"><sup>3</sup></a>. But, if the first card dealt is black and would <em>not</em> be replaced, the chance of the second card being black would no longer be 26 in 52 (.50), but rather 25 in 51 (.49), if the first <em>three</em> cards are black and would not be replaced, the chances of the fourth card’s being black would sink to 23 in 49 (.47).</p>
<p>To push the illustration further, consider what would happen if we used a deck of only six cards, half (3 of 6) black and half (3 of 6) red, instead of a deck of 52 cards. If the chosen card is replaced each time, the 6-card deck produces the same results as a 52-card deck; in fact, a two-card deck would do as well. But, if the sampling is done <em>without</em> replacement, it is <em>impossible</em> to obtain 4 “daughters” with the 6-card deck because there are only 3 “daughters” in the deck. To repeat, then, whenever you want to estimate the probability of some series of events where each event is independent of the other, you must sample <em>with replacement</em>. ## Variations of the daughters problem</p>
<p>In later chapters we will frequently refer to a problem which is identical in basic structure to the problem of three girls in four children — the probability of getting 9 females in ten calf births if the probability of a female birth is (say) .5 — when we set this problem in the context of the possibility that a genetic engineering practice is effective in increasing the proportion of females (desirable for the production of milk).</p>
<p>So far we have assumed the simple case where we have an array of values that we are sampling from, and we are selecting each of these values into the sample with equal probability.</p>
<p>For example, we started with the simple assumption that a child is just as likely to be born a boy as a girl. Our input is:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>input_values <span class="op">=</span> [<span class="st">'girl'</span>, <span class="st">'boy'</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>By default, <code>rnd.choice</code> will draw the input values with equal probability. Here, we draw a sample (<code>children</code>) of four values from the input, where <em>each value</em> in <code>children</code> has an equal chance of being “girl” or “boy”.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>children <span class="op">=</span> rnd.choice(input_values, size<span class="op">=</span><span class="dv">4</span>)</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>children</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>array(['boy', 'boy', 'boy', 'girl'], dtype='<U4')</code></pre>
</div>
</div>
<p>That is, <code>rnd.choice</code> gives each element in <code>input_values</code> an equal chance of being selected as the next element in <code>children</code>.</p>
<p>That is fine if we have some simple probability to simulate, like 0.5. But now let us imagine we want to get more precise. We happen to know that any given birth is just slightly more likely to be a boy than a girl.<a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a>. For example, the <a href="https://www.gov.uk/government/statistics/gender-ratios-at-birth-in-great-britain-2010-to-2014">proportion of boys born in the UK</a> is 0.513. Hence the proportion of girls is 1-0.513 = 0.487.</p>
</section>
<section id="and-the-probp-argument" class="level2" data-number="12.3">
<h2 data-number="12.3" class="anchored" data-anchor-id="and-the-probp-argument"><span class="header-section-number">12.3</span> <code>rnd.choice</code> and the <span class="python"><code>p</code></span> argument</h2>
<p>We could replicate this probability of 0.487 for ‘girl’ in the output sample by making an input array of 1000 strings, that contains 487 ‘girls’ and 513 ‘boys’:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>big_girls <span class="op">=</span> np.repeat([<span class="st">'girl'</span>, <span class="st">'boy'</span>], [<span class="dv">487</span>, <span class="dv">513</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Now if we sample using the default in <code>rnd.choice</code>, each <em>element</em> in the input <code>big_girls</code> array will have the same chance of appearing in the sample, but because there are 487 ‘girls’, and 513 ‘boys’, each with an equal chance of appearing in the sample, we will get a ‘girl’ in roughly 487 out of every 1000 elements we draw, and a boy roughly 513 / 1000 times. That is, our chance of any one element of being a ‘girl’ is, as we want, 0.487.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Now each element has probability 0.487 of 'girl', 0.513 of 'boy'.</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>realistic_children <span class="op">=</span> rnd.choice(big_girls, size<span class="op">=</span><span class="dv">4</span>)</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>realistic_children</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>array(['boy', 'boy', 'girl', 'boy'], dtype='<U4')</code></pre>
</div>
</div>
<p>But, there is an easier way than compiling a big 1000 element array, and that is to use the <span class="python"><code>p=</code></span> argument to <code>rnd.choice</code>. This allows us to specify the probability with which we will draw each of the input elements into the output sample. For example, to draw ‘girl’ with probability 0.487 and ‘boy’ with probability 0.513, we would do:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Draw 'girl' with probability (p) 0.487 and 'boy' 0.513.</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>children_again <span class="op">=</span> rnd.choice([<span class="st">'girl'</span>, <span class="st">'boy'</span>], size<span class="op">=</span><span class="dv">4</span>, p<span class="op">=</span>[<span class="fl">0.487</span>, <span class="fl">0.513</span>])</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>children_again</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>array(['girl', 'boy', 'girl', 'girl'], dtype='<U4')</code></pre>
</div>
</div>
<p>The <span class="python"><code>p</code></span> argument allows us to specify the probability of each element in the input array — so if we had three elements in the input array, we would need three probabilities in <span class="python"><code>p</code></span>. For example, let’s say we were looking at some poorly-entered hospital records, we might have ‘girl’ or ‘boy’ recorded as the child’s gender, but the record might be missing — ‘not-recorded’ — with a 19% chance:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Draw 'girl' with probability (p) 0.4, 'boy' with p=0.41, 'not-recorded' with</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="co"># p=0.19.</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>rnd.choice([<span class="st">'girl'</span>, <span class="st">'boy'</span>, <span class="st">'not-recorded'</span>], size<span class="op">=</span><span class="dv">30</span>, p<span class="op">=</span>[<span class="fl">0.4</span>, <span class="fl">0.41</span>, <span class="fl">0.19</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-stdout">
<pre><code>array(['girl', 'girl', 'girl', 'girl', 'boy', 'girl', 'girl',
'not-recorded', 'girl', 'boy', 'boy', 'girl', 'girl', 'boy',
'not-recorded', 'girl', 'not-recorded', 'boy', 'girl', 'boy',
'not-recorded', 'girl', 'boy', 'girl', 'boy', 'not-recorded',
'girl', 'girl', 'boy', 'not-recorded'], dtype='<U12')</code></pre>
</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">
How does the <span class="python"><code>p</code></span> argument to <code>rnd.choice</code> work?
</div>
</div>
<div class="callout-body-container callout-body">
<p>You might wonder how Python does this trick of choosing the elements with different probabilities.</p>
<p>One way of doing this is to use <em>uniform</em> random numbers from 0 through 1. These are floating point numbers that can take any value, at random, from 0 through 1.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Run this cell a few times to see random numbers anywhere from 0 through 1.</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>rnd.uniform()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>0.3358873070551027</code></pre>
</div>
</div>
<p>Because this random uniform number has an equal chance of being anywhere in the range 0 through 1, there is a 50% chance that any given number will be less then 0.5 and a 50% chance it is greater than 0.5. (Of course it could be <em>exactly equal to</em> 0.5, but this is vanishingly unlikely, so we will ignore that for now).</p>
<p>So, if we thought girls were exactly as likely as boys, we could select from ‘girl’ and ‘boy’ using this simple logic:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> rnd.uniform() <span class="op"><</span> <span class="fl">0.5</span>:</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> result <span class="op">=</span> <span class="st">'girl'</span></span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span>:</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a> result <span class="op">=</span> <span class="st">'boy'</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>But, by the same logic, there is a 0.487 chance that the random uniform number will be less than 0.487 and a 0.513 chance it will be greater. So, if we wanted to give ourselves a 0.487 chance of ‘girl’, we could do:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> rnd.uniform() <span class="op"><</span> <span class="fl">0.487</span>:</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> result <span class="op">=</span> <span class="st">'girl'</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span>:</span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> result <span class="op">=</span> <span class="st">'boy'</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>We can extend the same kind of logic to three options. For example, there is a 0.4 chance the random uniform number will be less than 0.4, a 0.41 chance it will be somewhere between 0.4 and 0.81, and a 0.19 chance it will be greater than 0.81.</p>
</div>
</div>
</section>
<section id="the-daughters-problem-with-more-accurate-probabilities" class="level2" data-number="12.4">
<h2 data-number="12.4" class="anchored" data-anchor-id="the-daughters-problem-with-more-accurate-probabilities"><span class="header-section-number">12.4</span> The daughters problem with more accurate probabilities</h2>
<p>We can use the probability argument to <code>rnd.choice</code> to do a more realistic simulation of the chance of a family with exactly three girls. In this case it is easy to make the chance for the Python simulation, but much more difficult using physical devices like coins to simulate the randomness.</p>
<p>Remember, the original code for the 50-50 case, has the following:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select 'girl' or 'boy' at random, four times.</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>children <span class="op">=</span> rnd.choice([<span class="st">'girl'</span>, <span class="st">'boy'</span>], size<span class="op">=</span><span class="dv">4</span>)</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Count the number of girls and put the result in b.</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>b <span class="op">=</span> np.<span class="bu">sum</span>(children <span class="op">==</span> <span class="st">'girl'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The only change we need to the above, for the 0.487 - 0.513 case, is the one you see above:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Give 'girl' 48.7% of the time, 'boy' 51.3% of the time.</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>children <span class="op">=</span> rnd.choice([<span class="st">'girl'</span>, <span class="st">'boy'</span>], size<span class="op">=</span><span class="dv">4</span>, p<span class="op">=</span>[<span class="fl">0.487</span>, <span class="fl">0.513</span>])</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>b <span class="op">=</span> np.<span class="bu">sum</span>(children <span class="op">==</span> <span class="st">'girl'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The rest of the program remains unchanged.</p>
</section>
<section id="a-note-on-clarifying-and-labeling-problems" class="level2" data-number="12.5">
<h2 data-number="12.5" class="anchored" data-anchor-id="a-note-on-clarifying-and-labeling-problems"><span class="header-section-number">12.5</span> A note on clarifying and labeling problems</h2>
<p>In conventional analytic texts and courses on inferential statistics, students are taught to distinguish between various classes of problems in order to decide which formula to apply. I doubt the wisdom of categorizing and labeling problems in that fashion, and the practice is unnecessary here. I consider it better that the student think through every new problem in the most fundamental terms. The exercise of this basic thinking avoids the mistakes that come from too-hasty and superficial pigeon-holing of problems into categories. Nevertheless, in order to help readers connect up the resampling material with the conventional curriculum of analytic methods, the examples presented here are given their conventional labels. And the examples given here cover the range of problems encountered in courses in probability and inferential statistics.</p>
<p>To repeat, one does not need to classify a problem when one proceeds with the Monte Carlo resampling method; you simply model the features of the situation you wish to analyze. In contrast, with conventional methods you must classify the situation and then apply procedures according to rules that depend upon the classification; often the decision about which rules to follow must be messy because classification is difficult in many cases, which contributes to the difficulty of choosing correct conventional formulaic methods.</p>
</section>
<section id="binomial-trials" class="level2" data-number="12.6">
<h2 data-number="12.6" class="anchored" data-anchor-id="binomial-trials"><span class="header-section-number">12.6</span> Binomial trials</h2>
<p>The problem of the three daughters in four births is known in the conventional literature as a “binomial sampling experiment with equally-likely outcomes.” “Binomial” means that the <em>individual</em> simple event (a birth or a coin flip) can have only <em>two outcomes</em> (boy or girl, heads or tails), “binomial” meaning “two names” in Latin.<a href="#fn5" class="footnote-ref" id="fnref5" role="doc-noteref"><sup>5</sup></a></p>
<p>A fundamental property of binomial processes is that the individual trials are <em>independent</em>, a concept discussed earlier. A binomial sampling process is a <em>series</em> of binomial (one-of-two-outcome) events about which one may ask many sorts of questions — the probability of exactly X heads (“successes”) in N trials, or the probability of X or more “successes” in N trials, and so on.</p>
<p>“Equally likely outcomes” means we assume that the probability of a girl or boy in any one birth is the same (though this assumption is slightly contrary to fact); we represent this assumption with the equal-probability heads and tails of a coin. Shortly we will come to binomial sampling experiments where the probabilities of the individual outcomes are <em>not</em> equal.</p>
<p>The term “with replacement” was explained earlier; if we were to use a deck of red and black cards (instead of a coin) for this resampling experiment, we would <em>replace</em> the card each time a card is drawn.</p>
<p>The introductory poker example from <a href="probability_theory_2_compound.html#sec-one-pair" class="quarto-xref"><span>Section 11.2</span></a>, illustrated sampling without replacement, as will other examples to follow.</p>
<p>This problem would be done conventionally with the binomial theorem using probabilities of .5, or of .487 and .513, asking about 3 successes in 4 trials.</p>
</section>
<section id="example-three-or-more-successful-basketball-shots-in-five-attempts" class="level2" data-number="12.7">
<h2 data-number="12.7" class="anchored" data-anchor-id="example-three-or-more-successful-basketball-shots-in-five-attempts"><span class="header-section-number">12.7</span> Example: Three or More Successful Basketball Shots in Five Attempts</h2>
<p>This is an example of two-outcome sampling with unequally-likely outcomes, with replacement — a binomial experiment.</p>
<p>What is the probability that a basketball player will score three or more baskets in five shots from a spot 30 feet from the basket, if on the average she succeeds with 25 percent of her shots from that spot?</p>
<p>In this problem the probabilities of “success” or “failure” are not equal, in contrast to the previous problem of the daughters. Instead of a 50-50 coin, then, an appropriate “model” would be a thumbtack that has a 25 percent chance of landing “up” when it falls, and a 75 percent chance of landing down.</p>
<p>If we lack a thumbtack known to have a 25 percent chance of landing “up,” we could use a card deck and let spades equal “success” and the other three suits represent “failure.” Our resampling experiment could then be done as follows:</p>
<ol type="1">
<li>Let “spade” stand for “successful shot,” and the other suits stand for unsuccessful shot.</li>
<li>Draw a card, record its suit (“spade” or “other”) and replace. Do so five times (for five shots).</li>
<li>Record whether the outcome of step 2 was three or more spades. If so indicate “yes,” and otherwise “no.”</li>
<li>Repeat steps 2-4 perhaps four hundred times.</li>
<li>Count the proportion “yes” out of the four hundred throws. That proportion estimates the probability of getting three or more baskets out of five shots if the probability of a single basket is .25.</li>
</ol>
<p>The first four repetitions on your score sheet might look like this (<a href="#tbl-three-shots" class="quarto-xref">Table <span>12.2</span></a>):</p>
<div id="tbl-three-shots" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-three-shots-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table 12.2: First four repetitions of 3 or more shots simulation
</figcaption>
<div aria-describedby="tbl-three-shots-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="caption-top table">
<thead>
<tr class="header">
<th>Card 1</th>
<th>Card 2</th>
<th>Card 3</th>
<th>Card 4</th>
<th>Card 5</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Spade</td>
<td>Other</td>
<td>Other</td>
<td>Other</td>
<td>Other</td>
<td>No</td>
</tr>
<tr class="even">
<td>Other</td>
<td>Other</td>
<td>Other</td>
<td>Other</td>
<td>Other</td>
<td>No</td>
</tr>
<tr class="odd">
<td>Spade</td>
<td>Spade</td>
<td>Other</td>
<td>Spade</td>
<td>Spade</td>
<td>Yes</td>
</tr>
<tr class="even">
<td>Other</td>
<td>Spade</td>
<td>Other</td>
<td>Other</td>
<td>Spade</td>
<td>No</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
<p>Instead of cards, we could have used two-digit random numbers, with (say) “1-25” standing for “success,” and “26-00” (“00” in place of “100”) standing for failure. Then the steps would simply be:</p>
<ol type="1">
<li>Let the random numbers “1-25” stand for “successful shot,” “26-00” for unsuccessful shot.</li>
<li>Draw five random numbers;</li>
<li>Count how many of the numbers are between “01” and “25.” If three or more, score “yes.”</li>
<li>Repeat step 2 four hundred times.</li>
</ol>
<p>If you understand the earlier “three_girls” program, then the program below should be easy: To create 10000 samples, we start with a <code>for</code> statement. We then sample 5 numbers between “1” and “4” into our variable <code>a</code> to simulate the 5 shots, each with a 25 percent — or 1 in 4 — chance of scoring. We decide that 1 will stand for a successful shot, and 2 through 4 will stand for a missed shot, and therefore we count (<code>sum</code>) the number of 1’s in <code>a</code> to determine the number of shots resulting in baskets in the current sample. The next step is to transfer the results of each trial to array <code>n_baskets</code>. We then finish the loop <span class="python">by unindenting the next line of code</span>. The final step is to search the array <code>n_baskets</code>, after the 10000 samples have been generated and <code>sum</code> the times that 3 or more baskets were made. We place the results in <code>n_more_than_2</code>, calculate the proportion in <code>propo_more_than_2</code>, and then display the result.</p>
<div id="nte-basketball_shots" 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">
Note 12.3: Notebook: Three or more basketball shots
</div>
</div>
<div class="callout-body-container callout-body">
<div class="nb-links">
<p><a class="notebook-link" href="notebooks/basketball_shots.ipynb">Download notebook</a> <a class="interact-button" href="./interact/lab/index.html?path=basketball_shots.ipynb">Interact</a></p>
</div>
</div>
</div>
<div class="nb-start" name="basketball_shots" title="Three or more basketball shots">
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>rnd <span class="op">=</span> np.random.default_rng()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>n_baskets <span class="op">=</span> np.zeros(<span class="dv">10000</span>)</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Do 10000 experimental trials.</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">10000</span>):</span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># Generate 5 random numbers, each between 1 and 4, put them in "a".</span></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># Let "1" represent a basket, "2" through "4" be a miss.</span></span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a> a <span class="op">=</span> rnd.integers(<span class="dv">1</span>, <span class="dv">5</span>, size<span class="op">=</span><span class="dv">5</span>)</span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a> <span class="co"># Count the number of baskets, put that result in b.</span></span>
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true" tabindex="-1"></a> b <span class="op">=</span> np.<span class="bu">sum</span>(a <span class="op">==</span> <span class="dv">1</span>)</span>
<span id="cb24-12"><a href="#cb24-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-13"><a href="#cb24-13" aria-hidden="true" tabindex="-1"></a> <span class="co"># Keep track of each experiment's results in z.</span></span>
<span id="cb24-14"><a href="#cb24-14" aria-hidden="true" tabindex="-1"></a> n_baskets[i] <span class="op">=</span> b</span>
<span id="cb24-15"><a href="#cb24-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-16"><a href="#cb24-16" aria-hidden="true" tabindex="-1"></a> <span class="co"># End the experiment, go back and repeat until all 10000 are completed, then</span></span>
<span id="cb24-17"><a href="#cb24-17" aria-hidden="true" tabindex="-1"></a> <span class="co"># proceed.</span></span>
<span id="cb24-18"><a href="#cb24-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-19"><a href="#cb24-19" aria-hidden="true" tabindex="-1"></a><span class="co"># Determine how many experiments produced more than two baskets, put that</span></span>
<span id="cb24-20"><a href="#cb24-20" aria-hidden="true" tabindex="-1"></a><span class="co"># result in k.</span></span>
<span id="cb24-21"><a href="#cb24-21" aria-hidden="true" tabindex="-1"></a>n_more_than_2 <span class="op">=</span> np.<span class="bu">sum</span>(n_baskets <span class="op">></span> <span class="dv">2</span>)</span>
<span id="cb24-22"><a href="#cb24-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-23"><a href="#cb24-23" aria-hidden="true" tabindex="-1"></a><span class="co"># Convert to a proportion.</span></span>
<span id="cb24-24"><a href="#cb24-24" aria-hidden="true" tabindex="-1"></a>prop_more_than_2 <span class="op">=</span> n_more_than_2 <span class="op">/</span> <span class="dv">10000</span></span>
<span id="cb24-25"><a href="#cb24-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-26"><a href="#cb24-26" aria-hidden="true" tabindex="-1"></a><span class="co"># Print the result.</span></span>
<span id="cb24-27"><a href="#cb24-27" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(prop_more_than_2)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>0.104</code></pre>
</div>
</div>
<div class="nb-end">
</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">
End of notebook: Three or more basketball shots
</div>
</div>
<div class="callout-body-container callout-body">
<p><code>basketball_shots</code> starts at <a href="#nte-basketball_shots" class="quarto-xref">Note <span>12.3</span></a>.</p>
</div>
</div>
</section>
<section id="note-to-the-student-of-analytic-probability-theory" class="level2" data-number="12.8">
<h2 data-number="12.8" class="anchored" data-anchor-id="note-to-the-student-of-analytic-probability-theory"><span class="header-section-number">12.8</span> Note to the student of analytic probability theory</h2>
<p>This problem would be done conventionally with the binomial theorem, asking about the chance of getting 3 successes in 5 trials, with the probability of a success = .25.</p>
</section>
<section id="sec-one-black-archery" class="level2" data-number="12.9">
<h2 data-number="12.9" class="anchored" data-anchor-id="sec-one-black-archery"><span class="header-section-number">12.9</span> Example: One in Black, Two in White, No Misses in Three Archery Shots</h2>
<p>This is an example of a multiple outcome (<em>multinomial</em>) sampling with unequally likely outcomes; with replacement.</p>
<p>Assume from past experience that a given archer puts 10 percent of his shots in the black (“bullseye”) and 60 percent of his shots in the white ring around the bullseye, but misses with 30 percent of his shots. How likely is it that in three shots the shooter will get exactly one bullseye, two in the white, and no misses? Notice that unlike the previous cases, in this example there are more than two outcomes for each trial.</p>
<p>This problem may be handled with a deck of three colors (or suits) of cards in proportions varying according to the probabilities of the various outcomes, and sampling with replacement. Using random numbers is simpler, however:</p>
<ul>
<li><strong>Step 1.</strong> Let “1” = “bullseye,” “2-7” = “in the white,” and “8-0” = “miss.”</li>
<li><strong>Step 2.</strong> Choose three random numbers, and examine whether there are one “1” and two numbers “2-7.” If so, record “yes,” otherwise “no.”</li>
<li><strong>Step 3.</strong> Repeat step 2 perhaps 400 times, and count the proportion of “yeses.” This estimates the probability sought.</li>
</ul>
<p>This problem would be handled in conventional probability theory with what is known as the <em>Multinomial Distribution</em>.</p>
<p>This problem may be quickly solved on the computer using Python with the notebook labeled “bullseye” below. Bullseye has a complication not found in previous problems: It tests whether two different sorts of events <em>both</em> happen — a bullseye plus two shots in the white.</p>
<p>After generating three randomly-drawn numbers between 1 and 10, we check with the <code>sum</code> function to see if there is a bullseye. If there is, the <code>if</code> statement tells the computer to continue with the operations, checking if there are two shots in the white; if there is no bullseye, the <code>if</code> statement tells the computer to end the trial and start another trial. A thousand repetitions are called for, the number of trials meeting the criteria are counted, and the results are then printed.</p>