-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBayesian-Statistics-in-R.html
More file actions
1639 lines (1480 loc) · 208 KB
/
Bayesian-Statistics-in-R.html
File metadata and controls
1639 lines (1480 loc) · 208 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bayesian Statistics in R: Build Genuine Intuition Before Opening Stan or brms</title>
<meta charset="utf-8">
<meta name="Description" content="Bayesian statistics in R from scratch: simulate the prior-likelihood-posterior update, watch a wrong prior get washed out by data, then bridge to MCMC.">
<meta name="Keywords" content="Bayesian statistics R, prior likelihood posterior, Beta-Binomial conjugate, posterior simulation, credible interval, Bayesian inference, prior distribution, posterior distribution, grid approximation, MCMC introduction">
<meta name="Distribution" content="Global">
<meta name="Author" content="Selva Prabhakaran">
<meta name="Robots" content="index, follow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="strict-origin-when-cross-origin">
<link rel="icon" href="/screenshots/iconb-64.png" type="image/x-icon" />
<link rel="canonical" href="https://r-statistics.co/Bayesian-Statistics-in-R.html">
<link rel="alternate" type="application/atom+xml" title="r-statistics.co" href="https://r-statistics.co/feed.xml">
<link rel="preconnect" href="https://cdn.jsdelivr.net">
<!-- Preload the primary body font so first paint has IBM Plex Sans ready -->
<link rel="preload" href="/www/fonts/ibm-plex/ibm-plex-sans-latin.woff2" as="font" type="font/woff2" crossorigin>
<!-- Preload heading font (IBM Plex Serif 700) to prevent H1 font swap -->
<link rel="preload" href="/www/fonts/ibm-plex/ibm-plex-serif-700.woff2" as="font" type="font/woff2" crossorigin>
<!-- Critical CSS inlined for fast first paint -->
<style>
@font-face{font-family:'IBM Plex Sans';font-style:normal;font-weight:400;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-sans-latin.woff2') format('woff2')}
@font-face{font-family:'IBM Plex Sans';font-style:normal;font-weight:500;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-sans-latin.woff2') format('woff2')}
@font-face{font-family:'IBM Plex Sans';font-style:normal;font-weight:600;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-sans-latin.woff2') format('woff2')}
@font-face{font-family:'IBM Plex Sans';font-style:normal;font-weight:700;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-sans-latin.woff2') format('woff2')}
@font-face{font-family:'IBM Plex Serif';font-style:normal;font-weight:600;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-serif-600.woff2') format('woff2')}
@font-face{font-family:'IBM Plex Serif';font-style:normal;font-weight:700;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-serif-700.woff2') format('woff2')}
@font-face{font-family:'IBM Plex Mono';font-style:normal;font-weight:400;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-mono-400.woff2') format('woff2')}
@font-face{font-family:'IBM Plex Mono';font-style:normal;font-weight:500;font-display:optional;src:url('/www/fonts/ibm-plex/ibm-plex-mono-500.woff2') format('woff2')}
*,*::before,*::after{box-sizing:border-box}
html{font-family:sans-serif;-webkit-text-size-adjust:100%}
body{margin:0;font-family:'IBM Plex Sans',-apple-system,BlinkMacSystemFont,sans-serif;font-size:18px;line-height:1.7;color:#0d1117;background:#fafbfc}
html body{font-size:18px;line-height:1.7}
p{margin:0 0 15px}
.container{max-width:1170px;margin:0 auto;padding:0 15px}
@media(min-width:1200px){.container{width:1170px}}
.row{margin-left:-15px;margin-right:-15px}.row::after{content:"";display:table;clear:both}
.col-xs-12,.col-sm-2,.col-sm-3,.col-sm-7{position:relative;min-height:1px;padding-left:15px;padding-right:15px;float:left}
.col-xs-12{width:100%}
@media(min-width:768px){.col-sm-2{width:16.667%}.col-sm-3{width:25%}.col-sm-7{width:58.333%}.hidden-xs{display:block!important}}
.hidden-xs{display:none}
.table{width:100%;border-collapse:collapse}.table>thead>tr>th,.table>tbody>tr>td{padding:8px;border-top:1px solid #ddd}
.table-striped>tbody>tr:nth-of-type(odd){background:#f9f9f9}
.btn{display:inline-block;padding:6px 12px;font-size:14px;border-radius:4px;cursor:pointer;border:1px solid transparent}
.btn-primary{color:#fff;background:#1d3158;border-color:#1d3158}.btn-primary:hover{background:#2c4574}
.btn-default{color:#333;background:#fff;border-color:#ccc}
.btn-sm{padding:3px 10px;font-size:12px}
.form-control{display:block;padding:6px 12px;font-size:14px;border:1px solid #ccc;border-radius:4px}
.list-unstyled{list-style:none;padding-left:0}
.img-responsive{max-width:100%;height:auto}
.pull-right{float:right}
a{color:#1d3158;text-decoration:none}a:hover{text-decoration:underline}
html,body{overflow-x:hidden;max-width:100vw}
#sidebar-nav{position:sticky;top:20px;max-height:calc(100vh - 40px);overflow-y:auto;padding:8px 0}
.breadcrumb-nav{font-size:13.5px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:#6c757d;margin-bottom:2px;padding:0}
.breadcrumb-nav a{color:#6c757d;text-decoration:none}
.bc-sep,.breadcrumb-sep{margin:0 5px;color:#757575}
.bc-current,.breadcrumb-current{color:#495057;font-weight:500}
#content h1,#content h2,#content h3,#content h4{font-family:'IBM Plex Serif',Georgia,'Times New Roman',serif}
#content h1{font-weight:700;font-size:2.1em;line-height:1.2;margin:0 0 0.4em 0;letter-spacing:-0.01em;color:#0d1117}
#content h2{font-weight:600;font-size:1.65em;line-height:1.25;margin:2.5em 0 0.6em 0;color:#0d1117;padding-top:0.8em;padding-bottom:6px;border-top:1px solid #d8dce2}
#content h2:first-of-type{border-top:none;margin-top:1.5em}
#content p{line-height:1.75;margin-bottom:1.15em;color:#0d1117}
p.lead{font-size:1.1em;line-height:1.75;color:#4a5160;font-weight:400;border-left:3px solid #1d3158;padding-left:1em;margin:-4px 0 1.15em 0}
.site-masthead{position:sticky;top:0;z-index:30;background:rgba(250,251,252,0.92);backdrop-filter:saturate(160%) blur(14px);border-bottom:1px solid transparent;margin:0 -15px 24px;transition:border-color 0.2s}
.site-masthead.scrolled{border-bottom-color:#d8dce2}
.site-masthead-inner{max-width:1170px;margin:0 auto;padding:14px 28px;display:flex;align-items:center;gap:24px}
.masthead-menu-btn{display:none;background:none;border:1px solid #d8dce2;border-radius:6px;padding:4px 8px;font-size:18px;line-height:1;color:#4a5160;cursor:pointer}
.masthead-wordmark{display:inline-flex;align-items:center;gap:10px;font-family:'IBM Plex Mono',monospace;font-weight:600;font-size:15px;color:#0d1117;text-decoration:none;white-space:nowrap}
.masthead-mark{position:relative;width:32px;height:32px;border-radius:6px;background:#1d3158;color:#fff;display:inline-flex;align-items:center;justify-content:center;font-family:'IBM Plex Serif',Georgia,serif;font-style:italic;font-weight:700;font-size:19px;line-height:1;letter-spacing:-0.04em;padding-right:1px;box-shadow:0 1px 2px rgba(13,17,23,0.08),inset 0 1px 0 rgba(255,255,255,0.12)}
.masthead-mark::after{content:'';position:absolute;right:5px;bottom:5px;width:4px;height:4px;border-radius:50%;background:rgba(255,255,255,0.85)}
.masthead-tld{color:#757a87}
.masthead-nav{display:flex;gap:4px;flex:1;margin-left:8px}
.masthead-nav-link{font-family:'IBM Plex Sans',sans-serif;color:#4a5160;font-size:14px;font-weight:500;padding:6px 12px;border-radius:6px;text-decoration:none;transition:all 0.15s}
.masthead-nav-link:hover{background:#f1f3f6;color:#0d1117;text-decoration:none}
.masthead-nav-link.active{background:#f1f3f6;color:#0d1117}
.masthead-tools{display:flex;align-items:center;gap:10px;flex-shrink:0}
.masthead-search{margin:0;display:flex;align-items:center}
.masthead-search input{height:32px;padding:6px 12px;font-size:13px;border:1px solid #d8dce2;border-radius:6px;background:#fff;color:#0d1117;width:160px;font-family:'IBM Plex Sans',sans-serif;transition:border-color 0.15s,box-shadow 0.15s}
.masthead-search input:focus{outline:none;border-color:#1d3158;box-shadow:0 0 0 3px rgba(29,49,88,0.10)}
.masthead-icon-btn{background:none;border:1px solid transparent;border-radius:6px;width:32px;height:32px;display:inline-flex;align-items:center;justify-content:center;font-size:14px;color:#4a5160;cursor:pointer;transition:all 0.15s}
.masthead-icon-btn:hover{background:#f1f3f6;color:#0d1117}
html.dark .site-masthead{background:rgba(12,13,16,0.85)}
html.dark .site-masthead.scrolled{border-bottom-color:#262a31}
html.dark .masthead-wordmark{color:#e8eaee}
html.dark .masthead-tld{color:#6e7382}
html.dark .masthead-mark{background:#92a4d8}
html.dark .masthead-nav-link{color:#b0b5bf}
html.dark .masthead-nav-link:hover,html.dark .masthead-nav-link.active{background:#1a1d22;color:#e8eaee}
.nav-dropdown{position:relative;display:inline-block}
.nav-dropdown-trigger{cursor:pointer}
.nav-dropdown-trigger::after{content:' \25BE';font-size:10px;color:#8a8f99}
.nav-dropdown-panel{display:none;position:absolute;top:calc(100% + 6px);left:0;background:#fff;border:1px solid #e5e7eb;border-radius:8px;padding:14px 0;box-shadow:0 8px 24px rgba(13,17,23,0.10);min-width:260px;z-index:40;flex-direction:column}
.nav-dropdown:hover .nav-dropdown-panel,.nav-dropdown.open .nav-dropdown-panel{display:flex}
.nav-cat{position:relative;display:flex;align-items:center;justify-content:space-between;padding:7px 18px;font-family:'IBM Plex Sans',sans-serif;font-size:13px;font-weight:500;color:#3a3f4a;cursor:pointer;transition:background 0.1s}
.nav-cat:hover{background:#f1f3f6;color:#0d1117}
.nav-cat::after{content:' \25B8';font-size:10px;color:#8a8f99;margin-left:8px}
.nav-sub{display:none;position:absolute;top:0;left:100%;background:#fff;border:1px solid #e5e7eb;border-radius:8px;padding:14px 18px;box-shadow:0 8px 24px rgba(13,17,23,0.10);min-width:230px;z-index:50}
.nav-cat:hover .nav-sub{display:block}
.nav-sub a{display:block;padding:5px 0;font-size:13px;color:#3a3f4a;text-decoration:none;font-weight:400;line-height:1.4}
.nav-sub a:hover{color:#1d3158;text-decoration:underline}
.nav-sub h6{margin:10px 0 4px;font-family:'IBM Plex Sans',sans-serif;font-size:10px;font-weight:600;color:#8a8f99;text-transform:uppercase;letter-spacing:0.06em}
.nav-sub h6:first-child{margin-top:0}
html.dark .nav-dropdown-panel,html.dark .nav-sub{background:#161a1f;border-color:#2a2e35;box-shadow:0 8px 24px rgba(0,0,0,0.45)}
html.dark .nav-cat{color:#c5cad3}
html.dark .nav-cat:hover{background:#1a1d22;color:#fff}
html.dark .nav-sub a{color:#c5cad3}
html.dark .nav-sub a:hover{color:#fff}
html.dark .nav-sub h6{color:#7a808c}
@media (max-width: 768px){.nav-dropdown-panel{min-width:220px;left:auto;right:0}.nav-sub{position:static;border:none;box-shadow:none;padding:6px 0 6px 16px}.nav-cat::after{content:''}}
html.dark .masthead-search input{background:#14161a;border-color:#262a31;color:#e8eaee}
html.dark .masthead-search input:focus{border-color:#92a4d8;box-shadow:0 0 0 3px rgba(146,164,216,0.15)}
html.dark .masthead-icon-btn{color:#b0b5bf}
html.dark .masthead-icon-btn:hover{background:#1a1d22;color:#e8eaee}
hr{height:0;box-sizing:content-box;border:0;border-top:1px solid #eee}
.img-zoomable{cursor:zoom-in;transition:opacity .15s}
.img-lightbox{display:none;position:fixed;top:0;left:0;right:0;bottom:0;z-index:10001;background:rgba(0,0,0,.85);cursor:zoom-out;align-items:center;justify-content:center}
.img-lightbox.open{display:flex}
.img-lightbox img{max-width:95vw;max-height:95vh;border-radius:4px;box-shadow:0 4px 24px rgba(0,0,0,.4)}
/* CLS prevention: sidebar component styles (match main.css final state) */
.sidebar-menu{margin:0;padding:0}
.sidebar-tabs{display:flex;gap:0;margin:4px 0 0;border-bottom:1px solid #d8dce2}
.sidebar-tab{flex:1;padding:9px 12px 8px;border:none;background:transparent;font:600 13px 'IBM Plex Sans',sans-serif;color:#757a87;cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px;transition:color 0.15s,border-color 0.15s}
.sidebar-tab.active{color:#1d3158;border-bottom-color:#1d3158}
.sidebar-panel{display:none;padding-top:10px}
.sidebar-panel.active{display:block}
.sidebar-tools-list{margin:0;padding:0;list-style:none}
.sidebar-tools-list li a{display:block;padding:5px 10px 5px 24px;font-size:14px;color:#495057;text-decoration:none;border-left:2px solid transparent;border-radius:0 4px 4px 0}
.sidebar-section-header{padding:7px 12px;font-size:15px;font-weight:700;color:#212529;cursor:pointer;border-radius:4px}
.sidebar-chevron{display:inline-block;font-size:10px;margin-right:4px;color:#757575}
.sidebar-section-items{display:none;padding-left:0;margin:2px 0 6px}
.sidebar-section.expanded .sidebar-section-items{display:block}
.sidebar-section-items li{line-height:1.5}
.sidebar-section-items li a{display:block;padding:4px 10px 4px 32px;font-size:14px;color:#495057;text-decoration:none;border-left:2px solid transparent;border-radius:0 4px 4px 0}
.sidebar-divider{margin:12px 0 2px;padding:0 12px 4px 24px;font-size:11px;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:#9ca3af;border-bottom:1px solid #f0f2f5;list-style:none}
.sidebar-divider:first-child{margin-top:4px}
.progress-dot{display:inline-block;width:10px;height:10px;border-radius:50%;border:1.5px solid #d1d5db;margin-right:7px;vertical-align:middle;flex-shrink:0;position:relative}
/* CLS prevention: TOC sidebar matches main.css final state */
#toc-wrapper{position:sticky;top:20px;max-height:calc(100vh - 40px);overflow-y:auto;padding-left:14px;border-left:1px solid #e9ecef}
.toc-title{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.8px;color:#6c757d;margin-bottom:10px;padding-bottom:0}
#toc{margin:0;padding:0}
#toc li{line-height:1.45;margin-bottom:1px}
#toc li a{font-size:13.5px;color:#6c757d;text-decoration:none;display:block;padding:3px 0;border-left:2px solid transparent;padding-left:8px;margin-left:-15px}
#toc li a.toc-active{color:#1d3158;font-weight:600;border-left-color:#1d3158}
/* CLS prevention: engagement strip layout (matches engagement.css) */
.engagement-header{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;font-size:12px;color:#64748b;letter-spacing:0.01em;margin:0.4em 0 1em;min-height:22px}
.engagement-header:empty{display:none}
/* CLS prevention: progress bar space (matches engagement.css) */
.engagement-progress{min-height:32px;margin:1.2em 0 1.6em}
/* CLS prevention: WebR editor min-height so the static→textarea swap doesn't shift layout */
.webr-editor{min-height:60px}
/* CLS prevention: images in content always reserve aspect ratio */
#content img{max-width:100%;height:auto}
</style>
<!-- Full Bootstrap deferred (non-render-blocking) -->
<link href="www/bootstrap.min.css?h=dae0a568" rel="stylesheet" media="print" onload="this.media='all'">
<noscript><link href="www/bootstrap.min.css?h=dae0a568" rel="stylesheet"></noscript>
<link href="www/highlight.min.css?h=f103014a" rel="stylesheet" media="print" onload="this.media='all'">
<link href="css/main.min.css?h=58574f81" rel="stylesheet" media="print" onload="this.media='all'">
<noscript><link href="css/main.min.css?h=58574f81" rel="stylesheet"></noscript>
<style>
a{color:#1d3158}a:hover{text-decoration:underline}
li{line-height:1.65}
.MathJax_Display{margin:0}
blockquote p{line-height:1.75;color:#717171}
@media(min-width:1200px){.container{width:1170px}}
#nav,#content,#toc-sidebar{box-sizing:border-box}
#content{padding-left:15px;padding-right:15px;overflow-wrap:break-word;word-wrap:break-word;overflow-x:clip}
@media(max-width:767px){#nav{display:none}.masthead-menu-btn{display:inline-flex!important}.masthead-nav{display:none}.masthead-search{display:none}.site-masthead-inner{padding:10px 16px;gap:12px}}
@media(max-width:400px){.masthead-name{font-size:13px}}
.mobile-sidebar-overlay{display:none;position:fixed;top:0;left:0;right:0;bottom:0;z-index:9999;background:rgba(0,0,0,0.4)}
.mobile-sidebar-overlay.open{display:block}
.mobile-sidebar-panel{position:fixed;top:0;left:0;bottom:0;width:280px;background:#fff;z-index:10000;overflow-y:auto;padding:16px;box-shadow:2px 0 16px rgba(0,0,0,0.15);transform:translateX(-100%);transition:transform 0.25s ease}
.mobile-sidebar-overlay.open .mobile-sidebar-panel{transform:translateX(0)}
.mobile-sidebar-close{position:absolute;top:10px;right:12px;background:none;border:none;font-size:22px;cursor:pointer;color:#666}
/* Mobile top-nav drawer section */
.mnav-section{margin-bottom:18px;padding-bottom:14px;border-bottom:1px solid #e5e7eb}
.mnav-section:last-child{border-bottom:none}
.mnav-title{font-family:'IBM Plex Sans',sans-serif;font-size:11px;font-weight:600;color:#8a8f99;text-transform:uppercase;letter-spacing:0.06em;margin:0 0 8px}
.mnav-link{display:block;padding:9px 10px;color:#3a3f4a;text-decoration:none;font-size:15px;border-radius:6px;font-family:'IBM Plex Sans',sans-serif}
.mnav-link:hover,.mnav-link:active{background:#f1f3f6;color:#0d1117;text-decoration:none}
.mnav-accordion{padding:0}
.mnav-accordion>summary{padding:9px 10px;cursor:pointer;font-size:15px;font-weight:500;color:#3a3f4a;list-style:none;border-radius:6px;font-family:'IBM Plex Sans',sans-serif;display:flex;align-items:center;justify-content:space-between}
.mnav-accordion>summary::-webkit-details-marker{display:none}
.mnav-accordion>summary::after{content:'\25BE';font-size:11px;color:#8a8f99;transition:transform 0.15s}
.mnav-accordion[open]>summary::after{transform:rotate(180deg)}
.mnav-accordion>summary:hover{background:#f1f3f6}
.mnav-accordion-body{padding:4px 6px 8px 10px}
.mnav-accordion-body .mnav-link{padding:7px 8px;font-size:14px;color:#4a5160}
.mnav-accordion-body h6{margin:10px 0 4px 8px;font-family:'IBM Plex Sans',sans-serif;font-size:10px;font-weight:600;color:#8a8f99;text-transform:uppercase;letter-spacing:0.06em}
html.dark .mobile-sidebar-panel{background:#1e293b}
html.dark .mobile-sidebar-overlay{background:rgba(0,0,0,0.6)}
html.dark .mobile-sidebar-close{color:#94a3b8}
html.dark .mnav-section{border-bottom-color:#334155}
html.dark .mnav-title{color:#7a808c}
html.dark .mnav-link,html.dark .mnav-accordion>summary{color:#c5cad3}
html.dark .mnav-link:hover,html.dark .mnav-link:active,html.dark .mnav-accordion>summary:hover{background:#1a1d22;color:#fff}
html.dark .mnav-accordion-body .mnav-link{color:#b0b5bf}
html.dark .mnav-accordion-body h6{color:#7a808c}
</style>
<!-- Open Graph -->
<meta property="og:title" content="Bayesian Statistics in R: Build Genuine Intuition Before Opening Stan or brms">
<meta property="og:description" content="Bayesian statistics in R from scratch: simulate the prior-likelihood-posterior update, watch a wrong prior get washed out by data, then bridge to MCMC.">
<meta property="og:type" content="article">
<meta property="og:url" content="https://r-statistics.co/Bayesian-Statistics-in-R.html">
<meta property="og:site_name" content="r-statistics.co">
<meta property="og:image" content="https://r-statistics.co/screenshots/og/Bayesian-Statistics-in-R.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Bayesian Statistics in R: Build Genuine Intuition Before Opening Stan or brms">
<meta name="twitter:description" content="Bayesian statistics in R from scratch: simulate the prior-likelihood-posterior update, watch a wrong prior get washed out by data, then bridge to MCMC.">
<meta name="twitter:image" content="https://r-statistics.co/screenshots/og/Bayesian-Statistics-in-R.png">
<!-- JSON-LD Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": ["TechArticle", "LearningResource"],
"headline": "Bayesian Statistics in R: Build Genuine Intuition Before Opening Stan or brms",
"description": "Bayesian statistics in R from scratch: simulate the prior-likelihood-posterior update, watch a wrong prior get washed out by data, then bridge to MCMC.",
"author": {"@type": "Person", "name": "Selva Prabhakaran", "url": "https://r-statistics.co/about/", "jobTitle": "Data Scientist"},
"publisher": {"@type": "Organization", "name": "r-statistics.co", "url": "https://r-statistics.co/", "logo": {"@type": "ImageObject", "url": "https://r-statistics.co/screenshots/og-default.png"}},
"url": "https://r-statistics.co/Bayesian-Statistics-in-R.html",
"datePublished": "2026-05-13",
"dateModified": "2026-05-13",
"inLanguage": "en",
"educationalLevel": "Intermediate",
"programmingLanguage": "R",
"speakable": {"@type": "SpeakableSpecification", "cssSelector": [".lead", "#content h1"]}
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://r-statistics.co/"},
{"@type": "ListItem", "position": 2, "name": "Statistics", "item": "https://r-statistics.co/"},
{"@type": "ListItem", "position": 3, "name": "Bayesian Statistics in R: Build Genuine Intuition Before Opening Stan or brms", "item": "https://r-statistics.co/Bayesian-Statistics-in-R.html"}
]
}
</script>
<link rel="stylesheet" href="www/webr.min.css?h=23e578a3">
<link rel="stylesheet" href="www/engagement.min.css?h=6cdbfd3e" media="print" onload="this.media='all'">
<noscript><link rel="stylesheet" href="www/engagement.min.css?h=6cdbfd3e"></noscript>
</head>
<body>
<!-- Mobile sidebar overlay -->
<div class="mobile-sidebar-overlay" id="mobile-sidebar">
<div class="mobile-sidebar-panel">
<button class="mobile-sidebar-close" id="mobile-sidebar-close">×</button>
<!-- Top nav (mobile only) -->
<div class="mnav-section">
<h6 class="mnav-title">Navigate</h6>
<a class="mnav-link" href="/">Home</a>
<a class="mnav-link" href="/posts/">Compendium</a>
<details class="mnav-accordion">
<summary>Exercises</summary>
<div class="mnav-accordion-body">
<h6>Tidyverse packages</h6>
<a class="mnav-link" href="/dplyr-Exercises-in-R.html">dplyr</a>
<a class="mnav-link" href="/ggplot2-Exercises-in-R.html">ggplot2</a>
<a class="mnav-link" href="/tidyr-Exercises-in-R.html">tidyr</a>
<a class="mnav-link" href="/stringr-Exercises-in-R.html">stringr</a>
<a class="mnav-link" href="/lubridate-Exercises-in-R.html">lubridate</a>
<a class="mnav-link" href="/purrr-Exercises-in-R.html">purrr</a>
<a class="mnav-link" href="/forcats-Exercises-in-R.html">forcats</a>
<a class="mnav-link" href="/readr-Exercises-in-R.html">readr</a>
<a class="mnav-link" href="/broom-Exercises-in-R.html">broom</a>
<a class="mnav-link" href="/tidyverse-Exercises-in-R.html">Tidyverse</a>
<a class="mnav-link" href="/R-for-Data-Science-Exercises.html">R for Data Science</a>
<h6>Deep dives</h6>
<a class="mnav-link" href="/dplyr-Joins-Exercises-in-R.html">dplyr Joins</a>
<a class="mnav-link" href="/dplyr-Window-Functions-Exercises-in-R.html">dplyr Window Functions</a>
<a class="mnav-link" href="/dplyr-Group-By-Exercises-in-R.html">dplyr group_by</a>
<a class="mnav-link" href="/ggplot2-Themes-Exercises-in-R.html">ggplot2 Themes</a>
<a class="mnav-link" href="/ggplot2-Facets-Exercises-in-R.html">ggplot2 Facets</a>
<a class="mnav-link" href="/ggplot2-Color-Scales-Exercises-in-R.html">ggplot2 Color Scales</a>
<a class="mnav-link" href="/ggplot2-Bar-Chart-Exercises-in-R.html">ggplot2 Bar Charts</a>
<a class="mnav-link" href="/ggplot2-Heatmap-Exercises-in-R.html">ggplot2 Heatmaps</a>
<a class="mnav-link" href="/tidyr-Pivot-Exercises-in-R.html">tidyr Pivot</a>
<a class="mnav-link" href="/tidyr-Nest-Unnest-Exercises-in-R.html">tidyr Nest/Unnest</a>
<a class="mnav-link" href="/Regex-Exercises-in-R.html">Regex</a>
<h6>Wrangling & EDA</h6>
<a class="mnav-link" href="/Data-Wrangling-Exercises-in-R.html">Data Wrangling</a>
<a class="mnav-link" href="/Data-Cleaning-Exercises-in-R.html">Data Cleaning</a>
<a class="mnav-link" href="/EDA-Exercises-in-R.html">EDA</a>
<a class="mnav-link" href="/Data-Visualization-Exercises-in-R.html">Data Visualization</a>
<a class="mnav-link" href="/data.table-Exercises-in-R.html">data.table</a>
<a class="mnav-link" href="/dbplyr-SQL-Exercises-in-R.html">dbplyr / SQL</a>
<a class="mnav-link" href="/Web-Scraping-Exercises-in-R.html">Web Scraping</a>
<a class="mnav-link" href="/API-Calls-Exercises-in-R.html">API Calls</a>
<h6>Statistics</h6>
<a class="mnav-link" href="/Hypothesis-Testing-Exercises-in-R.html">Hypothesis Testing</a>
<a class="mnav-link" href="/Linear-Regression-Exercises-in-R.html">Linear Regression</a>
<a class="mnav-link" href="/Logistic-Regression-Exercises-in-R.html">Logistic Regression</a>
<a class="mnav-link" href="/Correlation-Exercises-in-R.html">Correlation</a>
<a class="mnav-link" href="/Probability-Distributions-Exercises-in-R.html">Probability Distributions</a>
<h6>Machine Learning</h6>
<a class="mnav-link" href="/Machine-Learning-Exercises-in-R.html">Machine Learning</a>
<a class="mnav-link" href="/tidymodels-Exercises-in-R.html">tidymodels</a>
<a class="mnav-link" href="/Random-Forest-Exercises-in-R.html">Random Forest</a>
<a class="mnav-link" href="/XGBoost-Exercises-in-R.html">XGBoost</a>
<a class="mnav-link" href="/Clustering-Exercises-in-R.html">Clustering</a>
<a class="mnav-link" href="/PCA-Exercises-in-R.html">PCA</a>
<a class="mnav-link" href="/Cross-Validation-Exercises-in-R.html">Cross-Validation</a>
<h6>Time Series</h6>
<a class="mnav-link" href="/Time-Series-Exercises-in-R.html">Time Series</a>
<a class="mnav-link" href="/ARIMA-Exercises-in-R.html">ARIMA</a>
<h6>By Industry</h6>
<a class="mnav-link" href="/R-for-Finance-Exercises.html">Finance</a>
<a class="mnav-link" href="/R-for-Marketing-Analytics-Exercises.html">Marketing Analytics</a>
<a class="mnav-link" href="/R-for-Healthcare-Exercises.html">Healthcare</a>
<a class="mnav-link" href="/R-for-Biostatistics-Exercises.html">Biostatistics</a>
<a class="mnav-link" href="/R-for-Genomics-Exercises.html">Genomics</a>
<a class="mnav-link" href="/R-for-Sports-Analytics-Exercises.html">Sports Analytics</a>
<a class="mnav-link" href="/A-B-Testing-Exercises-in-R.html">A/B Testing</a>
<h6>Reporting & Apps</h6>
<a class="mnav-link" href="/Shiny-Exercises-in-R.html">Shiny</a>
<a class="mnav-link" href="/R-Markdown-Exercises.html">R Markdown</a>
<h6>Levels</h6>
<a class="mnav-link" href="/R-Beginner-Exercises.html">R for Beginners</a>
<a class="mnav-link" href="/R-Interview-Questions.html">R Interview Questions</a>
</div>
</details>
</div>
<div id="mobile-sidebar-content">
<!-- Populated by toc.js (curriculum nav) -->
</div>
</div>
</div>
<div class="container">
<header class="site-masthead">
<div class="site-masthead-inner">
<button id="mobile-menu-btn" class="masthead-menu-btn" aria-label="Menu">☰</button>
<a class="masthead-wordmark" href="/">
<span class="masthead-mark">R</span>
<span class="masthead-name">r‑statistics<span class="masthead-tld">.co</span></span>
</a>
<nav class="masthead-nav">
<a class="masthead-nav-link" href="/">Home</a>
<a class="masthead-nav-link" href="/posts/">Compendium</a>
<span class="nav-dropdown">
<a class="masthead-nav-link nav-dropdown-trigger" href="javascript:void(0)" onclick="this.parentNode.classList.toggle('open')">Exercises</a>
<div class="nav-dropdown-panel">
<div class="nav-cat">Tidyverse
<div class="nav-sub">
<h6>Packages</h6>
<a href="/dplyr-Exercises-in-R.html">dplyr</a>
<a href="/ggplot2-Exercises-in-R.html">ggplot2</a>
<a href="/tidyr-Exercises-in-R.html">tidyr</a>
<a href="/stringr-Exercises-in-R.html">stringr</a>
<a href="/lubridate-Exercises-in-R.html">lubridate</a>
<a href="/purrr-Exercises-in-R.html">purrr</a>
<a href="/forcats-Exercises-in-R.html">forcats</a>
<a href="/readr-Exercises-in-R.html">readr</a>
<a href="/broom-Exercises-in-R.html">broom</a>
<h6>Cross-package</h6>
<a href="/tidyverse-Exercises-in-R.html">Tidyverse</a>
<a href="/R-for-Data-Science-Exercises.html">R for Data Science</a>
</div>
</div>
<div class="nav-cat">dplyr deep dives
<div class="nav-sub">
<a href="/dplyr-Joins-Exercises-in-R.html">Joins</a>
<a href="/dplyr-Window-Functions-Exercises-in-R.html">Window Functions</a>
<a href="/dplyr-Group-By-Exercises-in-R.html">group_by</a>
</div>
</div>
<div class="nav-cat">ggplot2 deep dives
<div class="nav-sub">
<a href="/ggplot2-Themes-Exercises-in-R.html">Themes</a>
<a href="/ggplot2-Facets-Exercises-in-R.html">Facets</a>
<a href="/ggplot2-Color-Scales-Exercises-in-R.html">Color Scales</a>
<a href="/ggplot2-Bar-Chart-Exercises-in-R.html">Bar Charts</a>
<a href="/ggplot2-Heatmap-Exercises-in-R.html">Heatmaps</a>
<a href="/Data-Visualization-Exercises-in-R.html">Data Visualization (general)</a>
<a href="/plotly-Exercises-in-R.html">plotly (interactive)</a>
<a href="/leaflet-Exercises-in-R.html">leaflet (maps)</a>
<a href="/gt-Tables-Exercises-in-R.html">gt Tables</a>
</div>
</div>
<div class="nav-cat">tidyr deep dives
<div class="nav-sub">
<a href="/tidyr-Pivot-Exercises-in-R.html">Pivot</a>
<a href="/tidyr-Nest-Unnest-Exercises-in-R.html">Nest/Unnest</a>
<a href="/Regex-Exercises-in-R.html">Regex in R</a>
</div>
</div>
<div class="nav-cat">Data Wrangling
<div class="nav-sub">
<a href="/Data-Wrangling-Exercises-in-R.html">Data Wrangling</a>
<a href="/Data-Cleaning-Exercises-in-R.html">Data Cleaning</a>
<a href="/EDA-Exercises-in-R.html">EDA</a>
<a href="/data.table-Exercises-in-R.html">data.table</a>
<a href="/dbplyr-SQL-Exercises-in-R.html">dbplyr / SQL</a>
<a href="/Web-Scraping-Exercises-in-R.html">Web Scraping</a>
<a href="/API-Calls-Exercises-in-R.html">API Calls</a>
</div>
</div>
<div class="nav-cat">Statistics
<div class="nav-sub">
<h6>Tests</h6>
<a href="/Hypothesis-Testing-Exercises-in-R.html">Hypothesis Testing</a>
<a href="/t-Test-Exercises-in-R.html">t-Test</a>
<a href="/ANOVA-Exercises-in-R.html">ANOVA</a>
<a href="/Chi-Square-Test-Exercises-in-R.html">Chi-Square</a>
<a href="/Correlation-Exercises-in-R.html">Correlation</a>
<h6>Regression</h6>
<a href="/Linear-Regression-Exercises-in-R.html">Linear Regression</a>
<a href="/Logistic-Regression-Exercises-in-R.html">Logistic Regression</a>
<h6>Probability & Sampling</h6>
<a href="/Probability-Distributions-Exercises-in-R.html">Probability Distributions</a>
<a href="/Sampling-Methods-Exercises-in-R.html">Sampling Methods</a>
<a href="/Survey-Analysis-in-R-Exercises.html">Survey Analysis</a>
</div>
</div>
<div class="nav-cat">Machine Learning
<div class="nav-sub">
<h6>Workflow</h6>
<a href="/Machine-Learning-Exercises-in-R.html">Machine Learning</a>
<a href="/tidymodels-Exercises-in-R.html">tidymodels</a>
<a href="/Cross-Validation-Exercises-in-R.html">Cross-Validation</a>
<h6>Algorithms</h6>
<a href="/Random-Forest-Exercises-in-R.html">Random Forest</a>
<a href="/XGBoost-Exercises-in-R.html">XGBoost</a>
<a href="/Clustering-Exercises-in-R.html">Clustering</a>
<a href="/PCA-Exercises-in-R.html">PCA</a>
</div>
</div>
<div class="nav-cat">Time Series
<div class="nav-sub">
<a href="/Time-Series-Exercises-in-R.html">Time Series</a>
<a href="/ARIMA-Exercises-in-R.html">ARIMA</a>
</div>
</div>
<div class="nav-cat">By Industry
<div class="nav-sub">
<a href="/R-for-Finance-Exercises.html">Finance</a>
<a href="/R-for-Marketing-Analytics-Exercises.html">Marketing Analytics</a>
<a href="/R-for-Healthcare-Exercises.html">Healthcare</a>
<a href="/R-for-Biostatistics-Exercises.html">Biostatistics</a>
<a href="/R-for-Genomics-Exercises.html">Genomics</a>
<a href="/R-for-Sports-Analytics-Exercises.html">Sports Analytics</a>
<a href="/A-B-Testing-Exercises-in-R.html">A/B Testing</a>
</div>
</div>
<div class="nav-cat">Reporting & Apps
<div class="nav-sub">
<a href="/Shiny-Exercises-in-R.html">Shiny</a>
<a href="/R-Markdown-Exercises.html">R Markdown</a>
</div>
</div>
<div class="nav-cat">Performance
<div class="nav-sub">
<a href="/R-Performance-Optimization-Exercises.html">Performance Optimization</a>
<a href="/Parallel-Computing-in-R-Exercises.html">Parallel Computing</a>
</div>
</div>
<div class="nav-cat">By Level
<div class="nav-sub">
<a href="/R-Beginner-Exercises.html">R for Beginners</a>
<a href="/R-Interview-Questions.html">R Interview Questions</a>
</div>
</div>
</div>
</span>
</nav>
<div class="masthead-tools">
<form onsubmit="my_search_google(); return false;" class="masthead-search">
<input type="text" id="my-google-search" placeholder="Search…" aria-label="Search r-statistics.co">
</form>
<button id="dark-mode-toggle" class="masthead-icon-btn" aria-label="Toggle dark mode" title="Toggle dark mode">☽</button>
</div>
</div>
</header>
<div class="row">
<div class="col-xs-12 col-sm-3" id="nav">
<div id="sidebar-nav"><div class="continue-chip" data-continue-chip><span class="chip-label">Continue reading</span><a href="#" data-continue-link></a></div><div class="sidebar-tabs" role="tablist"><button class="sidebar-tab active" data-tab="posts" type="button" role="tab" onclick="var n=this.dataset.tab;document.querySelectorAll('.sidebar-tab').forEach(function(x){x.classList.toggle('active',x.dataset.tab===n)});document.querySelectorAll('.sidebar-panel').forEach(function(p){p.classList.toggle('active',p.dataset.panel===n)});try{localStorage.setItem('rstat_sidebar_tab',n)}catch(e){}">Posts</button><button class="sidebar-tab" data-tab="tools" type="button" role="tab" onclick="var n=this.dataset.tab;document.querySelectorAll('.sidebar-tab').forEach(function(x){x.classList.toggle('active',x.dataset.tab===n)});document.querySelectorAll('.sidebar-panel').forEach(function(p){p.classList.toggle('active',p.dataset.panel===n)});try{localStorage.setItem('rstat_sidebar_tab',n)}catch(e){}">Tools</button></div><div class="sidebar-panel active" data-panel="posts"><ul class="sidebar-menu list-unstyled"><li class="sidebar-section"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Learn R<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec0sub1" data-collapsed="false"><span class="subsec-chevron">▼</span> Getting Started</li><li data-subkey="sec0sub1"><a href="/Is-R-Worth-Learning-in-2026.html"><span class="progress-dot"></span>Is R Worth Learning?</a></li><li data-subkey="sec0sub1"><a href="/Install-R-and-RStudio-2026.html"><span class="progress-dot"></span>Install R & RStudio</a></li><li data-subkey="sec0sub1"><a href="/RStudio-IDE-Tour.html"><span class="progress-dot"></span>RStudio IDE Tour</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec0sub2" data-collapsed="false"><span class="subsec-chevron">▼</span> R Fundamentals</li><li data-subkey="sec0sub2"><a href="/R-Syntax-101.html"><span class="progress-dot"></span>R Syntax 101</a></li><li data-subkey="sec0sub2"><a href="/R-Data-Types.html"><span class="progress-dot"></span>R Data Types</a></li><li data-subkey="sec0sub2"><a href="/R-Vectors.html"><span class="progress-dot"></span>R Vectors</a></li><li data-subkey="sec0sub2"><a href="/R-Matrices.html"><span class="progress-dot"></span>R Matrices</a></li><li data-subkey="sec0sub2"><a href="/R-Factors.html"><span class="progress-dot"></span>R Factors</a></li><li data-subkey="sec0sub2"><a href="/R-Data-Frames.html"><span class="progress-dot"></span>R Data Frames</a></li><li data-subkey="sec0sub2"><a href="/R-Lists.html"><span class="progress-dot"></span>R Lists</a></li><li data-subkey="sec0sub2"><a href="/R-Control-Flow.html"><span class="progress-dot"></span>R Control Flow</a></li><li data-subkey="sec0sub2"><a href="/R-Special-Values.html"><span class="progress-dot"></span>R Special Values</a></li><li data-subkey="sec0sub2"><a href="/R-Type-Coercion.html"><span class="progress-dot"></span>R Type Coercion</a></li><li data-subkey="sec0sub2"><a href="/R-Functions.html"><span class="progress-dot"></span>Writing R Functions</a></li><li data-subkey="sec0sub2"><a href="/R-Beginner-Exercises-quiz.html"><span class="progress-dot"></span>R Fundamentals Quiz</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec0sub3" data-collapsed="false"><span class="subsec-chevron">▼</span> Working Effectively</li><li data-subkey="sec0sub3"><a href="/R-Subsetting.html"><span class="progress-dot"></span>R Subsetting</a></li><li data-subkey="sec0sub3"><a href="/Getting-Help-in-R.html"><span class="progress-dot"></span>Getting Help in R</a></li><li data-subkey="sec0sub3"><a href="/R-Project-Structure.html"><span class="progress-dot"></span>R Project Structure</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec0sub4" data-collapsed="false"><span class="subsec-chevron">▼</span> R Career & Resources</li><li data-subkey="sec0sub4"><a href="/R-vs-Python.html"><span class="progress-dot"></span>R vs Python</a></li><li data-subkey="sec0sub4"><a href="/How-to-Learn-R.html"><span class="progress-dot"></span>How to Learn R</a></li><li data-subkey="sec0sub4"><a href="/R-for-Excel-Users.html"><span class="progress-dot"></span>R for Excel Users</a></li><li data-subkey="sec0sub4"><a href="/R-Interview-Questions.html"><span class="progress-dot"></span>R Interview Questions</a></li><li data-subkey="sec0sub4"><a href="/R-Interview-Questions-quiz.html"><span class="progress-dot"></span>R Interview Readiness Quiz</a></li><li data-subkey="sec0sub4"><a href="/R-Cheat-Sheet.html"><span class="progress-dot"></span>R Cheat Sheet</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec0sub5" data-collapsed="false"><span class="subsec-chevron">▼</span> Professional R</li><li data-subkey="sec0sub5"><a href="/Data-Ethics-in-R.html"><span class="progress-dot"></span>Data Ethics</a></li><li data-subkey="sec0sub5"><a href="/Bias-in-Data-and-Models.html"><span class="progress-dot"></span>Bias in Data & Models</a></li><li data-subkey="sec0sub5"><a href="/Reproducibility-Crisis.html"><span class="progress-dot"></span>Reproducibility</a></li><li data-subkey="sec0sub5"><a href="/Data-Privacy-in-R.html"><span class="progress-dot"></span>Data Privacy</a></li><li data-subkey="sec0sub5"><a href="/Communicating-Uncertainty.html"><span class="progress-dot"></span>Communicating Uncertainty</a></li></ul></li><li class="sidebar-section"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Data Wrangling<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec1sub1" data-collapsed="false"><span class="subsec-chevron">▼</span> Import & Setup</li><li data-subkey="sec1sub1"><a href="/Importing-Data-in-R.html"><span class="progress-dot"></span>Importing Data</a></li><li data-subkey="sec1sub1"><a href="/R-Pipe-Operator.html"><span class="progress-dot"></span>Pipe Operator</a></li><li data-subkey="sec1sub1"><a href="/Tidy-Data-in-R.html"><span class="progress-dot"></span>Tidy Data</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec1sub2" data-collapsed="false"><span class="subsec-chevron">▼</span> dplyr Essentials</li><li data-subkey="sec1sub2"><a href="/dplyr-filter-select.html"><span class="progress-dot"></span>dplyr filter & select</a></li><li data-subkey="sec1sub2"><a href="/dplyr-mutate-rename.html"><span class="progress-dot"></span>dplyr mutate & rename</a></li><li data-subkey="sec1sub2"><a href="/dplyr-group-by-summarise.html"><span class="progress-dot"></span>dplyr group_by & summarise</a></li><li data-subkey="sec1sub2"><a href="/dplyr-arrange-slice.html"><span class="progress-dot"></span>dplyr arrange & slice</a></li><li data-subkey="sec1sub2"><a href="/dplyr-across.html"><span class="progress-dot"></span>dplyr across()</a></li><li data-subkey="sec1sub2"><a href="/dplyr-case-when.html"><span class="progress-dot"></span>dplyr case_when()</a></li><li data-subkey="sec1sub2"><a href="/dplyr-Exercises-in-R-quiz.html"><span class="progress-dot"></span>dplyr Quiz</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec1sub3" data-collapsed="false"><span class="subsec-chevron">▼</span> Join & Reshape</li><li data-subkey="sec1sub3"><a href="/R-Joins.html"><span class="progress-dot"></span>R Joins</a></li><li data-subkey="sec1sub3"><a href="/pivot_longer-pivot_wider-Reshape-Data-in-R.html"><span class="progress-dot"></span>pivot_longer & pivot_wider</a></li><li data-subkey="sec1sub3"><a href="/tidyr-separate-unite-Split-Combine-Columns-in-R.html"><span class="progress-dot"></span>separate() & unite()</a></li><li data-subkey="sec1sub3"><a href="/tidyr-Exercises-in-R-quiz.html"><span class="progress-dot"></span>tidyr Quiz</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec1sub4" data-collapsed="false"><span class="subsec-chevron">▼</span> Clean & Quality</li><li data-subkey="sec1sub4"><a href="/Missing-Values-in-R-Detect-Count-Remove-Impute-NA.html"><span class="progress-dot"></span>Missing Values (NA)</a></li><li data-subkey="sec1sub4"><a href="/Data-Quality-Checking-in-R.html"><span class="progress-dot"></span>Data Quality Checking</a></li><li data-subkey="sec1sub4"><a href="/janitor-Package-in-R.html"><span class="progress-dot"></span>janitor Package</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec1sub5" data-collapsed="false"><span class="subsec-chevron">▼</span> Strings & Dates</li><li data-subkey="sec1sub5"><a href="/stringr-in-R.html"><span class="progress-dot"></span>stringr</a></li><li data-subkey="sec1sub5"><a href="/R-Regex-stringr-Pattern-Matching.html"><span class="progress-dot"></span>Regex Patterns</a></li><li data-subkey="sec1sub5"><a href="/lubridate-in-R.html"><span class="progress-dot"></span>lubridate</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec1sub6" data-collapsed="false"><span class="subsec-chevron">▼</span> Scale & Connect</li><li data-subkey="sec1sub6"><a href="/DBI-in-R.html"><span class="progress-dot"></span>DBI & Databases</a></li><li data-subkey="sec1sub6"><a href="/DuckDB-in-R.html"><span class="progress-dot"></span>DuckDB & duckplyr</a></li><li data-subkey="sec1sub6"><a href="/Web-Scraping-in-R-with-rvest.html"><span class="progress-dot"></span>Web Scraping (rvest)</a></li><li data-subkey="sec1sub6"><a href="/REST-APIs-in-R-with-httr2.html"><span class="progress-dot"></span>REST APIs (httr2)</a></li></ul></li><li class="sidebar-section"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Visualization<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub1" data-collapsed="false"><span class="subsec-chevron">▼</span> ggplot2 Foundations</li><li data-subkey="sec2sub1"><a href="/ggplot2-Grammar-of-Graphics.html"><span class="progress-dot"></span>Grammar of Graphics</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Getting-Started.html"><span class="progress-dot"></span>ggplot2 Getting Started</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Aesthetics-aes-Map-Data.html"><span class="progress-dot"></span>ggplot2 Aesthetics (aes)</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Colours.html"><span class="progress-dot"></span>ggplot2 Colours</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Scales.html"><span class="progress-dot"></span>ggplot2 Scales</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Themes-in-R.html"><span class="progress-dot"></span>ggplot2 Themes</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Labels-and-Annotations.html"><span class="progress-dot"></span>Labels & Annotations</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Facets.html"><span class="progress-dot"></span>ggplot2 Facets</a></li><li data-subkey="sec2sub1"><a href="/ggplot2-Exercises-in-R-quiz.html"><span class="progress-dot"></span>ggplot2 Quiz</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub2" data-collapsed="false"><span class="subsec-chevron">▼</span> Core Charts</li><li data-subkey="sec2sub2"><a href="/ggplot2-Scatter-Plots.html"><span class="progress-dot"></span>Scatter Plots</a></li><li data-subkey="sec2sub2"><a href="/ggplot2-Line-Charts.html"><span class="progress-dot"></span>Line Charts</a></li><li data-subkey="sec2sub2"><a href="/ggplot2-Bar-Charts.html"><span class="progress-dot"></span>Bar Charts</a></li><li data-subkey="sec2sub2"><a href="/ggplot2-Distribution-Charts.html"><span class="progress-dot"></span>Distribution Charts</a></li><li data-subkey="sec2sub2"><a href="/Error-Bars-in-R.html"><span class="progress-dot"></span>Error Bars</a></li><li data-subkey="sec2sub2"><a href="/geom_smooth-in-R.html"><span class="progress-dot"></span>geom_smooth()</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub3" data-collapsed="false"><span class="subsec-chevron">▼</span> Distributions & Groups</li><li data-subkey="sec2sub3"><a href="/Violin-Plot-in-R.html"><span class="progress-dot"></span>Violin Plot</a></li><li data-subkey="sec2sub3"><a href="/Ridgeline-Plot-in-R.html"><span class="progress-dot"></span>Ridgeline Plot</a></li><li data-subkey="sec2sub3"><a href="/Lollipop-Chart-in-R.html"><span class="progress-dot"></span>Lollipop Chart</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub4" data-collapsed="false"><span class="subsec-chevron">▼</span> Relationships</li><li data-subkey="sec2sub4"><a href="/Bubble-Chart-in-R.html"><span class="progress-dot"></span>Bubble Chart</a></li><li data-subkey="sec2sub4"><a href="/Heatmap-in-R.html"><span class="progress-dot"></span>Heatmap in R</a></li><li data-subkey="sec2sub4"><a href="/Correlation-Matrix-Plot-in-R.html"><span class="progress-dot"></span>Correlation Matrix</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub5" data-collapsed="false"><span class="subsec-chevron">▼</span> Advanced Charts</li><li data-subkey="sec2sub5"><a href="/Pie-Donut-Chart-in-R.html"><span class="progress-dot"></span>Pie & Donut Chart</a></li><li data-subkey="sec2sub5"><a href="/Treemap-in-R.html"><span class="progress-dot"></span>Treemap</a></li><li data-subkey="sec2sub5"><a href="/Waffle-Chart-in-R.html"><span class="progress-dot"></span>Waffle Chart</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub6" data-collapsed="false"><span class="subsec-chevron">▼</span> Exploratory Analysis</li><li data-subkey="sec2sub6"><a href="/Exploratory-Data-Analysis-in-R.html"><span class="progress-dot"></span>EDA (7-Step Framework)</a></li><li data-subkey="sec2sub6"><a href="/Univariate-EDA-in-R.html"><span class="progress-dot"></span>Univariate EDA</a></li><li data-subkey="sec2sub6"><a href="/Bivariate-EDA-in-R.html"><span class="progress-dot"></span>Bivariate EDA</a></li><li data-subkey="sec2sub6"><a href="/Descriptive-Statistics-in-R.html"><span class="progress-dot"></span>Descriptive Statistics</a></li><li data-subkey="sec2sub6"><a href="/Correlation-Analysis-in-R.html"><span class="progress-dot"></span>Correlation Analysis</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub7" data-collapsed="false"><span class="subsec-chevron">▼</span> Interactive & Maps</li><li data-subkey="sec2sub7"><a href="/Combining-ggplot2-with-plotly.html"><span class="progress-dot"></span>ggplot2 + plotly Interactive</a></li><li data-subkey="sec2sub7"><a href="/Interactive-Maps-in-R-with-leaflet.html"><span class="progress-dot"></span>Leaflet Interactive Maps</a></li><li data-subkey="sec2sub7"><a href="/Spatial-Data-in-R-with-sf.html"><span class="progress-dot"></span>Spatial Data (sf)</a></li><li data-subkey="sec2sub7"><a href="/Choropleth-Maps-in-R.html"><span class="progress-dot"></span>Choropleth Maps (sf)</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec2sub8" data-collapsed="false"><span class="subsec-chevron">▼</span> Customization & Reference</li><li data-subkey="sec2sub8"><a href="/ggplot2-Legends-in-R.html"><span class="progress-dot"></span>ggplot2 Legends</a></li><li data-subkey="sec2sub8"><a href="/ggplot2-Secondary-Axis.html"><span class="progress-dot"></span>Secondary Axis</a></li><li data-subkey="sec2sub8"><a href="/ggplot2-Log-Scale.html"><span class="progress-dot"></span>Log Scale</a></li><li data-subkey="sec2sub8"><a href="/patchwork-Package.html"><span class="progress-dot"></span>patchwork (Combine Plots)</a></li><li data-subkey="sec2sub8"><a href="/Publication-Quality-Figures-in-R.html"><span class="progress-dot"></span>Publication-Ready Figures</a></li><li data-subkey="sec2sub8"><a href="/ggplot2-cheatsheet.html"><span class="progress-dot"></span>ggplot2 Quickref</a></li></ul></li><li class="sidebar-section expanded"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Statistics<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec3sub1" data-collapsed="false"><span class="subsec-chevron">▼</span> EDA & Data Quality</li><li data-subkey="sec3sub1"><a href="/Automated-EDA-in-R.html"><span class="progress-dot"></span>Automated EDA</a></li><li data-subkey="sec3sub1"><a href="/Missing-Data-Visualization-in-R-naniar.html"><span class="progress-dot"></span>Missing Data Viz (naniar)</a></li><li data-subkey="sec3sub1"><a href="/Outlier-Detection-in-R.html"><span class="progress-dot"></span>Outlier Detection</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec3sub2" data-collapsed="false"><span class="subsec-chevron">▼</span> Probability</li><li data-subkey="sec3sub2"><a href="/Sample-Spaces-Events-and-Probability-Axioms-in-R-With-Monte-Carlo-Proof.html"><span class="progress-dot"></span>Probability Axioms</a></li><li data-subkey="sec3sub2"><a href="/Conditional-Probability-in-R.html"><span class="progress-dot"></span>Conditional Probability</a></li><li data-subkey="sec3sub2"><a href="/Random-Variables-in-R.html"><span class="progress-dot"></span>Random Variables</a></li><li data-subkey="sec3sub2"><a href="/Binomial-and-Poisson-Distributions-in-R.html"><span class="progress-dot"></span>Binomial vs Poisson</a></li><li data-subkey="sec3sub2"><a href="/Normal-t-F-and-Chi-Squared-Distributions-in-R.html"><span class="progress-dot"></span>Normal, t, F, Chi-Squared</a></li><li data-subkey="sec3sub2"><a href="/Central-Limit-Theorem-in-R.html"><span class="progress-dot"></span>Central Limit Theorem</a></li><li data-subkey="sec3sub2"><a href="/Sampling-Distributions-in-R.html"><span class="progress-dot"></span>Sampling Distributions</a></li><li data-subkey="sec3sub2"><a href="/Law-of-Large-Numbers-vs-CLT-in-R.html"><span class="progress-dot"></span>LLN vs CLT</a></li><li data-subkey="sec3sub2"><a href="/What-Is-Probability-Simulation-First-Intuition-in-R-Before-the-Formulas.html"><span class="progress-dot"></span>Probability (Simulation-First)</a></li><li data-subkey="sec3sub2"><a href="/Expected-Value-and-Variance-in-R.html"><span class="progress-dot"></span>Expected Value and Variance</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec3sub3" data-collapsed="false"><span class="subsec-chevron">▼</span> Inference & Estimation</li><li data-subkey="sec3sub3"><a href="/Maximum-Likelihood-Estimation-in-R.html"><span class="progress-dot"></span>Maximum Likelihood Estimation</a></li><li data-subkey="sec3sub3"><a href="/Hypothesis-Testing-in-R.html"><span class="progress-dot"></span>Hypothesis Testing</a></li><li data-subkey="sec3sub3"><a href="/Sample-Size-Planning-in-R.html"><span class="progress-dot"></span>Sample Size Planning</a></li><li data-subkey="sec3sub3"><a href="/Which-Statistical-Test-in-R.html"><span class="progress-dot"></span>Choosing the Right Test</a></li><li data-subkey="sec3sub3"><a href="/Statistical-Tests-in-R.html"><span class="progress-dot"></span>Statistical Tests</a></li><li data-subkey="sec3sub3"><a href="/Measures-of-Association-in-R.html"><span class="progress-dot"></span>Measures of Association</a></li><li data-subkey="sec3sub3"><a href="/Point-Estimation-in-R.html"><span class="progress-dot"></span>Point Estimation</a></li><li data-subkey="sec3sub3"><a href="/Confidence-Intervals-in-R.html"><span class="progress-dot"></span>Confidence Intervals</a></li><li data-subkey="sec3sub3"><a href="/Type-I-and-Type-II-Errors-in-R.html"><span class="progress-dot"></span>Type I and II Errors</a></li><li data-subkey="sec3sub3"><a href="/Statistical-Power-Analysis-in-R.html"><span class="progress-dot"></span>Power Analysis</a></li><li data-subkey="sec3sub3"><a href="/Effect-Size-in-R.html"><span class="progress-dot"></span>Effect Size</a></li><li data-subkey="sec3sub3"><a href="/t-Tests-in-R.html"><span class="progress-dot"></span>t-Tests</a></li><li data-subkey="sec3sub3"><a href="/Proportion-Tests-in-R.html"><span class="progress-dot"></span>Proportion Tests</a></li><li data-subkey="sec3sub3"><a href="/Normality-and-Variance-Tests-in-R.html"><span class="progress-dot"></span>Normality & Variance Tests</a></li><li data-subkey="sec3sub3"><a href="/Chi-Square-Tests-in-R.html"><span class="progress-dot"></span>Chi-Square Tests</a></li><li data-subkey="sec3sub3"><a href="/Wilcoxon-Mann-Whitney-and-Kruskal-Wallis-in-R.html"><span class="progress-dot"></span>Wilcoxon, Mann-Whitney & Kruskal-Wallis</a></li><li data-subkey="sec3sub3"><a href="/Multiple-Comparisons-in-R.html"><span class="progress-dot"></span>Multiple Testing Correction</a></li><li data-subkey="sec3sub3"><a href="/Hypothesis-Testing-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Hypothesis Testing Quiz</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec3sub4" data-collapsed="false"><span class="subsec-chevron">▼</span> Regression</li><li data-subkey="sec3sub4"><a href="/Linear-Regression.html"><span class="progress-dot"></span>Linear Regression</a></li><li data-subkey="sec3sub4"><a href="/Logistic-Regression-With-R.html"><span class="progress-dot"></span>Logistic Regression</a></li><li data-subkey="sec3sub4"><a href="/Variable-Selection-and-Importance-With-R.html"><span class="progress-dot"></span>Feature Selection</a></li><li data-subkey="sec3sub4"><a href="/Model-Selection-in-R.html"><span class="progress-dot"></span>Model Selection</a></li><li data-subkey="sec3sub4"><a href="/Missing-Value-Treatment-With-R.html"><span class="progress-dot"></span>Missing Value Treatment</a></li><li data-subkey="sec3sub4"><a href="/Outlier-Treatment-With-R.html"><span class="progress-dot"></span>Outlier Analysis</a></li><li data-subkey="sec3sub4"><a href="/adv-regression-models.html"><span class="progress-dot"></span>Advanced Regression Models</a></li><li data-subkey="sec3sub4"><a href="/Linear-Regression-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Linear Regression Quiz</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec3sub5" data-collapsed="false"><span class="subsec-chevron">▼</span> Reporting</li><li data-subkey="sec3sub5"><a href="/Statistical-Consulting-in-R.html"><span class="progress-dot"></span>Statistical Consulting</a></li><li data-subkey="sec3sub5"><a href="/Statistical-Report-Writing-in-R.html"><span class="progress-dot"></span>Statistical Report Writing</a></li><li data-subkey="sec3sub5"><a href="/Bootstrap-Confidence-Intervals-in-R.html"><span class="progress-dot"></span>Bootstrap Confidence Intervals</a></li><li data-subkey="sec3sub5"><a href="/Reporting-Statistics-in-R.html"><span class="progress-dot"></span>Reporting Statistics</a></li><li data-subkey="sec3sub5"><a href="/Correlation-in-R.html"><span class="progress-dot"></span>Correlation (Pearson, Spearman, Kendall)</a></li><li data-subkey="sec3sub5"><a href="/Linear-Regression-Assumptions-in-R.html"><span class="progress-dot"></span>Linear Regression Assumptions</a></li><li data-subkey="sec3sub5"><a href="/Dummy-Variables-in-R.html"><span class="progress-dot"></span>Dummy Variables in R</a></li><li data-subkey="sec3sub5"><a href="/Interaction-Effects-in-R.html"><span class="progress-dot"></span>Interaction Effects</a></li><li data-subkey="sec3sub5"><a href="/Regression-Diagnostics-in-R.html"><span class="progress-dot"></span>Regression Diagnostics</a></li><li data-subkey="sec3sub5"><a href="/Logistic-Regression-in-R.html"><span class="progress-dot"></span>Logistic Regression (glm + ROC)</a></li><li data-subkey="sec3sub5"><a href="/Variable-Selection-in-R.html"><span class="progress-dot"></span>Variable Selection</a></li><li data-subkey="sec3sub5"><a href="/Poisson-Regression-in-R.html"><span class="progress-dot"></span>Poisson Regression</a></li><li data-subkey="sec3sub5"><a href="/Ridge-and-Lasso-Regression-in-R.html"><span class="progress-dot"></span>Ridge & Lasso Regression</a></li><li data-subkey="sec3sub5"><a href="/Polynomial-and-Spline-Regression-in-R.html"><span class="progress-dot"></span>Polynomial & Splines</a></li><li data-subkey="sec3sub5"><a href="/Regression-Tables-in-R.html"><span class="progress-dot"></span>Regression Tables (3 packages)</a></li><li data-subkey="sec3sub5"><a href="/One-Way-ANOVA-in-R.html"><span class="progress-dot"></span>One-Way ANOVA</a></li><li data-subkey="sec3sub5"><a href="/Post-Hoc-Tests-After-ANOVA.html"><span class="progress-dot"></span>Post-Hoc Tests After ANOVA</a></li><li data-subkey="sec3sub5"><a href="/Two-Way-ANOVA-in-R.html"><span class="progress-dot"></span>Two-Way ANOVA</a></li><li data-subkey="sec3sub5"><a href="/Repeated-Measures-ANOVA-in-R.html"><span class="progress-dot"></span>Repeated Measures ANOVA</a></li><li data-subkey="sec3sub5"><a href="/ANCOVA-in-R.html"><span class="progress-dot"></span>ANCOVA</a></li><li data-subkey="sec3sub5"><a href="/Experimental-Design-Principles-in-R.html"><span class="progress-dot"></span>Experimental Design in R</a></li><li data-subkey="sec3sub5"><a href="/Factorial-Experiments-in-R.html"><span class="progress-dot"></span>Factorial Designs (2^k)</a></li><li data-subkey="sec3sub5"><a href="/AB-Testing-in-R.html"><span class="progress-dot"></span>A/B Testing</a></li><li data-subkey="sec3sub5"><a href="/MANOVA-in-R.html"><span class="progress-dot"></span>MANOVA</a></li><li data-subkey="sec3sub5"><a href="/Mixed-ANOVA-in-R.html"><span class="progress-dot"></span>Mixed ANOVA</a></li><li data-subkey="sec3sub5"><a href="/Multivariate-Statistics-in-R.html"><span class="progress-dot"></span>Multivariate Distances & Hotelling's T²</a></li><li data-subkey="sec3sub5"><a href="/PCA-in-R.html"><span class="progress-dot"></span>PCA with prcomp()</a></li><li data-subkey="sec3sub5"><a href="/Interpreting-PCA-Results-in-R.html"><span class="progress-dot"></span>Interpreting PCA Output</a></li><li data-subkey="sec3sub5"><a href="/Exploratory-Factor-Analysis-in-R.html"><span class="progress-dot"></span>Exploratory Factor Analysis</a></li><li data-subkey="sec3sub5"><a href="/CFA-and-Structural-Equation-Modeling-in-R.html"><span class="progress-dot"></span>SEM and CFA (lavaan)</a></li><li data-subkey="sec3sub5"><a href="/Linear-Discriminant-Analysis-in-R.html"><span class="progress-dot"></span>LDA (Linear Discriminant Analysis)</a></li><li data-subkey="sec3sub5"><a href="/Cluster-Analysis-in-R.html"><span class="progress-dot"></span>Clustering (k-Means / HC / DBSCAN)</a></li><li data-subkey="sec3sub5"><a href="/Correspondence-Analysis-in-R.html"><span class="progress-dot"></span>Correspondence Analysis</a></li><li data-subkey="sec3sub5"><a href="/t-SNE-and-UMAP-in-R.html"><span class="progress-dot"></span>t-SNE and UMAP</a></li><li data-subkey="sec3sub5"><a href="/Simple-Linear-Regression-in-R.html"><span class="progress-dot"></span>Simple Linear Regression</a></li><li data-subkey="sec3sub5"><a href="/Multiple-Regression-in-R.html"><span class="progress-dot"></span>Multiple Regression</a></li><li data-subkey="sec3sub5"><a href="/Robust-Regression-in-R.html"><span class="progress-dot"></span>Robust Regression (rlm)</a></li><li data-subkey="sec3sub5"><a href="/factoextra-and-FactoMineR.html"><span class="progress-dot"></span>factoextra (PCA + Clusters)</a></li><li data-subkey="sec3sub5"><a href="/Categorical-Data-in-R.html"><span class="progress-dot"></span>Categorical Data (Tables & Mosaic)</a></li><li data-subkey="sec3sub5"><a href="/Chi-Square-Test-of-Independence-in-R.html"><span class="progress-dot"></span>Chi-Square Test of Independence</a></li><li data-subkey="sec3sub5"><a href="/Chi-Square-Goodness-of-Fit-Test-in-R.html"><span class="progress-dot"></span>Chi-Square Goodness-of-Fit</a></li><li data-subkey="sec3sub5"><a href="/Fishers-Exact-Test-in-R.html"><span class="progress-dot"></span>Fisher's Exact Test</a></li><li data-subkey="sec3sub5"><a href="/Odds-Ratios-and-Relative-Risk-in-R.html"><span class="progress-dot"></span>Odds Ratios & Relative Risk</a></li><li data-subkey="sec3sub5"><a href="/Logistic-Regression-in-R-2.html"><span class="progress-dot"></span>Logistic Regression (Diagnostics)</a></li><li data-subkey="sec3sub5"><a href="/Poisson-and-Negative-Binomial-Regression.html"><span class="progress-dot"></span>Poisson & Negative Binomial Regression</a></li><li data-subkey="sec3sub5"><a href="/Multinomial-and-Ordinal-Logistic-Regression-in-R.html"><span class="progress-dot"></span>Multinomial & Ordinal Logistic Regression</a></li><li data-subkey="sec3sub5"><a href="/When-to-Use-Nonparametric-Tests-in-R.html"><span class="progress-dot"></span>When to Use Nonparametric Tests</a></li><li data-subkey="sec3sub5"><a href="/Wilcoxon-Signed-Rank-Test-in-R.html"><span class="progress-dot"></span>Wilcoxon Signed-Rank Test</a></li><li data-subkey="sec3sub5"><a href="/Mann-Whitney-U-Test-in-R.html"><span class="progress-dot"></span>Mann-Whitney U Test</a></li><li data-subkey="sec3sub5"><a href="/Kruskal-Wallis-Test-in-R-2.html"><span class="progress-dot"></span>Kruskal-Wallis Test</a></li><li data-subkey="sec3sub5"><a href="/Friedman-Test-in-R.html"><span class="progress-dot"></span>Friedman Test</a></li><li data-subkey="sec3sub5"><a href="/Spearman-and-Kendall-Correlation-in-R.html"><span class="progress-dot"></span>Spearman & Kendall Correlation</a></li><li data-subkey="sec3sub5"><a href="/Bootstrap-in-R.html"><span class="progress-dot"></span>Bootstrap (boot package)</a></li><li data-subkey="sec3sub5"><a href="/Quantile-Regression-in-R-2.html"><span class="progress-dot"></span>Quantile Regression</a></li><li data-subkey="sec3sub5"><a href="/Matrix-Operations-in-R.html"><span class="progress-dot"></span>Matrix Operations in R</a></li><li data-subkey="sec3sub5"><a href="/Solving-Linear-Systems-in-R.html"><span class="progress-dot"></span>Solving Linear Systems in R</a></li><li data-subkey="sec3sub5"><a href="/Eigenvalues-and-Eigenvectors-in-R.html"><span class="progress-dot"></span>Eigenvalues & Eigenvectors in R</a></li><li data-subkey="sec3sub5"><a href="/Singular-Value-Decomposition-in-R.html"><span class="progress-dot"></span>Singular Value Decomposition in R</a></li><li data-subkey="sec3sub5"><a href="/Projections-and-the-Hat-Matrix-in-R.html"><span class="progress-dot"></span>Projections & the Hat Matrix</a></li><li data-subkey="sec3sub5"><a href="/QR-Decomposition-in-R.html"><span class="progress-dot"></span>QR Decomposition in R</a></li><li data-subkey="sec3sub5"><a href="/Quadratic-Forms-in-R.html"><span class="progress-dot"></span>Quadratic Forms</a></li><li data-subkey="sec3sub5"><a href="/Matrix-Derivatives-and-the-Hessian-in-R.html"><span class="progress-dot"></span>Matrix Derivatives & Hessian</a></li><li data-subkey="sec3sub5"><a href="/Exponential-Family-Distributions-in-R.html"><span class="progress-dot"></span>Exponential Family Distributions</a></li><li data-subkey="sec3sub5"><a href="/Sufficient-Statistics-in-R.html"><span class="progress-dot"></span>Sufficient Statistics</a></li><li data-subkey="sec3sub5"><a href="/Complete-and-Ancillary-Statistics-in-R.html"><span class="progress-dot"></span>Complete & Ancillary Statistics</a></li><li data-subkey="sec3sub5"><a href="/UMVUE-in-R-2.html"><span class="progress-dot"></span>UMVUE (Rao-Blackwell & Lehmann-Scheffé)</a></li><li data-subkey="sec3sub5"><a href="/Cramer-Rao-Lower-Bound-in-R-2.html"><span class="progress-dot"></span>Cramér-Rao Lower Bound</a></li><li data-subkey="sec3sub5"><a href="/Asymptotic-Theory-in-R-2.html"><span class="progress-dot"></span>Asymptotic Theory</a></li><li data-subkey="sec3sub5"><a href="/Neyman-Pearson-Lemma-in-R-2.html"><span class="progress-dot"></span>Neyman-Pearson Lemma</a></li><li data-subkey="sec3sub5"><a href="/Likelihood-Ratio-Tests-and-Pivotal-Methods.html"><span class="progress-dot"></span>Likelihood Ratio & Pivotal Methods</a></li><li data-subkey="sec3sub5"><a href="/Decision-Theory-in-R.html"><span class="progress-dot"></span>Decision Theory</a></li><li data-subkey="sec3sub5"><a href="/Asymptotic-Relative-Efficiency-in-R.html"><span class="progress-dot"></span>Asymptotic Relative Efficiency</a></li><li data-subkey="sec3sub5"><a href="/Bayes-Theorem-in-R.html"><span class="progress-dot"></span>Bayes' Theorem</a></li><li data-subkey="sec3sub5"><a href="/Bayesian-Statistics-in-R.html" class="active"><span class="progress-dot"></span>Bayesian Statistics</a></li><li data-subkey="sec3sub5"><a href="/Conjugate-Priors-in-R.html"><span class="progress-dot"></span>Conjugate Priors</a></li><li data-subkey="sec3sub5"><a href="/Grid-Approximation-in-R.html"><span class="progress-dot"></span>Grid Approximation</a></li><li data-subkey="sec3sub5"><a href="/MCMC-in-R.html"><span class="progress-dot"></span>MCMC in R</a></li><li data-subkey="sec3sub5"><a href="/Gibbs-Sampling-in-R.html"><span class="progress-dot"></span>Gibbs Sampling</a></li><li data-subkey="sec3sub5"><a href="/Hamiltonian-Monte-Carlo-in-R.html"><span class="progress-dot"></span>Hamiltonian Monte Carlo</a></li><li data-subkey="sec3sub5"><a href="/Stan-in-R.html"><span class="progress-dot"></span>Stan</a></li><li data-subkey="sec3sub5"><a href="/brms-in-R.html"><span class="progress-dot"></span>brms</a></li><li data-subkey="sec3sub5"><a href="/Choosing-Priors-in-R.html"><span class="progress-dot"></span>Choosing Priors</a></li><li data-subkey="sec3sub5"><a href="/Prior-Predictive-Checks-in-R.html"><span class="progress-dot"></span>Prior Predictive Checks</a></li><li data-subkey="sec3sub5"><a href="/Compare-Bayesian-Models-in-R.html"><span class="progress-dot"></span>Compare Bayesian Models</a></li><li data-subkey="sec3sub5"><a href="/Posterior-Predictive-Checks-in-R.html"><span class="progress-dot"></span>Posterior Predictive Checks</a></li><li data-subkey="sec3sub5"><a href="/Bayesian-Linear-Regression-in-R.html"><span class="progress-dot"></span>Bayesian Linear Regression</a></li><li data-subkey="sec3sub5"><a href="/Bayesian-Logistic-Regression-in-R.html"><span class="progress-dot"></span>Bayesian Logistic Regression</a></li><li data-subkey="sec3sub5"><a href="/Bayesian-Hierarchical-Models-in-R.html"><span class="progress-dot"></span>Bayesian Hierarchical Models</a></li><li data-subkey="sec3sub5"><a href="/Multilevel-Models-in-R.html"><span class="progress-dot"></span>Multilevel Models</a></li><li data-subkey="sec3sub5"><a href="/Bayesian-ANOVA-in-R.html"><span class="progress-dot"></span>Bayesian ANOVA</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec3sub6" data-collapsed="false"><span class="subsec-chevron">▼</span> Machine Learning</li><li data-subkey="sec3sub6"><a href="/Machine-Learning-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Machine Learning Quiz</a></li></ul></li><li class="sidebar-section"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Time Series<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li data-subkey="sec4sub0"><a href="/Time-Series-Analysis-With-R.html"><span class="progress-dot"></span>Time Series Analysis</a></li><li data-subkey="sec4sub0"><a href="/Time-Series-Forecasting-With-R.html"><span class="progress-dot"></span>Time Series Forecasting</a></li><li data-subkey="sec4sub0"><a href="/Time-Series-Forecasting-With-R-part2.html"><span class="progress-dot"></span>More Time Series Forecasting</a></li><li data-subkey="sec4sub0"><a href="/Time-Series-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Time Series Quiz</a></li></ul></li><li class="sidebar-section"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Advanced R<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec5sub1" data-collapsed="false"><span class="subsec-chevron">▼</span> Functional Programming</li><li data-subkey="sec5sub1"><a href="/Functional-Programming-in-R.html"><span class="progress-dot"></span>Functional Programming</a></li><li data-subkey="sec5sub1"><a href="/R-Functional-Programming-Exercises-quiz.html"><span class="progress-dot"></span>Functional Programming Quiz</a></li><li data-subkey="sec5sub1"><a href="/purrr-map-Variants.html"><span class="progress-dot"></span>purrr map() Variants</a></li><li data-subkey="sec5sub1"><a href="/R-Anonymous-Functions.html"><span class="progress-dot"></span>R Anonymous Functions</a></li><li data-subkey="sec5sub1"><a href="/R-Function-Factories.html"><span class="progress-dot"></span>R Function Factories</a></li><li data-subkey="sec5sub1"><a href="/R-Function-Operators.html"><span class="progress-dot"></span>R Function Operators</a></li><li data-subkey="sec5sub1"><a href="/Reduce-Filter-Map-in-R.html"><span class="progress-dot"></span>Reduce, Filter, Map</a></li><li data-subkey="sec5sub1"><a href="/Memoization-in-R.html"><span class="progress-dot"></span>Memoization in R</a></li><li data-subkey="sec5sub1"><a href="/Writing-Composable-R-Code.html"><span class="progress-dot"></span>Composable R Code</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec5sub2" data-collapsed="false"><span class="subsec-chevron">▼</span> OOP in R</li><li data-subkey="sec5sub2"><a href="/OOP-in-R.html"><span class="progress-dot"></span>OOP in R: S3/S4/R6</a></li><li data-subkey="sec5sub2"><a href="/S3-Classes-in-R.html"><span class="progress-dot"></span>S3 Classes</a></li><li data-subkey="sec5sub2"><a href="/S3-Method-Dispatch-in-R.html"><span class="progress-dot"></span>S3 Method Dispatch</a></li><li data-subkey="sec5sub2"><a href="/S4-Classes-in-R.html"><span class="progress-dot"></span>S4 Classes</a></li><li data-subkey="sec5sub2"><a href="/S4-Methods-in-R.html"><span class="progress-dot"></span>S4 Methods & Dispatch</a></li><li data-subkey="sec5sub2"><a href="/R6-Classes-in-R.html"><span class="progress-dot"></span>R6 Classes</a></li><li data-subkey="sec5sub2"><a href="/R6-Advanced.html"><span class="progress-dot"></span>R6 Advanced</a></li><li data-subkey="sec5sub2"><a href="/Operator-Overloading-in-R.html"><span class="progress-dot"></span>Operator Overloading</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec5sub3" data-collapsed="false"><span class="subsec-chevron">▼</span> How R Works</li><li data-subkey="sec5sub3"><a href="/R-Names-and-Values.html"><span class="progress-dot"></span>R Names & Values</a></li><li data-subkey="sec5sub3"><a href="/R-Assignment-Deep-Dive.html"><span class="progress-dot"></span>R Assignment Deep Dive</a></li><li data-subkey="sec5sub3"><a href="/R-Memory-lobstr.html"><span class="progress-dot"></span>R Memory & lobstr</a></li><li data-subkey="sec5sub3"><a href="/R-Environments.html"><span class="progress-dot"></span>R Environments</a></li><li data-subkey="sec5sub3"><a href="/R-Lexical-Scoping.html"><span class="progress-dot"></span>Lexical Scoping</a></li><li data-subkey="sec5sub3"><a href="/R-Closures.html"><span class="progress-dot"></span>R Closures</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec5sub4" data-collapsed="false"><span class="subsec-chevron">▼</span> Debugging & Performance</li><li data-subkey="sec5sub4"><a href="/R-Conditions-System.html"><span class="progress-dot"></span>Conditions System</a></li><li data-subkey="sec5sub4"><a href="/R-Debugging.html"><span class="progress-dot"></span>Debugging R Code</a></li><li data-subkey="sec5sub4"><a href="/R-Common-Errors.html"><span class="progress-dot"></span>50 Common R Errors</a></li><li data-subkey="sec5sub4"><a href="/Parallel-Computing-With-R.html"><span class="progress-dot"></span>Parallel Computing</a></li><li data-subkey="sec5sub4"><a href="/Strategies-To-Improve-And-Speedup-R-Code.html"><span class="progress-dot"></span>Speedup R Code</a></li><li data-subkey="sec5sub4"><a href="/Shiny-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Shiny Quiz</a></li></ul></li><li class="sidebar-section"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Classic Tutorials<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li data-subkey="sec6sub0"><a href="/R-Tutorial.html"><span class="progress-dot"></span>R Tutorial (Classic)</a></li><li data-subkey="sec6sub0"><a href="/ggplot2-Tutorial-With-R.html"><span class="progress-dot"></span>ggplot2 Short Tutorial</a></li><li data-subkey="sec6sub0"><a href="/Complete-Ggplot2-Tutorial-Part1-With-R-Code.html"><span class="progress-dot"></span>ggplot2 Tutorial 1 - Intro</a></li><li data-subkey="sec6sub0"><a href="/Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html"><span class="progress-dot"></span>ggplot2 Tutorial 2 - Theme</a></li><li data-subkey="sec6sub0"><a href="/Top50-Ggplot2-Visualizations-MasterList-R-Code.html"><span class="progress-dot"></span>ggplot2 Tutorial 3 - Masterlist</a></li><li data-subkey="sec6sub0"><a href="/Association-Mining-With-R.html"><span class="progress-dot"></span>Association Mining</a></li><li data-subkey="sec6sub0"><a href="/Multi-Dimensional-Scaling-With-R.html"><span class="progress-dot"></span>Multi Dimensional Scaling</a></li><li data-subkey="sec6sub0"><a href="/Optimization-With-R.html"><span class="progress-dot"></span>Optimization</a></li><li data-subkey="sec6sub0"><a href="/Information-Value-With-R.html"><span class="progress-dot"></span>InformationValue Package</a></li></ul></li><li class="sidebar-section"><div class="sidebar-section-header"><span class="sidebar-chevron">▸</span> Practice Exercises<span class="section-meta" data-section-meta></span></div><ul class="sidebar-section-items list-unstyled"><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec7sub1" data-collapsed="false"><span class="subsec-chevron">▼</span> Mastery Quizzes (Certificate)</li><li data-subkey="sec7sub1"><a href="/R-Beginner-Exercises-quiz.html"><span class="progress-dot"></span>R Fundamentals Quiz</a></li><li data-subkey="sec7sub1"><a href="/dplyr-Exercises-in-R-quiz.html"><span class="progress-dot"></span>dplyr Quiz</a></li><li data-subkey="sec7sub1"><a href="/ggplot2-Exercises-in-R-quiz.html"><span class="progress-dot"></span>ggplot2 Quiz</a></li><li data-subkey="sec7sub1"><a href="/Hypothesis-Testing-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Hypothesis Testing Quiz</a></li><li data-subkey="sec7sub1"><a href="/Linear-Regression-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Linear Regression Quiz</a></li><li data-subkey="sec7sub1"><a href="/Machine-Learning-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Machine Learning Quiz</a></li><li data-subkey="sec7sub1"><a href="/tidyr-Exercises-in-R-quiz.html"><span class="progress-dot"></span>tidyr Quiz</a></li><li data-subkey="sec7sub1"><a href="/Time-Series-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Time Series Quiz</a></li><li data-subkey="sec7sub1"><a href="/Shiny-Exercises-in-R-quiz.html"><span class="progress-dot"></span>Shiny Quiz</a></li><li data-subkey="sec7sub1"><a href="/R-Interview-Questions-quiz.html"><span class="progress-dot"></span>R Interview Readiness Quiz</a></li><li data-subkey="sec7sub1"><a href="/R-Functional-Programming-Exercises-quiz.html"><span class="progress-dot"></span>Functional Programming Quiz</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec7sub2" data-collapsed="false"><span class="subsec-chevron">▼</span> R Fundamentals</li><li data-subkey="sec7sub2"><a href="/R-Basics-Exercises.html"><span class="progress-dot"></span>R Basics (15 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Vectors-Exercises.html"><span class="progress-dot"></span>R Vectors (12 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Data-Frames-Exercises.html"><span class="progress-dot"></span>R Data Frames (15 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Lists-Exercises.html"><span class="progress-dot"></span>R Lists (10 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Control-Flow-Exercises.html"><span class="progress-dot"></span>R Control Flow (12 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Functions-Exercises.html"><span class="progress-dot"></span>R Functions (10 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-String-Exercises.html"><span class="progress-dot"></span>R Strings (10 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Date-Time-Exercises.html"><span class="progress-dot"></span>R Date & Time (10 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Apply-Exercises.html"><span class="progress-dot"></span>R apply Family (12 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Subsetting-Exercises.html"><span class="progress-dot"></span>R Subsetting (10 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-Functional-Programming-Exercises.html"><span class="progress-dot"></span>Functional Programming (10 problems)</a></li><li data-subkey="sec7sub2"><a href="/R-OOP-Exercises.html"><span class="progress-dot"></span>OOP in R (8 problems)</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec7sub3" data-collapsed="false"><span class="subsec-chevron">▼</span> Data Wrangling</li><li data-subkey="sec7sub3"><a href="/R-Data-Import-Exercises.html"><span class="progress-dot"></span>Data Import (10 problems)</a></li><li data-subkey="sec7sub3"><a href="/dplyr-Exercises.html"><span class="progress-dot"></span>dplyr (15 problems)</a></li><li data-subkey="sec7sub3"><a href="/dplyr-filter-select-Exercises.html"><span class="progress-dot"></span>dplyr filter() & select() (12 problems)</a></li><li data-subkey="sec7sub3"><a href="/dplyr-group-by-summarise-Exercises.html"><span class="progress-dot"></span>dplyr group_by() & summarise() (10 problems)</a></li><li data-subkey="sec7sub3"><a href="/dplyr-Join-Exercises.html"><span class="progress-dot"></span>dplyr Joins (10 problems)</a></li><li data-subkey="sec7sub3"><a href="/data-table-Exercises.html"><span class="progress-dot"></span>data.table (12 problems)</a></li><li data-subkey="sec7sub3"><a href="/purrr-Exercises.html"><span class="progress-dot"></span>purrr (10 problems)</a></li><li data-subkey="sec7sub3"><a href="/tidyr-Reshaping-Exercises.html"><span class="progress-dot"></span>tidyr Reshaping (10 problems)</a></li><li data-subkey="sec7sub3"><a href="/Missing-Data-in-R-Exercises.html"><span class="progress-dot"></span>Missing Data in R (10 problems)</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec7sub4" data-collapsed="false"><span class="subsec-chevron">▼</span> Visualization</li><li data-subkey="sec7sub4"><a href="/ggplot2-Exercises.html"><span class="progress-dot"></span>ggplot2 (15 problems)</a></li><li data-subkey="sec7sub4"><a href="/ggplot2-Geom-Exercises.html"><span class="progress-dot"></span>ggplot2 Geoms (12 problems)</a></li><li data-subkey="sec7sub4"><a href="/ggplot2-Aesthetics-Exercises.html"><span class="progress-dot"></span>ggplot2 Aesthetics (10 problems)</a></li><li data-subkey="sec7sub4"><a href="/ggplot2-Customization-Exercises.html"><span class="progress-dot"></span>ggplot2 Customization (10 problems)</a></li><li data-subkey="sec7sub4"><a href="/ggplot2-Facet-Exercises.html"><span class="progress-dot"></span>ggplot2 Facets (8 problems)</a></li><li data-subkey="sec7sub4"><a href="/R-Visualization-Project.html"><span class="progress-dot"></span>R Visualization Project (5 charts)</a></li><li class="sidebar-divider sidebar-subsection-toggle" data-subkey="sec7sub5" data-collapsed="false"><span class="subsec-chevron">▼</span> Statistics</li><li data-subkey="sec7sub5"><a href="/Probability-in-R-Exercises.html"><span class="progress-dot"></span>Probability in R Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-Probability-Distributions-Exercises.html"><span class="progress-dot"></span>R Probability Distributions (12 problems)</a></li><li data-subkey="sec7sub5"><a href="/Binomial-Distribution-Exercises-in-R.html"><span class="progress-dot"></span>Binomial Distribution Exercises</a></li><li data-subkey="sec7sub5"><a href="/Poisson-Distribution-Exercises-in-R.html"><span class="progress-dot"></span>Poisson Distribution Exercises</a></li><li data-subkey="sec7sub5"><a href="/Central-Limit-Theorem-Exercises-in-R.html"><span class="progress-dot"></span>Central Limit Theorem Exercises</a></li><li data-subkey="sec7sub5"><a href="/Hypothesis-Testing-Exercises-in-R.html"><span class="progress-dot"></span>Hypothesis Testing Exercises</a></li><li data-subkey="sec7sub5"><a href="/t-Test-Exercises-in-R.html"><span class="progress-dot"></span>t-Test Exercises (12 problems)</a></li><li data-subkey="sec7sub5"><a href="/Chi-Square-Test-Exercises-in-R.html"><span class="progress-dot"></span>Chi-Square Exercises (10 problems)</a></li><li data-subkey="sec7sub5"><a href="/Confidence-Interval-Exercises-in-R.html"><span class="progress-dot"></span>Confidence Interval (10 problems)</a></li><li data-subkey="sec7sub5"><a href="/Power-Analysis-Exercises-in-R.html"><span class="progress-dot"></span>Power Analysis Exercises (8 problems)</a></li><li data-subkey="sec7sub5"><a href="/Nonparametric-Tests-Exercises-in-R.html"><span class="progress-dot"></span>Nonparametric Exercises (10 problems)</a></li><li data-subkey="sec7sub5"><a href="/Multiple-Testing-Exercises-in-R.html"><span class="progress-dot"></span>Multiple Testing (8 problems)</a></li><li data-subkey="sec7sub5"><a href="/Multiple-Regression-Exercises-in-R.html"><span class="progress-dot"></span>Multiple Regression Exercises</a></li><li data-subkey="sec7sub5"><a href="/Logistic-Regression-Exercises-in-R.html"><span class="progress-dot"></span>Logistic Regression Exercises (10 problems)</a></li><li data-subkey="sec7sub5"><a href="/Regression-Diagnostics-Exercises-in-R.html"><span class="progress-dot"></span>Regression Diagnostics Exercises</a></li><li data-subkey="sec7sub5"><a href="/Ridge-and-Lasso-Exercises-in-R.html"><span class="progress-dot"></span>Ridge & Lasso Exercises</a></li><li data-subkey="sec7sub5"><a href="/GLM-Exercises-in-R.html"><span class="progress-dot"></span>GLM Exercises (10 problems)</a></li><li data-subkey="sec7sub5"><a href="/ANOVA-Exercises-in-R.html"><span class="progress-dot"></span>ANOVA Exercises (15 problems)</a></li><li data-subkey="sec7sub5"><a href="/Post-Hoc-Tests-Exercises-in-R.html"><span class="progress-dot"></span>Post-Hoc Tests Exercises (8 problems)</a></li><li data-subkey="sec7sub5"><a href="/Repeated-Measures-Exercises-in-R.html"><span class="progress-dot"></span>Repeated Measures (8 problems)</a></li><li data-subkey="sec7sub5"><a href="/Experimental-Design-Exercises-in-R.html"><span class="progress-dot"></span>Experimental Design Exercises (8 problems)</a></li><li data-subkey="sec7sub5"><a href="/AB-Testing-Exercises-in-R.html"><span class="progress-dot"></span>A/B Testing Exercises (8 problems)</a></li><li data-subkey="sec7sub5"><a href="/Linear-Regression-Exercises-in-R.html"><span class="progress-dot"></span>Linear Regression (15 problems)</a></li><li data-subkey="sec7sub5"><a href="/PCA-Exercises-in-R.html"><span class="progress-dot"></span>PCA Exercises (10 problems)</a></li><li data-subkey="sec7sub5"><a href="/Cluster-Analysis-Exercises-in-R.html"><span class="progress-dot"></span>Clustering Exercises (10 problems)</a></li><li data-subkey="sec7sub5"><a href="/SEM-Exercises-in-R.html"><span class="progress-dot"></span>SEM Exercises (8 problems)</a></li><li data-subkey="sec7sub5"><a href="/A-B-Testing-Exercises-in-R.html"><span class="progress-dot"></span>A/B Testing Exercises</a></li><li data-subkey="sec7sub5"><a href="/API-Calls-Exercises-in-R.html"><span class="progress-dot"></span>API Calls Exercises</a></li><li data-subkey="sec7sub5"><a href="/ARIMA-Exercises-in-R.html"><span class="progress-dot"></span>ARIMA Exercises</a></li><li data-subkey="sec7sub5"><a href="/Apply-Family-Exercises-in-R.html"><span class="progress-dot"></span>Apply Family Exercises</a></li><li data-subkey="sec7sub5"><a href="/Bayesian-Statistics-Exercises-in-R.html"><span class="progress-dot"></span>Bayesian Statistics Exercises</a></li><li data-subkey="sec7sub5"><a href="/Clustering-Exercises-in-R.html"><span class="progress-dot"></span>Clustering Exercises</a></li><li data-subkey="sec7sub5"><a href="/Correlation-Exercises-in-R.html"><span class="progress-dot"></span>Correlation Exercises</a></li><li data-subkey="sec7sub5"><a href="/Cross-Validation-Exercises-in-R.html"><span class="progress-dot"></span>Cross Validation Exercises</a></li><li data-subkey="sec7sub5"><a href="/Data-Cleaning-Exercises-in-R.html"><span class="progress-dot"></span>Data Cleaning Exercises</a></li><li data-subkey="sec7sub5"><a href="/Data-Visualization-Exercises-in-R.html"><span class="progress-dot"></span>Data Viz Exercises</a></li><li data-subkey="sec7sub5"><a href="/Data-Wrangling-Exercises-in-R.html"><span class="progress-dot"></span>Data Wrangling Exercises</a></li><li data-subkey="sec7sub5"><a href="/Decision-Tree-Exercises-in-R.html"><span class="progress-dot"></span>Decision Tree Exercises</a></li><li data-subkey="sec7sub5"><a href="/EDA-Exercises-in-R.html"><span class="progress-dot"></span>EDA Exercises</a></li><li data-subkey="sec7sub5"><a href="/GAM-Exercises-in-R.html"><span class="progress-dot"></span>GAM Exercises</a></li><li data-subkey="sec7sub5"><a href="/Machine-Learning-Exercises-in-R.html"><span class="progress-dot"></span>Machine Learning Exercises</a></li><li data-subkey="sec7sub5"><a href="/Mixed-Effects-Models-Exercises-in-R.html"><span class="progress-dot"></span>Mixed Effects Exercises</a></li><li data-subkey="sec7sub5"><a href="/Network-Analysis-Exercises-in-R.html"><span class="progress-dot"></span>Network Analysis Exercises</a></li><li data-subkey="sec7sub5"><a href="/Parallel-Computing-in-R-Exercises.html"><span class="progress-dot"></span>Parallel Computing Exercises</a></li><li data-subkey="sec7sub5"><a href="/Poisson-Regression-Exercises-in-R.html"><span class="progress-dot"></span>Poisson Regression</a></li><li data-subkey="sec7sub5"><a href="/Probability-Distributions-Exercises-in-R.html"><span class="progress-dot"></span>Probability Distributions</a></li><li data-subkey="sec7sub5"><a href="/R-Beginner-Exercises.html"><span class="progress-dot"></span>R Beginner Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-Debugging-Exercises.html"><span class="progress-dot"></span>R Debugging Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-Markdown-Exercises.html"><span class="progress-dot"></span>R Markdown Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-Package-Development-Exercises.html"><span class="progress-dot"></span>R Package Development</a></li><li data-subkey="sec7sub5"><a href="/R-Performance-Optimization-Exercises.html"><span class="progress-dot"></span>R Performance Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-for-Biostatistics-Exercises.html"><span class="progress-dot"></span>R for Biostatistics</a></li><li data-subkey="sec7sub5"><a href="/R-for-Data-Science-Exercises.html"><span class="progress-dot"></span>R for Data Science Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-for-Finance-Exercises.html"><span class="progress-dot"></span>R for Finance Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-for-Genomics-Exercises.html"><span class="progress-dot"></span>R for Genomics</a></li><li data-subkey="sec7sub5"><a href="/R-for-Healthcare-Exercises.html"><span class="progress-dot"></span>R for Healthcare Exercises</a></li><li data-subkey="sec7sub5"><a href="/R-for-Marketing-Analytics-Exercises.html"><span class="progress-dot"></span>R for Marketing Analytics</a></li><li data-subkey="sec7sub5"><a href="/R-for-Sports-Analytics-Exercises.html"><span class="progress-dot"></span>R for Sports Analytics</a></li><li data-subkey="sec7sub5"><a href="/Random-Forest-Exercises-in-R.html"><span class="progress-dot"></span>Random Forest Exercises</a></li><li data-subkey="sec7sub5"><a href="/Regex-Exercises-in-R.html"><span class="progress-dot"></span>Regex Exercises</a></li><li data-subkey="sec7sub5"><a href="/Sampling-Methods-Exercises-in-R.html"><span class="progress-dot"></span>Sampling Methods Exercises</a></li><li data-subkey="sec7sub5"><a href="/Shiny-Exercises-in-R.html"><span class="progress-dot"></span>Shiny Exercises</a></li><li data-subkey="sec7sub5"><a href="/Spatial-Analysis-Exercises-in-R.html"><span class="progress-dot"></span>Spatial Analysis Exercises</a></li><li data-subkey="sec7sub5"><a href="/Survey-Analysis-in-R-Exercises.html"><span class="progress-dot"></span>Survey Analysis Exercises</a></li><li data-subkey="sec7sub5"><a href="/Survival-Analysis-Exercises-in-R.html"><span class="progress-dot"></span>Survival Analysis Exercises</a></li><li data-subkey="sec7sub5"><a href="/Text-Mining-Exercises-in-R.html"><span class="progress-dot"></span>Text Mining Exercises</a></li><li data-subkey="sec7sub5"><a href="/Time-Series-Exercises-in-R.html"><span class="progress-dot"></span>Time Series Exercises</a></li><li data-subkey="sec7sub5"><a href="/Web-Scraping-Exercises-in-R.html"><span class="progress-dot"></span>Web Scraping Exercises</a></li><li data-subkey="sec7sub5"><a href="/XGBoost-Exercises-in-R.html"><span class="progress-dot"></span>XGBoost Exercises</a></li><li data-subkey="sec7sub5"><a href="/broom-Exercises-in-R.html"><span class="progress-dot"></span>broom Exercises</a></li><li data-subkey="sec7sub5"><a href="/caret-Exercises-in-R.html"><span class="progress-dot"></span>caret Exercises</a></li><li data-subkey="sec7sub5"><a href="/data.table-Exercises-in-R.html"><span class="progress-dot"></span>data.table Exercises</a></li><li data-subkey="sec7sub5"><a href="/dbplyr-SQL-Exercises-in-R.html"><span class="progress-dot"></span>dbplyr / SQL Exercises</a></li><li data-subkey="sec7sub5"><a href="/dplyr-Exercises-in-R.html"><span class="progress-dot"></span>dplyr Exercises</a></li><li data-subkey="sec7sub5"><a href="/dplyr-Group-By-Exercises-in-R.html"><span class="progress-dot"></span>dplyr group_by Exercises</a></li><li data-subkey="sec7sub5"><a href="/dplyr-Joins-Exercises-in-R.html"><span class="progress-dot"></span>dplyr Joins Exercises</a></li><li data-subkey="sec7sub5"><a href="/dplyr-Window-Functions-Exercises-in-R.html"><span class="progress-dot"></span>dplyr Window Functions Exercises</a></li><li data-subkey="sec7sub5"><a href="/forcats-Exercises-in-R.html"><span class="progress-dot"></span>forcats Exercises</a></li><li data-subkey="sec7sub5"><a href="/ggplot2-Bar-Chart-Exercises-in-R.html"><span class="progress-dot"></span>ggplot2 Bar Chart Exercises</a></li><li data-subkey="sec7sub5"><a href="/ggplot2-Color-Scales-Exercises-in-R.html"><span class="progress-dot"></span>ggplot2 Color Scales Exercises</a></li><li data-subkey="sec7sub5"><a href="/ggplot2-Exercises-in-R.html"><span class="progress-dot"></span>ggplot2 Exercises</a></li><li data-subkey="sec7sub5"><a href="/ggplot2-Facets-Exercises-in-R.html"><span class="progress-dot"></span>ggplot2 Facets Exercises</a></li><li data-subkey="sec7sub5"><a href="/ggplot2-Heatmap-Exercises-in-R.html"><span class="progress-dot"></span>ggplot2 Heatmap Exercises</a></li><li data-subkey="sec7sub5"><a href="/ggplot2-Themes-Exercises-in-R.html"><span class="progress-dot"></span>ggplot2 Themes Exercises</a></li><li data-subkey="sec7sub5"><a href="/gt-Tables-Exercises-in-R.html"><span class="progress-dot"></span>gt Tables Exercises</a></li><li data-subkey="sec7sub5"><a href="/leaflet-Exercises-in-R.html"><span class="progress-dot"></span>leaflet Exercises</a></li><li data-subkey="sec7sub5"><a href="/lubridate-Exercises-in-R.html"><span class="progress-dot"></span>lubridate Exercises</a></li><li data-subkey="sec7sub5"><a href="/plotly-Exercises-in-R.html"><span class="progress-dot"></span>plotly Exercises</a></li><li data-subkey="sec7sub5"><a href="/purrr-Exercises-in-R.html"><span class="progress-dot"></span>purrr Exercises</a></li><li data-subkey="sec7sub5"><a href="/readr-Exercises-in-R.html"><span class="progress-dot"></span>readr Exercises</a></li><li data-subkey="sec7sub5"><a href="/stringr-Exercises-in-R.html"><span class="progress-dot"></span>stringr Exercises</a></li><li data-subkey="sec7sub5"><a href="/testthat-Exercises-in-R.html"><span class="progress-dot"></span>testthat Exercises</a></li><li data-subkey="sec7sub5"><a href="/tidymodels-Exercises-in-R.html"><span class="progress-dot"></span>tidymodels Exercises</a></li><li data-subkey="sec7sub5"><a href="/tidyr-Exercises-in-R.html"><span class="progress-dot"></span>tidyr Exercises</a></li><li data-subkey="sec7sub5"><a href="/tidyr-Nest-Unnest-Exercises-in-R.html"><span class="progress-dot"></span>tidyr Nest/Unnest Exercises</a></li><li data-subkey="sec7sub5"><a href="/tidyr-Pivot-Exercises-in-R.html"><span class="progress-dot"></span>tidyr Pivot Exercises</a></li><li data-subkey="sec7sub5"><a href="/tidyverse-Exercises-in-R.html"><span class="progress-dot"></span>Tidyverse Exercises</a></li><li data-subkey="sec7sub5"><a href="/Date-Time-Manipulation-Exercises-in-R.html"><span class="progress-dot"></span>Date-Time Manipulation Exercises</a></li><li data-subkey="sec7sub5"><a href="/Loops-vs-Vectorization-Exercises-in-R.html"><span class="progress-dot"></span>Loops vs Vectorization Exercises</a></li></ul></li></ul><div class="sidebar-subscribe"><p>Stay up-to-date. <a href="https://docs.google.com/forms/d/1xkMYkLNFU9U39Dd8S_2JC0p8B5t6_Yq6zUQjanQQJpY/viewform">Subscribe!</a></p><p><a href="https://docs.google.com/forms/d/13GrkCFcNa-TOIllQghsz2SIEbc-YqY9eJX02B19l5Ow/viewform">Chat!</a></p></div></div><div class="sidebar-panel" data-panel="tools"><ul class="sidebar-tools-list list-unstyled"><li class="sidebar-divider"><span class="subsec-chevron">▼</span> Calculators</li><li><a href="/tools/ab-test-calculator.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="3.5" width="4" height="9" rx="0.5"/><rect x="9.5" y="3.5" width="4" height="9" rx="0.5"/></svg></span><span class="tool-label">A/B Test Calculator</span></a></li><li><a href="/tools/t-test-calculator.html"><span class="tool-icon"></span><span class="tool-label">t-Test Calculator</span></a></li><li><a href="/tools/chi-square-calculator.html"><span class="tool-icon"></span><span class="tool-label">Chi-Square Test</span></a></li><li><a href="/tools/confidence-interval-calculator.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 4v8M3.5 4H5M3.5 12H5"/><circle cx="8" cy="8" r="1.4" fill="currentColor" stroke="none"/><path d="M12.5 4v8M12.5 4H11M12.5 12H11"/></svg></span><span class="tool-label">Confidence Interval</span></a></li><li><a href="/tools/bootstrap-ci-calculator.html"><span class="tool-icon"></span><span class="tool-label">Bootstrap CI</span></a></li><li><a href="/tools/effect-size-converter.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 5.5h11M11 3l2.5 2.5L11 8"/><path d="M13.5 10.5h-11M5 8l-2.5 2.5L5 13"/></svg></span><span class="tool-label">Effect Size Converter</span></a></li><li><a href="/tools/power-analysis.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 2L4 9h3.5L7 14l5-7H8.5z"/></svg></span><span class="tool-label">Power Analysis</span></a></li><li><a href="/tools/survival-power-calculator.html"><span class="tool-icon"></span><span class="tool-label">Survival Power</span></a></li><li><a href="/tools/type-i-ii-error-visualizer.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12c1.5 0 2-2 3.5-2S7 12 8 12s2-8 3.5-8S13 12 14.5 12"/><line x1="8" y1="2" x2="8" y2="14" stroke-dasharray="2 2"/></svg></span><span class="tool-label">Type I / II Error</span></a></li><li><a href="/tools/z-score-percentile.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 13c2 0 3-1 4-3s1.5-6 2-6 .5 6 2 6 2.5 0 4 0"/><path d="M2 13.5h12"/></svg></span><span class="tool-label">Z-Score & Percentile</span></a></li><li><a href="/tools/equivalence-noninferiority-calculator.html"><span class="tool-icon"></span><span class="tool-label">Equivalence / NI</span></a></li><li><a href="/tools/outlier-detection-calculator.html"><span class="tool-icon"></span><span class="tool-label">Outlier Detection</span></a></li><li><a href="/tools/roc-auc-calculator.html"><span class="tool-icon"></span><span class="tool-label">ROC / AUC</span></a></li><li class="sidebar-divider"><span class="subsec-chevron">▼</span> Bayesian</li><li><a href="/tools/bayes-theorem-calculator.html"><span class="tool-icon"></span><span class="tool-label">Bayes Theorem</span></a></li><li><a href="/tools/bayes-factor-calculator.html"><span class="tool-icon"></span><span class="tool-label">Bayes Factor</span></a></li><li class="sidebar-divider"><span class="subsec-chevron">▼</span> Interpreters</li><li><a href="/tools/lm-output-interpreter.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 13.5L14 3"/><circle cx="4" cy="11.5" r="1" fill="currentColor" stroke="none"/><circle cx="7.5" cy="9" r="1" fill="currentColor" stroke="none"/><circle cx="11" cy="6.5" r="1" fill="currentColor" stroke="none"/></svg></span><span class="tool-label">lm() Output</span></a></li><li><a href="/tools/glm-output-interpreter.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 13C5 13 5 3 8 3s3 10 6 10"/><path d="M2 13.5h12"/></svg></span><span class="tool-label">glm() Output</span></a></li><li><a href="/tools/anova-output-interpreter.html"><span class="tool-icon"></span><span class="tool-label">ANOVA Output</span></a></li><li><a href="/tools/vif-interpreter.html"><span class="tool-icon"></span><span class="tool-label">VIF / Multicollinearity</span></a></li><li><a href="/tools/confusion-matrix-interpreter.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="2.5" width="4.5" height="4.5"/><rect x="9" y="2.5" width="4.5" height="4.5"/><rect x="2.5" y="9" width="4.5" height="4.5"/><rect x="9" y="9" width="4.5" height="4.5"/></svg></span><span class="tool-label">Confusion Matrix</span></a></li><li><a href="/tools/diagnostic-plot-interpreter.html"><span class="tool-icon"></span><span class="tool-label">Diagnostic Plots</span></a></li><li class="sidebar-divider"><span class="subsec-chevron">▼</span> Pickers</li><li><a href="/tools/normality-test-picker.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 13c2 0 3-1 4-3s1.5-6 2-6 .5 6 2 6 2.5 0 4 0"/><circle cx="13" cy="4" r="1.6" fill="currentColor" stroke="none"/></svg></span><span class="tool-label">Normality Test</span></a></li><li><a href="/tools/nonparametric-test-picker.html"><span class="tool-icon"></span><span class="tool-label">Non-Parametric Test</span></a></li><li><a href="/tools/multiple-testing-correction.html"><span class="tool-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 4l2 2 3-3M2.5 8l2 2 3-3M2.5 12l2 2 3-3"/><path d="M10.5 4h3M10.5 8h3M10.5 12h3"/></svg></span><span class="tool-label">Multiple Testing</span></a></li><li class="sidebar-divider"><span class="subsec-chevron">▼</span> Time series</li><li><a href="/tools/ts-stationarity-calculator.html"><span class="tool-icon"></span><span class="tool-label">TS Stationarity</span></a></li><li class="sidebar-divider"><span class="subsec-chevron">▼</span> Utilities</li><li><a href="/tools/dag-confounder-picker.html"><span class="tool-icon"></span><span class="tool-label">DAG Confounder Picker</span></a></li><li><a href="/tools/reprex-builder.html"><span class="tool-icon"></span><span class="tool-label">Reprex Builder</span></a></li></ul></div></div>
</div>
<main id="content" class="col-xs-12 col-sm-7">
<nav class="breadcrumb-nav" aria-label="Breadcrumb"><a href="/">Home</a> <span class="breadcrumb-sep">›</span> <span>Statistics</span> <span class="breadcrumb-sep">›</span> <span class="breadcrumb-current">Bayesian Statistics in R: Build Genuine Intuition Before Opening Stan or brms</span></nav>
<!-- md2html:generated -->
<h1>Bayesian Statistics in R: Build Genuine Intuition Before Opening Stan or brms</h1>
<p class="lead">Bayesian statistics in R updates a prior belief about an unknown parameter with observed data, producing a <a class="auto-link" href="Bayesian-Statistics-Exercises-in-R.html" title="Bayesian Statistics Exercises in R: 20 Practice Problems">posterior distribution</a> you can plot, integrate, and reason about. Unlike frequentist methods that return a single point estimate plus a confidence interval whose interpretation trips up most students, the Bayesian workflow gives you the full probability curve over plausible parameter values, ready for decision-making.</p>
<div class="post-byline" style="color:#6b7280;font-size:14px;margin:2px 0 18px 0;line-height:1.5;">By <strong>Selva Prabhakaran</strong> · Published May 13, 2026 · Last updated May 13, 2026</div>
<div class="engagement-header" data-difficulty="Intermediate" data-time="35" data-exercises="10" data-xp="150"></div>
<h2>How does Bayes' theorem turn data into a posterior?</h2>
<p>Frequentist tools answer "what is the parameter?" with a point estimate and a confidence interval whose interpretation bends most readers' minds. <a class="auto-link" href="Bayesian-Linear-Regression-in-R.html" title="Bayesian Linear Regression in R: Get Uncertainty Estimates lm() Cannot Give You">Bayesian inference</a> flips the question. You start with a prior belief about the parameter, observe data, and end with a posterior distribution: a probability curve over every plausible value. This section shows that update happen in a single line of base R using the Beta-Binomial pair, the simplest example of an analytic posterior.</p>
<p>The math behind every Bayesian update is one line:</p>
<p>$$ p(\theta \mid \text{data}) \;\propto\; p(\text{data} \mid \theta) \cdot p(\theta) $$</p>
<p>Where: $p(\theta)$ is the prior, $p(\text{data} \mid \theta)$ is the likelihood, and $p(\theta \mid \text{data})$ is the posterior. The proportional sign hides a normalizing constant that does not affect the shape of the curve.</p>
<p>Suppose you flip a possibly-biased coin 100 times and see 65 heads. You want to estimate the unknown success probability theta. A Beta(2, 2) prior is mildly skeptical of extreme values, gently centered at 0.5. The posterior comes out in closed form because the Beta family is conjugate to the Binomial likelihood, meaning the posterior stays in the Beta family.</p>
<div class="webr-container" data-block-title="Beta-Binomial posterior from 100 flips">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Beta-Binomial posterior from 100 flips</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">n <span class="o"><-</span> <span class="m">100</span> <span class="c1"># total flips</span></span>
<span class="cl">k <span class="o"><-</span> <span class="m">65</span> <span class="c1"># heads observed</span></span>
<span class="cl">alpha_prior <span class="o"><-</span> <span class="m">2</span> <span class="c1"># prior shape parameters</span></span>
<span class="cl">beta_prior <span class="o"><-</span> <span class="m">2</span> <span class="c1"># ... encoding "fair-ish, but uncertain"</span></span>
<span class="cl"></span>
<span class="cl">alpha_post <span class="o"><-</span> alpha_prior <span class="o">+</span> k <span class="c1"># closed-form posterior shape</span></span>
<span class="cl">beta_post <span class="o"><-</span> beta_prior <span class="o">+</span> n <span class="o">-</span> k <span class="c1"># ... thanks to Beta-Binomial conjugacy</span></span>
<span class="cl"></span>
<span class="cl">post_mean <span class="o"><-</span> alpha_post <span class="o">/</span> (alpha_post <span class="o">+</span> beta_post)</span>
<span class="cl">cri <span class="o"><-</span> <span class="nf">qbeta</span>(<span class="nf">c</span>(<span class="m">0.025</span>, <span class="m">0.975</span>), alpha_post, beta_post)</span>
<span class="cl"></span>
<span class="cl">post_mean</span>
<span class="cl"><span class="c1">#> [1] 0.6442308</span></span>
<span class="cl">cri</span>
<span class="cl"><span class="c1">#> [1] 0.5497073 0.7321076</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>The posterior is Beta(67, 37). Its mean of 0.644 sits between the prior mean of 0.5 and the data proportion of 0.65, gently pulled toward 0.5 by the prior's weight. The 95% credible interval [0.55, 0.73] is the range that contains 95% of the <a class="auto-link" href="Bayes-Theorem-in-R.html" title="Bayes' Theorem in R: Why Medical Tests Mislead You, A Simulation That Shows Why">posterior probability</a> mass. That is the interpretation people incorrectly give a frequentist confidence interval.</p>
<p><img src="screenshots/Bayesian-Statistics-in-R-workflow.webp" alt="The Bayesian update workflow" class="img-responsive img-zoomable" loading="lazy" width="2248" height="380" /></p>
<p><em>Figure 1: The Bayesian update workflow. Prior plus data give a posterior, which you then <a class="auto-link" href="dplyr-group-by-summarise.html" title="dplyr group_by() + summarise(): The Combination That Answers Most Business Questions">summarize</a>.</em></p>
<div class="callout callout-insight"><div class="callout-label">Key Insight</div><div class="callout-body"><strong>The posterior is the prior reweighted by the likelihood.</strong> No exotic computation, just multiplication and renormalization. The Beta-Binomial pair gives you the answer in closed form because the Beta family is conjugate to the Binomial, meaning the posterior stays in the Beta family.</div></div>
<section class="tryit-block">
<p><strong>Try it:</strong> Repeat the calculation with a much tighter prior, Beta(20, 20). What does the posterior mean become and why?</p>
<div class="webr-container" data-block-title="Your turn: tighten the prior">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Your turn: tighten the prior</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_alpha <span class="o"><-</span> <span class="m">20</span> <span class="c1"># try a tight prior</span></span>
<span class="cl">ex_beta <span class="o"><-</span> <span class="m">20</span></span>
<span class="cl"></span>
<span class="cl"><span class="c1"># compute the posterior shape parameters and posterior mean here</span></span>
<span class="cl"><span class="c1"># ex_alpha_post <- ?</span></span>
<span class="cl"><span class="c1"># ex_beta_post <- ?</span></span>
<span class="cl"><span class="c1"># ex_post_mean <- ?</span></span>
<span class="cl"><span class="c1">#> Expected: posterior mean closer to 0.5 than 0.65</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<details><summary>Click to reveal solution</summary>
<div class="webr-container" data-block-title="Tighter prior solution">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Tighter prior solution</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_alpha_post <span class="o"><-</span> ex_alpha <span class="o">+</span> k</span>
<span class="cl">ex_beta_post <span class="o"><-</span> ex_beta <span class="o">+</span> n <span class="o">-</span> k</span>
<span class="cl">ex_post_mean <span class="o"><-</span> ex_alpha_post <span class="o">/</span> (ex_alpha_post <span class="o">+</span> ex_beta_post)</span>
<span class="cl">ex_post_mean</span>
<span class="cl"><span class="c1">#> [1] 0.6071429</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>A Beta(20, 20) prior is equivalent to having seen 38 prior flips with 19 heads. Adding the new 100 flips gives a posterior that is pulled noticeably back toward 0.5. A stronger prior carries more weight against the same data, that is the lesson here.</p>
</details>
</section>
<h2>What does a prior actually encode?</h2>
<p>A prior is just a probability distribution over the parameter. Anything you can put on a curve, you can use as a prior. The Beta family is convenient for proportions because it lives on [0, 1] and supports two intuitive shape parameters that act like pseudo-counts of prior successes and failures. Three Beta priors illustrate the spectrum from ignorance to strong belief.</p>
<div class="webr-container" data-block-title="Three priors plotted on one panel">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Three priors plotted on one panel</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">theta_grid <span class="o"><-</span> <span class="nf">seq</span>(<span class="m">0</span>, <span class="m">1</span>, length.out <span class="o">=</span> <span class="m">200</span>)</span>
<span class="cl"></span>
<span class="cl"><span class="nf">plot</span>(theta_grid, <span class="nf">dbeta</span>(theta_grid, <span class="m">1</span>, <span class="m">1</span>), type <span class="o">=</span> <span class="s">"l"</span>, lwd <span class="o">=</span> <span class="m">2</span>,</span>
<span class="cl"> ylim <span class="o">=</span> <span class="nf">c</span>(<span class="m">0</span>, <span class="m">6</span>), xlab <span class="o">=</span> <span class="nf">expression</span>(theta), ylab <span class="o">=</span> <span class="s">"density"</span>,</span>
<span class="cl"> main <span class="o">=</span> <span class="s">"Three priors over a proportion"</span>)</span>
<span class="cl"><span class="nf">lines</span>(theta_grid, <span class="nf">dbeta</span>(theta_grid, <span class="m">20</span>, <span class="m">20</span>), lwd <span class="o">=</span> <span class="m">2</span>, col <span class="o">=</span> <span class="s">"steelblue"</span>)</span>
<span class="cl"><span class="nf">lines</span>(theta_grid, <span class="nf">dbeta</span>(theta_grid, <span class="m">2</span>, <span class="m">5</span>), lwd <span class="o">=</span> <span class="m">2</span>, col <span class="o">=</span> <span class="s">"tomato"</span>)</span>
<span class="cl"><span class="nf">legend</span>(<span class="s">"topright"</span>, lwd <span class="o">=</span> <span class="m">2</span>,</span>
<span class="cl"> col <span class="o">=</span> <span class="nf">c</span>(<span class="s">"black"</span>, <span class="s">"steelblue"</span>, <span class="s">"tomato"</span>),</span>
<span class="cl"> legend <span class="o">=</span> <span class="nf">c</span>(<span class="s">"Beta(1,1) uniform"</span>, <span class="s">"Beta(20,20) tight at 0.5"</span>, <span class="s">"Beta(2,5) skewed low"</span>))</span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>Beta(1, 1) is flat: every value of theta is equally plausible before seeing data. Beta(20, 20) is tight around 0.5: a strong belief that the coin is fair. Beta(2, 5) is skewed low: a belief that small values of theta are more likely. Each shape encodes a different domain assumption, and each will pull the posterior in a different direction.</p>
<p>You often have a substantive belief such as "I think theta is between 0.4 and 0.6 with about 90% probability." That language has a direct Beta translation. Search for shape parameters whose 5th and 95th percentiles match the beliefs. A symmetric, moderately tight Beta(45, 45) lands close.</p>
<div class="webr-container" data-block-title="Quantile-based prior elicitation">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Quantile-based prior elicitation</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl"><span class="nf">qbeta</span>(<span class="nf">c</span>(<span class="m">0.05</span>, <span class="m">0.95</span>), <span class="m">45</span>, <span class="m">45</span>)</span>
<span class="cl"><span class="c1">#> [1] 0.4133497 0.5866503</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>A Beta(45, 45) prior places 90% of its mass between 0.41 and 0.59, a near-perfect match for the stated belief. If you wanted a less tight prior, lower both shape parameters; for a more confident prior, raise them. This is how to translate qualitative belief into a quantitative prior without throwing darts.</p>
<div class="callout callout-tip"><div class="callout-label">Tip</div><div class="callout-body"><strong>Pick a prior whose shape matches your prior belief, document the choice, and plan to report sensitivity.</strong> Beta(2, 2) is mildly skeptical of extreme values; Beta(1, 1) is informationless; Beta(50, 50) is hard to budge. Match the prior to the belief, then check how much the answer changes if you nudge the prior.</div></div>
<section class="tryit-block">
<p><strong>Try it:</strong> Encode the belief "I think theta is around 0.7 with mild uncertainty" as Beta shape parameters. A good answer keeps most mass in the [0.6, 0.8] range.</p>
<div class="webr-container" data-block-title="Your turn: encode a belief at 0.7">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Your turn: encode a belief at 0.7</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_alpha2 <span class="o"><-</span> <span class="m">0</span> <span class="c1"># replace</span></span>
<span class="cl">ex_beta2 <span class="o"><-</span> <span class="m">0</span> <span class="c1"># replace</span></span>
<span class="cl"></span>
<span class="cl"><span class="c1"># Verify with: qbeta(c(0.05, 0.95), ex_alpha2, ex_beta2)</span></span>
<span class="cl"><span class="c1">#> Expected: 90% interval roughly [0.6, 0.8]</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<details><summary>Click to reveal solution</summary>
<div class="webr-container" data-block-title="Belief-at-0.7 solution">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Belief-at-0.7 solution</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_alpha2 <span class="o"><-</span> <span class="m">35</span></span>
<span class="cl">ex_beta2 <span class="o"><-</span> <span class="m">15</span></span>
<span class="cl"><span class="nf">qbeta</span>(<span class="nf">c</span>(<span class="m">0.05</span>, <span class="m">0.95</span>), ex_alpha2, ex_beta2)</span>
<span class="cl"><span class="c1">#> [1] 0.5901019 0.8003617</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>Beta(35, 15) has mean 35/50 = 0.7 with 90% of its mass between 0.59 and 0.80. The ratio alpha/(alpha+beta) controls the center; the sum alpha+beta controls how tight the curve is. Combine those two levers to encode any belief on [0,1].</p>
</details>
</section>
<h2>How do prior and likelihood combine into a posterior?</h2>
<p>The likelihood is a function of the parameter, given fixed data. It is not itself a probability distribution over theta, just a curve showing which theta values are most consistent with what you saw. Multiply the likelihood curve by the prior curve, normalize so the area is 1, and you have the posterior. Plotting all three on the same axes makes the arithmetic visual.</p>
<div class="webr-container" data-block-title="Prior, likelihood, posterior on one panel">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Prior, likelihood, posterior on one panel</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">likelihood_vals <span class="o"><-</span> <span class="nf">dbinom</span>(k, size <span class="o">=</span> n, prob <span class="o">=</span> theta_grid)</span>
<span class="cl"></span>
<span class="cl"><span class="nf">par</span>(mfrow <span class="o">=</span> <span class="nf">c</span>(<span class="m">1</span>, <span class="m">3</span>), mar <span class="o">=</span> <span class="nf">c</span>(<span class="m">4</span>, <span class="m">4</span>, <span class="m">3</span>, <span class="m">1</span>))</span>
<span class="cl"></span>
<span class="cl"><span class="nf">plot</span>(theta_grid, <span class="nf">dbeta</span>(theta_grid, alpha_prior, beta_prior),</span>
<span class="cl"> type <span class="o">=</span> <span class="s">"l"</span>, lwd <span class="o">=</span> <span class="m">2</span>, main <span class="o">=</span> <span class="s">"Prior Beta(2, 2)"</span>,</span>
<span class="cl"> xlab <span class="o">=</span> <span class="nf">expression</span>(theta), ylab <span class="o">=</span> <span class="s">"density"</span>)</span>
<span class="cl"></span>
<span class="cl"><span class="nf">plot</span>(theta_grid, likelihood_vals, type <span class="o">=</span> <span class="s">"l"</span>, lwd <span class="o">=</span> <span class="m">2</span>, col <span class="o">=</span> <span class="s">"tomato"</span>,</span>
<span class="cl"> main <span class="o">=</span> <span class="s">"Likelihood Binomial(n=100, k=65)"</span>,</span>
<span class="cl"> xlab <span class="o">=</span> <span class="nf">expression</span>(theta), ylab <span class="o">=</span> <span class="s">"L(theta)"</span>)</span>
<span class="cl"></span>
<span class="cl"><span class="nf">plot</span>(theta_grid, <span class="nf">dbeta</span>(theta_grid, alpha_post, beta_post),</span>
<span class="cl"> type <span class="o">=</span> <span class="s">"l"</span>, lwd <span class="o">=</span> <span class="m">2</span>, col <span class="o">=</span> <span class="s">"steelblue"</span>,</span>
<span class="cl"> main <span class="o">=</span> <span class="s">"Posterior Beta(67, 37)"</span>,</span>
<span class="cl"> xlab <span class="o">=</span> <span class="nf">expression</span>(theta), ylab <span class="o">=</span> <span class="s">"density"</span>)</span>
<span class="cl"></span>
<span class="cl"><span class="nf">par</span>(mfrow <span class="o">=</span> <span class="nf">c</span>(<span class="m">1</span>, <span class="m">1</span>))</span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>The likelihood peaks at the maximum likelihood estimate, exactly k/n = 0.65. The prior peaks at 0.5. The posterior peaks slightly below 0.65, pulled toward the prior in proportion to the prior's tightness. With a weak prior and large n, the posterior almost coincides with the likelihood.</p>
<p><img src="screenshots/Bayesian-Statistics-in-R-conjugate.webp" alt="Beta-Binomial conjugate update" class="img-responsive img-zoomable" loading="lazy" width="1486" height="690" /></p>
<p><em>Figure 2: <a class="auto-link" href="Conjugate-Priors-in-R.html" title="Conjugate Priors in R: The Shortcut That Gives Exact Posteriors Without MCMC">Beta-Binomial conjugate</a>. Closed-form posterior parameters absorb counts of observed successes and failures.</em></p>
<div class="callout callout-insight"><div class="callout-label">Key Insight</div><div class="callout-body"><strong>The posterior always lies between the prior and the likelihood, weighted by their relative confidence.</strong> A flat prior gives you back the likelihood. A point-mass prior ignores the data entirely. Real priors live in between, and the data nudges the answer accordingly.</div></div>
<section class="tryit-block">
<p><strong>Try it:</strong> Suppose you observed 20 heads in 100 flips instead of 65. Recompute the posterior parameters and the posterior mean.</p>
<div class="webr-container" data-block-title="Your turn: shift the data">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Your turn: shift the data</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_k_new <span class="o"><-</span> <span class="m">20</span></span>
<span class="cl"></span>
<span class="cl"><span class="c1"># compute new alpha_post, beta_post, and posterior mean</span></span>
<span class="cl"><span class="c1">#> Expected: posterior mean near 0.21</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<details><summary>Click to reveal solution</summary>
<div class="webr-container" data-block-title="Shifted-data solution">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Shifted-data solution</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_alpha_post_new <span class="o"><-</span> alpha_prior <span class="o">+</span> ex_k_new</span>
<span class="cl">ex_beta_post_new <span class="o"><-</span> beta_prior <span class="o">+</span> n <span class="o">-</span> ex_k_new</span>
<span class="cl">ex_alpha_post_new <span class="o">/</span> (ex_alpha_post_new <span class="o">+</span> ex_beta_post_new)</span>
<span class="cl"><span class="c1">#> [1] 0.2115385</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>The posterior peaks near 0.21, just above the data proportion 0.20, slightly pulled toward 0.5 by the prior. The shape and the location of the curve both follow the data, while the prior modulates the pull.</p>
</details>
</section>
<h2>How does the posterior shift as more data arrives?</h2>
<p>A common worry about Bayesian methods is "what if I pick the wrong prior?" The honest answer: with enough data, the prior gets washed out. Likelihood scales with n, prior does not, so the posterior shifts toward the data as n grows. Showing this with a deliberately bad prior makes the point concrete.</p>
<div class="webr-container" data-block-title="Posterior with n = 10, 100, 1000 against a wrong prior">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Posterior with n = 10, 100, 1000 against a wrong prior</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">true_theta <span class="o"><-</span> <span class="m">0.7</span> <span class="c1"># the truth we are trying to recover</span></span>
<span class="cl">sims <span class="o"><-</span> <span class="nf">list</span>(</span>
<span class="cl"> small <span class="o">=</span> <span class="nf">list</span>(n <span class="o">=</span> <span class="m">10</span>, k <span class="o">=</span> <span class="nf">round</span>(<span class="m">0.7</span> <span class="o">*</span> <span class="m">10</span>)), <span class="c1"># 7 / 10</span></span>
<span class="cl"> medium <span class="o">=</span> <span class="nf">list</span>(n <span class="o">=</span> <span class="m">100</span>, k <span class="o">=</span> <span class="nf">round</span>(<span class="m">0.7</span> <span class="o">*</span> <span class="m">100</span>)), <span class="c1"># 70 / 100</span></span>
<span class="cl"> large <span class="o">=</span> <span class="nf">list</span>(n <span class="o">=</span> <span class="m">1000</span>, k <span class="o">=</span> <span class="nf">round</span>(<span class="m">0.7</span> <span class="o">*</span> <span class="m">1000</span>)) <span class="c1"># 700/ 1000</span></span>
<span class="cl">)</span>
<span class="cl">wrong_alpha <span class="o"><-</span> <span class="m">80</span> <span class="c1"># a stubborn prior centered at 0.8 ...</span></span>
<span class="cl">wrong_beta <span class="o"><-</span> <span class="m">20</span> <span class="c1"># ... that disagrees with the truth</span></span>
<span class="cl"></span>
<span class="cl"><span class="nf">plot</span>(theta_grid, <span class="nf">dbeta</span>(theta_grid, wrong_alpha, wrong_beta), type <span class="o">=</span> <span class="s">"l"</span>, lwd <span class="o">=</span> <span class="m">2</span>,</span>
<span class="cl"> ylim <span class="o">=</span> <span class="nf">c</span>(<span class="m">0</span>, <span class="m">30</span>), xlab <span class="o">=</span> <span class="nf">expression</span>(theta), ylab <span class="o">=</span> <span class="s">"density"</span>,</span>
<span class="cl"> main <span class="o">=</span> <span class="s">"Posterior shifts toward the truth as n grows"</span>)</span>
<span class="cl"><span class="nf">abline</span>(v <span class="o">=</span> true_theta, lty <span class="o">=</span> <span class="m">2</span>)</span>
<span class="cl">cols <span class="o"><-</span> <span class="nf">c</span>(<span class="s">"tomato"</span>, <span class="s">"orange"</span>, <span class="s">"steelblue"</span>)</span>
<span class="cl"><span class="kr">for</span> (i <span class="kr">in</span> <span class="nf">seq_along</span>(sims)) {</span>
<span class="cl"> s <span class="o"><-</span> sims[[i]]</span>
<span class="cl"> <span class="nf">lines</span>(theta_grid,</span>
<span class="cl"> <span class="nf">dbeta</span>(theta_grid, wrong_alpha <span class="o">+</span> s<span class="o">$</span>k, wrong_beta <span class="o">+</span> s<span class="o">$</span>n <span class="o">-</span> s<span class="o">$</span>k),</span>
<span class="cl"> lwd <span class="o">=</span> <span class="m">2</span>, col <span class="o">=</span> cols[i])</span>
<span class="cl">}</span>
<span class="cl"><span class="nf">legend</span>(<span class="s">"topleft"</span>, lwd <span class="o">=</span> <span class="m">2</span>, col <span class="o">=</span> <span class="nf">c</span>(<span class="s">"black"</span>, cols),</span>
<span class="cl"> legend <span class="o">=</span> <span class="nf">c</span>(<span class="s">"Wrong prior Beta(80,20)"</span>, <span class="s">"n=10"</span>, <span class="s">"n=100"</span>, <span class="s">"n=1000"</span>))</span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>The prior peaks at 0.8 and refuses to budge much for n=10. By n=100 the posterior straddles 0.75. By n=1000 it has converged tightly around the true 0.7. The posterior peak migrates from prior toward truth as the data accumulates.</p>
<p>A subtler property of Bayes' theorem is that updates are order-independent. If you observe one batch, then another, then update sequentially, the result is mathematically identical to combining everything and updating once. The check below verifies that.</p>
<div class="webr-container" data-block-title="Sequential vs one-shot update">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Sequential vs one-shot update</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">batch1 <span class="o"><-</span> <span class="nf">list</span>(n <span class="o">=</span> <span class="m">50</span>, k <span class="o">=</span> <span class="m">35</span>)</span>
<span class="cl">batch2 <span class="o"><-</span> <span class="nf">list</span>(n <span class="o">=</span> <span class="m">50</span>, k <span class="o">=</span> <span class="m">40</span>)</span>
<span class="cl"></span>
<span class="cl"><span class="c1"># Sequential: update after each batch</span></span>
<span class="cl">seq_first <span class="o"><-</span> <span class="nf">c</span>(alpha <span class="o">=</span> <span class="m">1</span> <span class="o">+</span> batch1<span class="o">$</span>k,</span>
<span class="cl"> beta <span class="o">=</span> <span class="m">1</span> <span class="o">+</span> batch1<span class="o">$</span>n <span class="o">-</span> batch1<span class="o">$</span>k) <span class="c1"># Beta(36, 16)</span></span>
<span class="cl">seq_second <span class="o"><-</span> <span class="nf">c</span>(alpha <span class="o">=</span> seq_first[<span class="s">"alpha"</span>] <span class="o">+</span> batch2<span class="o">$</span>k,</span>
<span class="cl"> beta <span class="o">=</span> seq_first[<span class="s">"beta"</span>] <span class="o">+</span> batch2<span class="o">$</span>n <span class="o">-</span> batch2<span class="o">$</span>k) <span class="c1"># Beta(76, 26)</span></span>
<span class="cl"></span>
<span class="cl"><span class="c1"># One-shot: combine batches and update once</span></span>
<span class="cl">seq_combined <span class="o"><-</span> <span class="nf">c</span>(alpha <span class="o">=</span> <span class="m">1</span> <span class="o">+</span> batch1<span class="o">$</span>k <span class="o">+</span> batch2<span class="o">$</span>k,</span>
<span class="cl"> beta <span class="o">=</span> <span class="m">1</span> <span class="o">+</span> batch1<span class="o">$</span>n <span class="o">+</span> batch2<span class="o">$</span>n <span class="o">-</span> batch1<span class="o">$</span>k <span class="o">-</span> batch2<span class="o">$</span>k)</span>
<span class="cl"></span>
<span class="cl">seq_second</span>
<span class="cl"><span class="c1">#> alpha.alpha beta.beta</span></span>
<span class="cl"><span class="c1">#> 76 26</span></span>
<span class="cl">seq_combined</span>
<span class="cl"><span class="c1">#> alpha beta</span></span>
<span class="cl"><span class="c1">#> 76 26</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>Both paths land on Beta(76, 26). Sequential and one-shot updates are mathematically identical, which is why Bayesian methods fit naturally to streaming data: every new observation just nudges the existing posterior into a new posterior of the same family.</p>
<div class="callout callout-note"><div class="callout-label">Note</div><div class="callout-body"><strong>Bayes' theorem is order-independent and incremental.</strong> Observe one row at a time, ten at a time, or a million at a time, the math gives the same answer. That makes Bayesian updates the natural model for online learning and <a class="auto-link" href="Experimental-Design-Principles-in-R.html" title="Experimental Design in R: The Three Principles That Make Results Valid and Generalisable">experimental design</a>.</div></div>
<section class="tryit-block">
<p><strong>Try it:</strong> Start from a uniform Beta(1, 1) prior, observe n = 1000 with k = 700 (true theta = 0.7). Where does the posterior peak, and how tight is the 95% credible interval?</p>
<div class="webr-container" data-block-title="Your turn: uniform prior + n = 1000">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Your turn: uniform prior + n = 1000</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_alpha_unif <span class="o"><-</span> <span class="m">0</span> <span class="c1"># replace</span></span>
<span class="cl">ex_beta_unif <span class="o"><-</span> <span class="m">0</span> <span class="c1"># replace</span></span>
<span class="cl"><span class="c1"># ex_alpha_unif / (ex_alpha_unif + ex_beta_unif)</span></span>
<span class="cl"><span class="c1"># qbeta(c(0.025, 0.975), ex_alpha_unif, ex_beta_unif)</span></span>
<span class="cl"><span class="c1">#> Expected: posterior tightly peaked near 0.7</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<details><summary>Click to reveal solution</summary>
<div class="webr-container" data-block-title="Uniform prior + n = 1000 solution">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Uniform prior + n = 1000 solution</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_alpha_unif <span class="o"><-</span> <span class="m">1</span> <span class="o">+</span> <span class="m">700</span></span>
<span class="cl">ex_beta_unif <span class="o"><-</span> <span class="m">1</span> <span class="o">+</span> <span class="m">1000</span> <span class="o">-</span> <span class="m">700</span></span>
<span class="cl">ex_alpha_unif <span class="o">/</span> (ex_alpha_unif <span class="o">+</span> ex_beta_unif)</span>
<span class="cl"><span class="c1">#> [1] 0.6993014</span></span>
<span class="cl"><span class="nf">qbeta</span>(<span class="nf">c</span>(<span class="m">0.025</span>, <span class="m">0.975</span>), ex_alpha_unif, ex_beta_unif)</span>
<span class="cl"><span class="c1">#> [1] 0.6705486 0.7269683</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>A uniform prior plus 1000 observations gives a posterior whose mean is essentially the data proportion, with a 95% credible interval roughly +/- 0.03 around the truth. With this much data, the choice of weak prior barely matters.</p>
</details>
</section>
<h2>How do we summarize a posterior in R?</h2>
<p>A posterior is a curve, not a number. To report or act on it you reduce it to a few summaries: a central estimate, an interval that captures most of the mass, and the probability of any event of interest. R provides every Beta family helper you need: <code>dbeta</code>, <code>pbeta</code>, <code>qbeta</code>, <code>rbeta</code>.</p>
<div class="webr-container" data-block-title="Mean, mode, credible interval, P(theta > 0.5)">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Mean, mode, credible interval, P(theta > 0.5)</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">post_mean</span>
<span class="cl"><span class="c1">#> [1] 0.6442308</span></span>
<span class="cl"></span>
<span class="cl">post_mode <span class="o"><-</span> (alpha_post <span class="o">-</span> <span class="m">1</span>) <span class="o">/</span> (alpha_post <span class="o">+</span> beta_post <span class="o">-</span> <span class="m">2</span>) <span class="c1"># valid for alpha,beta > 1</span></span>
<span class="cl">post_mode</span>
<span class="cl"><span class="c1">#> [1] 0.6470588</span></span>
<span class="cl"></span>
<span class="cl">cri</span>
<span class="cl"><span class="c1">#> [1] 0.5497073 0.7321076</span></span>
<span class="cl"></span>
<span class="cl">p_gt_half <span class="o"><-</span> <span class="m">1</span> <span class="o">-</span> <span class="nf">pbeta</span>(<span class="m">0.5</span>, alpha_post, beta_post)</span>
<span class="cl">p_gt_half</span>
<span class="cl"><span class="c1">#> [1] 0.9979088</span></span>
<span class="cl"></span>
<span class="cl">p_hat <span class="o"><-</span> k <span class="o">/</span> n</span>
<span class="cl">freq_ci <span class="o"><-</span> p_hat <span class="o">+</span> <span class="nf">c</span>(<span class="m">-1</span>, <span class="m">1</span>) <span class="o">*</span> <span class="nf">qnorm</span>(<span class="m">0.975</span>) <span class="o">*</span> <span class="nf">sqrt</span>(p_hat <span class="o">*</span> (<span class="m">1</span> <span class="o">-</span> p_hat) <span class="o">/</span> n)</span>
<span class="cl">freq_ci</span>
<span class="cl"><span class="c1">#> [1] 0.5565097 0.7434903</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>The 95% credible interval [0.55, 0.73] is similar in width to the frequentist Wald CI [0.56, 0.74], but the interpretation differs sharply. The Bayesian statement is "given my prior and the data, there is a 95% probability that theta is in this interval." The frequentist statement is the multi-step contortion most students stumble over. The posterior probability of 0.998 that theta exceeds 0.5 is the kind of statement decision-makers can act on directly.</p>
<div class="callout callout-note"><div class="callout-label">Note</div><div class="callout-body"><strong>The credible interval has the interpretation people want from a confidence interval.</strong> That alone is worth the price of admission to Bayesian thinking. A posterior probability of 0.998 that theta exceeds 0.5 is far more communicable than "p < 0.001."</div></div>
<section class="tryit-block">
<p><strong>Try it:</strong> What is the posterior probability that theta > 0.6?</p>
<div class="webr-container" data-block-title="Your turn: P(theta > 0.6)">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Your turn: P(theta > 0.6)</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl"><span class="c1"># use 1 - pbeta() with alpha_post and beta_post</span></span>
<span class="cl"><span class="c1"># ex_p <- ?</span></span>
<span class="cl"><span class="c1">#> Expected: a value between 0.7 and 0.9</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<details><summary>Click to reveal solution</summary>
<div class="webr-container" data-block-title="Tail-probability solution">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Tail-probability solution</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">ex_p <span class="o"><-</span> <span class="m">1</span> <span class="o">-</span> <span class="nf">pbeta</span>(<span class="m">0.6</span>, alpha_post, beta_post)</span>
<span class="cl">ex_p</span>
<span class="cl"><span class="c1">#> [1] 0.8164234</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>There is roughly an 82% posterior probability that theta exceeds 0.6 given this prior and these data. Combined with the credible interval, you can quote any tail probability the stakeholder cares about.</p>
</details>
</section>
<h2>What if my prior matters? How do I check sensitivity?</h2>
<p>The honest answer to "what if my prior is wrong?" is to try several reasonable priors and see whether the conclusion changes. If three plausible priors give similar posteriors, you have a robust answer. If they give materially different posteriors, that is itself a finding to report alongside the analysis. The check is cheap with conjugate priors.</p>
<div class="webr-container" data-block-title="Prior sensitivity comparison">
<div class="webr-code-block">
<div class="webr-header"><div class="webr-header-left"><span class="webr-header-badge">R</span><span class="webr-header-label">Prior sensitivity comparison</span></div><div class="webr-header-right"><button type="button" class="webr-copy-btn" aria-label="Copy code" title="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button><button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run <span class="webr-run-shortcut">Ctrl+Enter</span></button></div></div>
<div class="webr-editor" data-language="r"><span class="cl">priors <span class="o"><-</span> <span class="nf">list</span>(</span>
<span class="cl"> skeptical <span class="o">=</span> <span class="nf">c</span>(alpha <span class="o">=</span> <span class="m">2</span>, beta <span class="o">=</span> <span class="m">5</span>), <span class="c1"># leans toward small theta</span></span>
<span class="cl"> uniform <span class="o">=</span> <span class="nf">c</span>(alpha <span class="o">=</span> <span class="m">1</span>, beta <span class="o">=</span> <span class="m">1</span>), <span class="c1"># informationless</span></span>
<span class="cl"> optimistic <span class="o">=</span> <span class="nf">c</span>(alpha <span class="o">=</span> <span class="m">8</span>, beta <span class="o">=</span> <span class="m">2</span>) <span class="c1"># leans toward large theta</span></span>
<span class="cl">)</span>
<span class="cl"></span>
<span class="cl">posterior_summary <span class="o"><-</span> <span class="nf">t</span>(<span class="nf">sapply</span>(priors, <span class="kr">function</span>(p) {</span>
<span class="cl"> ap <span class="o"><-</span> p[<span class="s">"alpha"</span>] <span class="o">+</span> k</span>
<span class="cl"> bp <span class="o"><-</span> p[<span class="s">"beta"</span>] <span class="o">+</span> n <span class="o">-</span> k</span>
<span class="cl"> <span class="nf">c</span>(post_mean <span class="o">=</span> ap <span class="o">/</span> (ap <span class="o">+</span> bp),</span>
<span class="cl"> cri_low <span class="o">=</span> <span class="nf">qbeta</span>(<span class="m">0.025</span>, ap, bp),</span>
<span class="cl"> cri_high <span class="o">=</span> <span class="nf">qbeta</span>(<span class="m">0.975</span>, ap, bp),</span>
<span class="cl"> p_above_half <span class="o">=</span> <span class="m">1</span> <span class="o">-</span> <span class="nf">pbeta</span>(<span class="m">0.5</span>, ap, bp))</span>
<span class="cl">}))</span>
<span class="cl"></span>
<span class="cl"><span class="nf">round</span>(posterior_summary, <span class="m">3</span>)</span>
<span class="cl"><span class="c1">#> post_mean.alpha cri_low cri_high p_above_half</span></span>
<span class="cl"><span class="c1">#> skeptical 0.626 0.530 0.717 0.992</span></span>
<span class="cl"><span class="c1">#> uniform 0.647 0.553 0.736 0.998</span></span>
<span class="cl"><span class="c1">#> optimistic 0.664 0.572 0.751 0.999</span></span></div>
<div class="webr-buttons">
<button class="btn btn-sm btn-primary webr-run-btn" onclick="runWebR(this)">▶ Run</button>
<button class="btn btn-sm btn-default webr-reset-btn" onclick="resetWebR(this)">↺ Reset</button>
</div>
<pre class="webr-output"></pre>
</div>
<div class="webr-plot-output"></div>
</div>
<p>All three priors produce posterior means within 0.04 of each other and 95% credible intervals that overlap heavily. The posterior probability that theta > 0.5 ranges from 0.992 to 0.999, well above any reasonable decision threshold. The conclusion that theta likely exceeds 0.5 is robust to a reasonable change of prior. That is exactly what you want to be able to report.</p>
<p><img src="screenshots/Bayesian-Statistics-in-R-when-mcmc.webp" alt="When to reach for MCMC" class="img-responsive img-zoomable" loading="lazy" width="1216" height="1766" /></p>