j1-template 2022.3.1 → 2022.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/_includes/themes/j1/modules/navigator/generator.html +1 -1
  3. data/assets/data/cookieconsent.html +4 -4
  4. data/assets/data/nbinteract.html +128 -0
  5. data/assets/data/quicklinks.html +15 -0
  6. data/assets/data/translator.html +15 -15
  7. data/assets/themes/j1/adapter/js/mmenu.js +25 -3
  8. data/assets/themes/j1/adapter/js/navigator.js +2 -2
  9. data/assets/themes/j1/adapter/js/nbinteract.js +230 -34
  10. data/assets/themes/j1/core/css/themes/unolight/bootstrap.css +27 -54
  11. data/assets/themes/j1/core/css/themes/unolight/bootstrap.min.css +1 -1
  12. data/assets/themes/j1/core/js/template.js +14 -3
  13. data/assets/themes/j1/core/js/template.min.js +1 -1
  14. data/assets/themes/j1/core/js/template.min.js.map +1 -1
  15. data/assets/themes/j1/modules/nbInteract/js/nbinteract/nbinteract-core.js +1 -1
  16. data/assets/themes/j1/modules/nbInteract/js/nbinteract/nbinteract-core.js.map +1 -1
  17. data/assets/themes/j1/modules/nbInteract/js/nbinteract/nbinteract-core.min.js +1 -1
  18. data/lib/j1/version.rb +3 -3
  19. data/lib/starter_web/Gemfile +1 -1
  20. data/lib/starter_web/_config.yml +1 -1
  21. data/lib/starter_web/_data/modules/defaults/cookieconsent.yml +51 -41
  22. data/lib/starter_web/_data/modules/defaults/navigator.yml +4 -0
  23. data/lib/starter_web/_data/modules/defaults/nbinteract.yml +95 -1
  24. data/lib/starter_web/_data/modules/defaults/translator.yml +24 -12
  25. data/lib/starter_web/_plugins/lunr_index.rb +1 -1
  26. data/lib/starter_web/package.json +1 -1
  27. data/lib/starter_web/pages/public/jupyter/docs/j1-nbinteract-doc.adoc +2 -3
  28. data/lib/starter_web/pages/public/jupyter/docs/nbinteract-doc.adoc +17 -17
  29. data/lib/starter_web/pages/public/jupyter/examples/j1-circular-times-table.adoc +7 -8
  30. data/lib/starter_web/pages/public/jupyter/examples/j1-interactive-widgets.adoc +4 -5
  31. data/lib/starter_web/pages/public/jupyter/examples/j1-odes-in-python.adoc +5 -6
  32. data/lib/starter_web/pages/public/jupyter/examples/j1-testing-plotly.adoc +3 -4
  33. data/lib/starter_web/pages/public/jupyter/examples/j1_climate-change-forecast.adoc +4 -4
  34. data/lib/starter_web/pages/public/jupyter/notebooks/j1/.ipynb_checkpoints/j1_interactive_widgets-checkpoint.ipynb +26 -26
  35. data/lib/starter_web/pages/public/jupyter/notebooks/j1/j1_interactive_widgets.ipynb +26 -26
  36. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_examples_central_limit_theorem-checkpoint.ipynb +247 -0
  37. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/.ipynb_checkpoints/nbi_docs_recipes_graphing-checkpoint.ipynb +18 -18
  38. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/nbi_docs_examples_central_limit_theorem.ipynb +1 -2
  39. data/lib/starter_web/pages/public/jupyter/notebooks/nbi-docs/nbi_docs_recipes_graphing.ipynb +18 -18
  40. data/lib/starter_web/pages/public/jupyter/notebooks/textbooks/j1_interactive_widgets.html +919 -919
  41. data/lib/starter_web/pages/public/jupyter/notebooks/textbooks/nbi_docs_recipes_graphing.html +473 -473
  42. data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
  43. data/lib/starter_web/utilsrv/package.json +1 -1
  44. metadata +4 -2
@@ -41,7 +41,7 @@
41
41
  {
42
42
  "data": {
43
43
  "application/vnd.jupyter.widget-view+json": {
44
- "model_id": "1608d7a21ea54170ac685e198f887628",
44
+ "model_id": "f66db90b8e2746a5bb4ce77b8a81738b",
45
45
  "version_major": 2,
46
46
  "version_minor": 0
47
47
  },
@@ -76,7 +76,7 @@
76
76
  {
77
77
  "data": {
78
78
  "application/vnd.jupyter.widget-view+json": {
79
- "model_id": "a6be50a107e24e85a292bc6145ad6d64",
79
+ "model_id": "674a3b8585444242843a165fd36a5cc2",
80
80
  "version_major": 2,
81
81
  "version_minor": 0
82
82
  },
@@ -113,7 +113,7 @@
113
113
  {
114
114
  "data": {
115
115
  "application/vnd.jupyter.widget-view+json": {
116
- "model_id": "bba72987ae664d9c91bb7d72ea7a4ceb",
116
+ "model_id": "63e03b8837e042ffb0fb36a48d95d85d",
117
117
  "version_major": 2,
118
118
  "version_minor": 0
119
119
  },
@@ -150,7 +150,7 @@
150
150
  {
151
151
  "data": {
152
152
  "application/vnd.jupyter.widget-view+json": {
153
- "model_id": "623ff24264344afba1e0e2ddfaba3954",
153
+ "model_id": "81de367a58a445afa093b39819fdeb65",
154
154
  "version_major": 2,
155
155
  "version_minor": 0
156
156
  },
@@ -164,7 +164,7 @@
164
164
  {
165
165
  "data": {
166
166
  "application/vnd.jupyter.widget-view+json": {
167
- "model_id": "9498800ce6c645129e7a1d0d0960bbab",
167
+ "model_id": "faba020a11b44537bf1b9f74339d8d52",
168
168
  "version_major": 2,
169
169
  "version_minor": 0
170
170
  },
@@ -178,7 +178,7 @@
178
178
  {
179
179
  "data": {
180
180
  "application/vnd.jupyter.widget-view+json": {
181
- "model_id": "a85fe7587ca741c8a763f4be2e2fbce5",
181
+ "model_id": "f34cec7fb4a54934940f5d037440e9b7",
182
182
  "version_major": 2,
183
183
  "version_minor": 0
184
184
  },
@@ -192,7 +192,7 @@
192
192
  {
193
193
  "data": {
194
194
  "application/vnd.jupyter.widget-view+json": {
195
- "model_id": "0589f62cfd2b47688ff5764899459a96",
195
+ "model_id": "b8b7d85b1759460dadc5568a014d7e80",
196
196
  "version_major": 2,
197
197
  "version_minor": 0
198
198
  },
@@ -232,7 +232,7 @@
232
232
  {
233
233
  "data": {
234
234
  "application/vnd.jupyter.widget-view+json": {
235
- "model_id": "3a7017ac9a934ccd8c87cc9bba6561f0",
235
+ "model_id": "e0535be20c59454aa7529e40e0457f0e",
236
236
  "version_major": 2,
237
237
  "version_minor": 0
238
238
  },
@@ -309,7 +309,7 @@
309
309
  {
310
310
  "data": {
311
311
  "application/vnd.jupyter.widget-view+json": {
312
- "model_id": "62a37ef13bf54f0cabe1c5a75d8ad7ab",
312
+ "model_id": "1196c754303d48c8954b2ba783112516",
313
313
  "version_major": 2,
314
314
  "version_minor": 0
315
315
  },
@@ -363,7 +363,7 @@
363
363
  {
364
364
  "data": {
365
365
  "application/vnd.jupyter.widget-view+json": {
366
- "model_id": "4b422c217fb84dc7bffec5159e36071a",
366
+ "model_id": "5940507213474cf7a7a33b5e60f9d386",
367
367
  "version_major": 2,
368
368
  "version_minor": 0
369
369
  },
@@ -383,7 +383,7 @@
383
383
  " '''\n",
384
384
  " return np.random.normal(loc=mean, scale=sd, size=1000)\n",
385
385
  "\n",
386
- "nbi.hist(hist_response_function, mean=(0, 10), sd=(0, 2.0, 0.2))"
386
+ "nbi.hist(hist_response_function, mean=(0, 10), sd=(0.2, 2.0, 0.2))"
387
387
  ]
388
388
  },
389
389
  {
@@ -401,18 +401,18 @@
401
401
  },
402
402
  {
403
403
  "cell_type": "code",
404
- "execution_count": 9,
404
+ "execution_count": 18,
405
405
  "metadata": {},
406
406
  "outputs": [
407
407
  {
408
408
  "data": {
409
409
  "application/vnd.jupyter.widget-view+json": {
410
- "model_id": "dce293ca5d6f40878190033fd4bacb44",
410
+ "model_id": "467a66b0b3ba4036ae7ff52caea9af3c",
411
411
  "version_major": 2,
412
412
  "version_minor": 0
413
413
  },
414
414
  "text/plain": [
415
- "VBox(children=(interactive(children=(IntSlider(value=5, description='n', max=10), IntSlider(value=5, descripti…"
415
+ "VBox(children=(interactive(children=(IntSlider(value=6, description='n', max=10, min=3), IntSlider(value=5, de…"
416
416
  ]
417
417
  },
418
418
  "metadata": {},
@@ -430,7 +430,7 @@
430
430
  " 'ylim': (0, 20),\n",
431
431
  "}\n",
432
432
  "\n",
433
- "nbi.bar(categories, heights, n=(0, 10), offset=(1, 10), options=opts)"
433
+ "nbi.bar(categories, heights, n=(3, 10), offset=(1, 10), options=opts)"
434
434
  ]
435
435
  },
436
436
  {
@@ -454,12 +454,12 @@
454
454
  {
455
455
  "data": {
456
456
  "application/vnd.jupyter.widget-view+json": {
457
- "model_id": "85d808e150a84179a61f5f24324eb233",
457
+ "model_id": "40dc861f38114d0589514725ce5062e3",
458
458
  "version_major": 2,
459
459
  "version_minor": 0
460
460
  },
461
461
  "text/plain": [
462
- "VBox(children=(Label(value='y = 1.03x + 0.36'), Figure(animation_duration=250, axes=[Axis(scale=LinearScale(ma…"
462
+ "VBox(children=(Label(value='y = 1.03x + 0.44'), Figure(animation_duration=250, axes=[Axis(scale=LinearScale(ma…"
463
463
  ]
464
464
  },
465
465
  "metadata": {},
@@ -494,12 +494,12 @@
494
494
  {
495
495
  "data": {
496
496
  "application/vnd.jupyter.widget-view+json": {
497
- "model_id": "b9ab17c9bcb4453e96247d1c3b5376b0",
497
+ "model_id": "4bee645a8f074735b3a76d7611a7ec01",
498
498
  "version_major": 2,
499
499
  "version_minor": 0
500
500
  },
501
501
  "text/plain": [
502
- "VBox(children=(interactive(children=(IntSlider(value=100, description='n', max=200), Output()), _dom_classes=(…"
502
+ "VBox(children=(interactive(children=(IntSlider(value=105, description='n', max=200, min=10), Output()), _dom_c…"
503
503
  ]
504
504
  },
505
505
  "metadata": {},
@@ -510,7 +510,7 @@
510
510
  "def x_values(n): return np.random.choice(100, n)\n",
511
511
  "def y_values(xs): return np.random.choice(100, len(xs))\n",
512
512
  "\n",
513
- "nbi.scatter(x_values, y_values, n=(0,200))"
513
+ "nbi.scatter(x_values, y_values, n=(10,200))"
514
514
  ]
515
515
  },
516
516
  {
@@ -532,7 +532,7 @@
532
532
  {
533
533
  "data": {
534
534
  "application/vnd.jupyter.widget-view+json": {
535
- "model_id": "1acc67b93a504dd68052f4f789977417",
535
+ "model_id": "e86bedcd6aa34fd99f7701ac7ea07efb",
536
536
  "version_major": 2,
537
537
  "version_minor": 0
538
538
  },
@@ -583,7 +583,7 @@
583
583
  {
584
584
  "data": {
585
585
  "application/vnd.jupyter.widget-view+json": {
586
- "model_id": "69125fc46e0a4ef98151a9a233699094",
586
+ "model_id": "d9f2357911f64e08bfd63b97e5f34b7b",
587
587
  "version_major": 2,
588
588
  "version_minor": 0
589
589
  },
@@ -611,7 +611,7 @@
611
611
  {
612
612
  "data": {
613
613
  "application/vnd.jupyter.widget-view+json": {
614
- "model_id": "7579a202c6124ff9b054ea2398505fa0",
614
+ "model_id": "bb9674fe94b0491f83de231ff76bc149",
615
615
  "version_major": 2,
616
616
  "version_minor": 0
617
617
  },
@@ -648,7 +648,7 @@
648
648
  {
649
649
  "data": {
650
650
  "application/vnd.jupyter.widget-view+json": {
651
- "model_id": "05e3ccd2d1254beab1511943bec50d2c",
651
+ "model_id": "c488ca7374b0478bb5db7f877738df78",
652
652
  "version_major": 2,
653
653
  "version_minor": 0
654
654
  },
@@ -672,7 +672,7 @@
672
672
  {
673
673
  "data": {
674
674
  "application/vnd.jupyter.widget-view+json": {
675
- "model_id": "4a1cd24a4d61497f82e0a58f51c84409",
675
+ "model_id": "8f9315d5c2fc4a9b9e1ca7c6e4433341",
676
676
  "version_major": 2,
677
677
  "version_minor": 0
678
678
  },
@@ -697,7 +697,7 @@
697
697
  {
698
698
  "data": {
699
699
  "application/vnd.jupyter.widget-view+json": {
700
- "model_id": "d4b70f05b0234029861de4fc50bd3aef",
700
+ "model_id": "b0bbe10d65cc485294295b94e6fab3a6",
701
701
  "version_major": 2,
702
702
  "version_minor": 0
703
703
  },
@@ -41,7 +41,7 @@
41
41
  {
42
42
  "data": {
43
43
  "application/vnd.jupyter.widget-view+json": {
44
- "model_id": "1608d7a21ea54170ac685e198f887628",
44
+ "model_id": "f66db90b8e2746a5bb4ce77b8a81738b",
45
45
  "version_major": 2,
46
46
  "version_minor": 0
47
47
  },
@@ -76,7 +76,7 @@
76
76
  {
77
77
  "data": {
78
78
  "application/vnd.jupyter.widget-view+json": {
79
- "model_id": "a6be50a107e24e85a292bc6145ad6d64",
79
+ "model_id": "674a3b8585444242843a165fd36a5cc2",
80
80
  "version_major": 2,
81
81
  "version_minor": 0
82
82
  },
@@ -113,7 +113,7 @@
113
113
  {
114
114
  "data": {
115
115
  "application/vnd.jupyter.widget-view+json": {
116
- "model_id": "bba72987ae664d9c91bb7d72ea7a4ceb",
116
+ "model_id": "63e03b8837e042ffb0fb36a48d95d85d",
117
117
  "version_major": 2,
118
118
  "version_minor": 0
119
119
  },
@@ -150,7 +150,7 @@
150
150
  {
151
151
  "data": {
152
152
  "application/vnd.jupyter.widget-view+json": {
153
- "model_id": "623ff24264344afba1e0e2ddfaba3954",
153
+ "model_id": "81de367a58a445afa093b39819fdeb65",
154
154
  "version_major": 2,
155
155
  "version_minor": 0
156
156
  },
@@ -164,7 +164,7 @@
164
164
  {
165
165
  "data": {
166
166
  "application/vnd.jupyter.widget-view+json": {
167
- "model_id": "9498800ce6c645129e7a1d0d0960bbab",
167
+ "model_id": "faba020a11b44537bf1b9f74339d8d52",
168
168
  "version_major": 2,
169
169
  "version_minor": 0
170
170
  },
@@ -178,7 +178,7 @@
178
178
  {
179
179
  "data": {
180
180
  "application/vnd.jupyter.widget-view+json": {
181
- "model_id": "a85fe7587ca741c8a763f4be2e2fbce5",
181
+ "model_id": "f34cec7fb4a54934940f5d037440e9b7",
182
182
  "version_major": 2,
183
183
  "version_minor": 0
184
184
  },
@@ -192,7 +192,7 @@
192
192
  {
193
193
  "data": {
194
194
  "application/vnd.jupyter.widget-view+json": {
195
- "model_id": "0589f62cfd2b47688ff5764899459a96",
195
+ "model_id": "b8b7d85b1759460dadc5568a014d7e80",
196
196
  "version_major": 2,
197
197
  "version_minor": 0
198
198
  },
@@ -232,7 +232,7 @@
232
232
  {
233
233
  "data": {
234
234
  "application/vnd.jupyter.widget-view+json": {
235
- "model_id": "3a7017ac9a934ccd8c87cc9bba6561f0",
235
+ "model_id": "e0535be20c59454aa7529e40e0457f0e",
236
236
  "version_major": 2,
237
237
  "version_minor": 0
238
238
  },
@@ -309,7 +309,7 @@
309
309
  {
310
310
  "data": {
311
311
  "application/vnd.jupyter.widget-view+json": {
312
- "model_id": "62a37ef13bf54f0cabe1c5a75d8ad7ab",
312
+ "model_id": "1196c754303d48c8954b2ba783112516",
313
313
  "version_major": 2,
314
314
  "version_minor": 0
315
315
  },
@@ -363,7 +363,7 @@
363
363
  {
364
364
  "data": {
365
365
  "application/vnd.jupyter.widget-view+json": {
366
- "model_id": "4b422c217fb84dc7bffec5159e36071a",
366
+ "model_id": "5940507213474cf7a7a33b5e60f9d386",
367
367
  "version_major": 2,
368
368
  "version_minor": 0
369
369
  },
@@ -383,7 +383,7 @@
383
383
  " '''\n",
384
384
  " return np.random.normal(loc=mean, scale=sd, size=1000)\n",
385
385
  "\n",
386
- "nbi.hist(hist_response_function, mean=(0, 10), sd=(0, 2.0, 0.2))"
386
+ "nbi.hist(hist_response_function, mean=(0, 10), sd=(0.2, 2.0, 0.2))"
387
387
  ]
388
388
  },
389
389
  {
@@ -401,18 +401,18 @@
401
401
  },
402
402
  {
403
403
  "cell_type": "code",
404
- "execution_count": 9,
404
+ "execution_count": 18,
405
405
  "metadata": {},
406
406
  "outputs": [
407
407
  {
408
408
  "data": {
409
409
  "application/vnd.jupyter.widget-view+json": {
410
- "model_id": "dce293ca5d6f40878190033fd4bacb44",
410
+ "model_id": "467a66b0b3ba4036ae7ff52caea9af3c",
411
411
  "version_major": 2,
412
412
  "version_minor": 0
413
413
  },
414
414
  "text/plain": [
415
- "VBox(children=(interactive(children=(IntSlider(value=5, description='n', max=10), IntSlider(value=5, descripti…"
415
+ "VBox(children=(interactive(children=(IntSlider(value=6, description='n', max=10, min=3), IntSlider(value=5, de…"
416
416
  ]
417
417
  },
418
418
  "metadata": {},
@@ -430,7 +430,7 @@
430
430
  " 'ylim': (0, 20),\n",
431
431
  "}\n",
432
432
  "\n",
433
- "nbi.bar(categories, heights, n=(0, 10), offset=(1, 10), options=opts)"
433
+ "nbi.bar(categories, heights, n=(3, 10), offset=(1, 10), options=opts)"
434
434
  ]
435
435
  },
436
436
  {
@@ -454,12 +454,12 @@
454
454
  {
455
455
  "data": {
456
456
  "application/vnd.jupyter.widget-view+json": {
457
- "model_id": "85d808e150a84179a61f5f24324eb233",
457
+ "model_id": "40dc861f38114d0589514725ce5062e3",
458
458
  "version_major": 2,
459
459
  "version_minor": 0
460
460
  },
461
461
  "text/plain": [
462
- "VBox(children=(Label(value='y = 1.03x + 0.36'), Figure(animation_duration=250, axes=[Axis(scale=LinearScale(ma…"
462
+ "VBox(children=(Label(value='y = 1.03x + 0.44'), Figure(animation_duration=250, axes=[Axis(scale=LinearScale(ma…"
463
463
  ]
464
464
  },
465
465
  "metadata": {},
@@ -494,12 +494,12 @@
494
494
  {
495
495
  "data": {
496
496
  "application/vnd.jupyter.widget-view+json": {
497
- "model_id": "b9ab17c9bcb4453e96247d1c3b5376b0",
497
+ "model_id": "4bee645a8f074735b3a76d7611a7ec01",
498
498
  "version_major": 2,
499
499
  "version_minor": 0
500
500
  },
501
501
  "text/plain": [
502
- "VBox(children=(interactive(children=(IntSlider(value=100, description='n', max=200), Output()), _dom_classes=(…"
502
+ "VBox(children=(interactive(children=(IntSlider(value=105, description='n', max=200, min=10), Output()), _dom_c…"
503
503
  ]
504
504
  },
505
505
  "metadata": {},
@@ -510,7 +510,7 @@
510
510
  "def x_values(n): return np.random.choice(100, n)\n",
511
511
  "def y_values(xs): return np.random.choice(100, len(xs))\n",
512
512
  "\n",
513
- "nbi.scatter(x_values, y_values, n=(0,200))"
513
+ "nbi.scatter(x_values, y_values, n=(10,200))"
514
514
  ]
515
515
  },
516
516
  {
@@ -532,7 +532,7 @@
532
532
  {
533
533
  "data": {
534
534
  "application/vnd.jupyter.widget-view+json": {
535
- "model_id": "1acc67b93a504dd68052f4f789977417",
535
+ "model_id": "e86bedcd6aa34fd99f7701ac7ea07efb",
536
536
  "version_major": 2,
537
537
  "version_minor": 0
538
538
  },
@@ -583,7 +583,7 @@
583
583
  {
584
584
  "data": {
585
585
  "application/vnd.jupyter.widget-view+json": {
586
- "model_id": "69125fc46e0a4ef98151a9a233699094",
586
+ "model_id": "d9f2357911f64e08bfd63b97e5f34b7b",
587
587
  "version_major": 2,
588
588
  "version_minor": 0
589
589
  },
@@ -611,7 +611,7 @@
611
611
  {
612
612
  "data": {
613
613
  "application/vnd.jupyter.widget-view+json": {
614
- "model_id": "7579a202c6124ff9b054ea2398505fa0",
614
+ "model_id": "bb9674fe94b0491f83de231ff76bc149",
615
615
  "version_major": 2,
616
616
  "version_minor": 0
617
617
  },
@@ -648,7 +648,7 @@
648
648
  {
649
649
  "data": {
650
650
  "application/vnd.jupyter.widget-view+json": {
651
- "model_id": "05e3ccd2d1254beab1511943bec50d2c",
651
+ "model_id": "c488ca7374b0478bb5db7f877738df78",
652
652
  "version_major": 2,
653
653
  "version_minor": 0
654
654
  },
@@ -672,7 +672,7 @@
672
672
  {
673
673
  "data": {
674
674
  "application/vnd.jupyter.widget-view+json": {
675
- "model_id": "4a1cd24a4d61497f82e0a58f51c84409",
675
+ "model_id": "8f9315d5c2fc4a9b9e1ca7c6e4433341",
676
676
  "version_major": 2,
677
677
  "version_minor": 0
678
678
  },
@@ -697,7 +697,7 @@
697
697
  {
698
698
  "data": {
699
699
  "application/vnd.jupyter.widget-view+json": {
700
- "model_id": "d4b70f05b0234029861de4fc50bd3aef",
700
+ "model_id": "b0bbe10d65cc485294295b94e6fab3a6",
701
701
  "version_major": 2,
702
702
  "version_minor": 0
703
703
  },
@@ -0,0 +1,247 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# HIDDEN\n",
10
+ "from datascience import *\n",
11
+ "%matplotlib inline\n",
12
+ "import matplotlib.pyplot as plots\n",
13
+ "plots.style.use('fivethirtyeight')\n",
14
+ "import math\n",
15
+ "import numpy as np\n",
16
+ "from scipy import stats\n",
17
+ "import ipywidgets as widgets\n",
18
+ "import nbinteract as nbi"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "markdown",
23
+ "metadata": {},
24
+ "source": [
25
+ "### The Central Limit Theorem\n",
26
+ "Very few of the data histograms that we have seen in this course have been bell shaped.\n",
27
+ "When we have come across a bell shaped distribution, it has almost invariably been an\n",
28
+ "empirical histogram of a statistic based on a random sample.\n"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "markdown",
33
+ "metadata": {},
34
+ "source": [
35
+ "**The Central Limit Theorem says that the probability distribution of the sum or average of a large random sample drawn with replacement will be roughly normal, *regardless of the distribution of the population from which the sample is drawn*.**\n",
36
+ "\n",
37
+ "As we noted when we were studying Chebychev's bounds, results that can be applied to random samples *regardless of the distribution of the population* are very powerful, because in data science we rarely know the distribution of the population.\n",
38
+ "\n",
39
+ "The Central Limit Theorem makes it possible to make inferences with very little knowledge about the population, provided we have a large random sample. That is why it is central to the field of statistical inference."
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "markdown",
44
+ "metadata": {},
45
+ "source": [
46
+ "#### Proportion of Purple Flowers\n",
47
+ "\n",
48
+ "Recall Mendel's probability model for the colors of the flowers of a species of pea plant. The model says that the flower colors of the plants are like draws made at random with replacement from {Purple, Purple, Purple, White}.\n",
49
+ "\n",
50
+ "In a large sample of plants, about what proportion will have purple flowers? We would expect the answer to be about 0.75, the proportion purple in the model. And, because proportions are means, the Central Limit Theorem says that the distribution of the sample proportion of purple plants is roughly normal.\n",
51
+ "\n",
52
+ "We can confirm this by simulation. Let's simulate the proportion of purple-flowered plants in a sample of 200 plants."
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 2,
58
+ "metadata": {},
59
+ "outputs": [
60
+ {
61
+ "data": {
62
+ "text/html": [
63
+ "<table border=\"1\" class=\"dataframe\">\n",
64
+ " <thead>\n",
65
+ " <tr>\n",
66
+ " <th>Color</th>\n",
67
+ " </tr>\n",
68
+ " </thead>\n",
69
+ " <tbody>\n",
70
+ " <tr>\n",
71
+ " <td>Purple</td>\n",
72
+ " </tr>\n",
73
+ " <tr>\n",
74
+ " <td>Purple</td>\n",
75
+ " </tr>\n",
76
+ " <tr>\n",
77
+ " <td>Purple</td>\n",
78
+ " </tr>\n",
79
+ " <tr>\n",
80
+ " <td>White </td>\n",
81
+ " </tr>\n",
82
+ " </tbody>\n",
83
+ "</table>"
84
+ ],
85
+ "text/plain": [
86
+ "Color\n",
87
+ "Purple\n",
88
+ "Purple\n",
89
+ "Purple\n",
90
+ "White"
91
+ ]
92
+ },
93
+ "execution_count": 2,
94
+ "metadata": {},
95
+ "output_type": "execute_result"
96
+ }
97
+ ],
98
+ "source": [
99
+ "colors = make_array('Purple', 'Purple', 'Purple', 'White')\n",
100
+ "\n",
101
+ "model = Table().with_column('Color', colors)\n",
102
+ "\n",
103
+ "model"
104
+ ]
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "execution_count": 3,
109
+ "metadata": {},
110
+ "outputs": [
111
+ {
112
+ "data": {
113
+ "text/plain": [
114
+ "array([0.765, 0.695, 0.69 , 0.76 , 0.78 ])"
115
+ ]
116
+ },
117
+ "execution_count": 3,
118
+ "metadata": {},
119
+ "output_type": "execute_result"
120
+ }
121
+ ],
122
+ "source": [
123
+ "props = make_array()\n",
124
+ "\n",
125
+ "num_plants = 200\n",
126
+ "repetitions = 1000\n",
127
+ "\n",
128
+ "for i in np.arange(repetitions):\n",
129
+ " sample = model.sample(num_plants)\n",
130
+ " new_prop = np.count_nonzero(sample.column('Color') == 'Purple')/num_plants\n",
131
+ " props = np.append(props, new_prop)\n",
132
+ "props[:5]"
133
+ ]
134
+ },
135
+ {
136
+ "cell_type": "code",
137
+ "execution_count": 4,
138
+ "metadata": {},
139
+ "outputs": [
140
+ {
141
+ "data": {
142
+ "application/vnd.jupyter.widget-view+json": {
143
+ "model_id": "67c0c138c5c846efba2c9e32338801d0",
144
+ "version_major": 2,
145
+ "version_minor": 0
146
+ },
147
+ "text/plain": [
148
+ "VBox(children=(interactive(children=(Output(),), _dom_classes=('widget-interact',)), Figure(axes=[Axis(label='…"
149
+ ]
150
+ },
151
+ "metadata": {},
152
+ "output_type": "display_data"
153
+ }
154
+ ],
155
+ "source": [
156
+ "opts = {\n",
157
+ " 'title': 'Distribution of sample proportions',\n",
158
+ " 'xlabel': 'Sample Proportion',\n",
159
+ " 'ylabel': 'Percent per unit',\n",
160
+ " 'xlim': (0.64, 0.84),\n",
161
+ " 'ylim': (0, 25),\n",
162
+ " 'bins': 20,\n",
163
+ "}\n",
164
+ "nbi.hist(props, options=opts)"
165
+ ]
166
+ },
167
+ {
168
+ "cell_type": "markdown",
169
+ "metadata": {},
170
+ "source": [
171
+ "There's that normal curve again, as predicted by the Central Limit Theorem, centered at around 0.75 just as you would expect.\n",
172
+ "\n",
173
+ "How would this distribution change if we increased the sample size? We can copy our sampling code into a function and then use interaction to see how the distribution changes as the sample size increases.\n",
174
+ "\n",
175
+ "We will keep the number of `repetitions` the same as before so that the two columns have the same length."
176
+ ]
177
+ },
178
+ {
179
+ "cell_type": "code",
180
+ "execution_count": 5,
181
+ "metadata": {},
182
+ "outputs": [],
183
+ "source": [
184
+ "def empirical_props(num_plants):\n",
185
+ " props = make_array()\n",
186
+ " for i in np.arange(repetitions):\n",
187
+ " sample = model.sample(num_plants)\n",
188
+ " new_prop = np.count_nonzero(sample.column('Color') == 'Purple')/num_plants\n",
189
+ " props = np.append(props, new_prop)\n",
190
+ " return props"
191
+ ]
192
+ },
193
+ {
194
+ "cell_type": "code",
195
+ "execution_count": 6,
196
+ "metadata": {},
197
+ "outputs": [
198
+ {
199
+ "data": {
200
+ "application/vnd.jupyter.widget-view+json": {
201
+ "model_id": "539198ed74234f20ac5d449a617305f8",
202
+ "version_major": 2,
203
+ "version_minor": 0
204
+ },
205
+ "text/plain": [
206
+ "VBox(children=(interactive(children=(ToggleButtons(description='num_plants', options=(100, 200, 400, 800), val…"
207
+ ]
208
+ },
209
+ "metadata": {},
210
+ "output_type": "display_data"
211
+ }
212
+ ],
213
+ "source": [
214
+ "nbi.hist(empirical_props, options=opts,\n",
215
+ " num_plants=widgets.ToggleButtons(options=[100, 200, 400, 800]))"
216
+ ]
217
+ },
218
+ {
219
+ "cell_type": "markdown",
220
+ "metadata": {},
221
+ "source": [
222
+ "All of the above distributions are approximately normal but become more narrow as the sample size increases. For example, the proportions based on a sample size of 800 are more tightly clustered around 0.75 than those from a sample size of 200. Increasing the sample size has decreased the variability in the sample proportion."
223
+ ]
224
+ }
225
+ ],
226
+ "metadata": {
227
+ "kernelspec": {
228
+ "display_name": "Python 3",
229
+ "language": "python",
230
+ "name": "python3"
231
+ },
232
+ "language_info": {
233
+ "codemirror_mode": {
234
+ "name": "ipython",
235
+ "version": 3
236
+ },
237
+ "file_extension": ".py",
238
+ "mimetype": "text/x-python",
239
+ "name": "python",
240
+ "nbconvert_exporter": "python",
241
+ "pygments_lexer": "ipython3",
242
+ "version": "3.7.9"
243
+ }
244
+ },
245
+ "nbformat": 4,
246
+ "nbformat_minor": 1
247
+ }