more work

This commit is contained in:
Emanuel Rodriguez 2022-09-11 01:27:09 -07:00
parent 838f9e05f3
commit 0d08907a15
8 changed files with 399 additions and 114 deletions

View File

@ -113,10 +113,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
<ul> <ul>
<li><a href="#likelihood" id="toc-likelihood" class="nav-link active" data-scroll-target="#likelihood">Likelihood</a></li> <li><a href="#likelihood" id="toc-likelihood" class="nav-link active" data-scroll-target="#likelihood">Likelihood</a></li>
<li><a href="#simualation" id="toc-simualation" class="nav-link" data-scroll-target="#simualation">Simualation</a></li> <li><a href="#simualation" id="toc-simualation" class="nav-link" data-scroll-target="#simualation">Simualation</a></li>
<li><a href="#binomial-model-and-the-chess-example" id="toc-binomial-model-and-the-chess-example" class="nav-link" data-scroll-target="#binomial-model-and-the-chess-example">Binomial Model and the chess example</a> <li><a href="#binomial-model-and-the-chess-example" id="toc-binomial-model-and-the-chess-example" class="nav-link" data-scroll-target="#binomial-model-and-the-chess-example">Binomial Model and the chess example</a></li>
<ul class="collapse">
<li><a href="#the-binomial-model" id="toc-the-binomial-model" class="nav-link" data-scroll-target="#the-binomial-model">The Binomial Model</a></li>
</ul></li>
</ul> </ul>
</nav> </nav>
</div> </div>
@ -244,12 +241,12 @@ Probability and Likelihood
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> gt<span class="sc">::</span><span class="fu">cols_width</span>(<span class="fu">everything</span>() <span class="sc">~</span> <span class="fu">px</span>(<span class="dv">100</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> <span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> gt<span class="sc">::</span><span class="fu">cols_width</span>(<span class="fu">everything</span>() <span class="sc">~</span> <span class="fu">px</span>(<span class="dv">100</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display"> <div class="cell-output-display">
<div id="ibvcfeegcr" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;"> <div id="gqllsnwjsv" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>html { <style>html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
} }
#ibvcfeegcr .gt_table { #gqllsnwjsv .gt_table {
display: table; display: table;
border-collapse: collapse; border-collapse: collapse;
margin-left: auto; margin-left: auto;
@ -274,7 +271,7 @@ Probability and Likelihood
border-left-color: #D3D3D3; border-left-color: #D3D3D3;
} }
#ibvcfeegcr .gt_heading { #gqllsnwjsv .gt_heading {
background-color: #FFFFFF; background-color: #FFFFFF;
text-align: center; text-align: center;
border-bottom-color: #FFFFFF; border-bottom-color: #FFFFFF;
@ -286,7 +283,7 @@ Probability and Likelihood
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#ibvcfeegcr .gt_title { #gqllsnwjsv .gt_title {
color: #333333; color: #333333;
font-size: 125%; font-size: 125%;
font-weight: initial; font-weight: initial;
@ -298,7 +295,7 @@ Probability and Likelihood
border-bottom-width: 0; border-bottom-width: 0;
} }
#ibvcfeegcr .gt_subtitle { #gqllsnwjsv .gt_subtitle {
color: #333333; color: #333333;
font-size: 85%; font-size: 85%;
font-weight: initial; font-weight: initial;
@ -310,13 +307,13 @@ Probability and Likelihood
border-top-width: 0; border-top-width: 0;
} }
#ibvcfeegcr .gt_bottom_border { #gqllsnwjsv .gt_bottom_border {
border-bottom-style: solid; border-bottom-style: solid;
border-bottom-width: 2px; border-bottom-width: 2px;
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
} }
#ibvcfeegcr .gt_col_headings { #gqllsnwjsv .gt_col_headings {
border-top-style: solid; border-top-style: solid;
border-top-width: 2px; border-top-width: 2px;
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
@ -331,7 +328,7 @@ Probability and Likelihood
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#ibvcfeegcr .gt_col_heading { #gqllsnwjsv .gt_col_heading {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -351,7 +348,7 @@ Probability and Likelihood
overflow-x: hidden; overflow-x: hidden;
} }
#ibvcfeegcr .gt_column_spanner_outer { #gqllsnwjsv .gt_column_spanner_outer {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -363,15 +360,15 @@ Probability and Likelihood
padding-right: 4px; padding-right: 4px;
} }
#ibvcfeegcr .gt_column_spanner_outer:first-child { #gqllsnwjsv .gt_column_spanner_outer:first-child {
padding-left: 0; padding-left: 0;
} }
#ibvcfeegcr .gt_column_spanner_outer:last-child { #gqllsnwjsv .gt_column_spanner_outer:last-child {
padding-right: 0; padding-right: 0;
} }
#ibvcfeegcr .gt_column_spanner { #gqllsnwjsv .gt_column_spanner {
border-bottom-style: solid; border-bottom-style: solid;
border-bottom-width: 2px; border-bottom-width: 2px;
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
@ -383,7 +380,7 @@ Probability and Likelihood
width: 100%; width: 100%;
} }
#ibvcfeegcr .gt_group_heading { #gqllsnwjsv .gt_group_heading {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -408,7 +405,7 @@ Probability and Likelihood
vertical-align: middle; vertical-align: middle;
} }
#ibvcfeegcr .gt_empty_group_heading { #gqllsnwjsv .gt_empty_group_heading {
padding: 0.5px; padding: 0.5px;
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
@ -423,15 +420,15 @@ Probability and Likelihood
vertical-align: middle; vertical-align: middle;
} }
#ibvcfeegcr .gt_from_md > :first-child { #gqllsnwjsv .gt_from_md > :first-child {
margin-top: 0; margin-top: 0;
} }
#ibvcfeegcr .gt_from_md > :last-child { #gqllsnwjsv .gt_from_md > :last-child {
margin-bottom: 0; margin-bottom: 0;
} }
#ibvcfeegcr .gt_row { #gqllsnwjsv .gt_row {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -450,7 +447,7 @@ Probability and Likelihood
overflow-x: hidden; overflow-x: hidden;
} }
#ibvcfeegcr .gt_stub { #gqllsnwjsv .gt_stub {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -463,7 +460,7 @@ Probability and Likelihood
padding-right: 5px; padding-right: 5px;
} }
#ibvcfeegcr .gt_stub_row_group { #gqllsnwjsv .gt_stub_row_group {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -477,11 +474,11 @@ Probability and Likelihood
vertical-align: top; vertical-align: top;
} }
#ibvcfeegcr .gt_row_group_first td { #gqllsnwjsv .gt_row_group_first td {
border-top-width: 2px; border-top-width: 2px;
} }
#ibvcfeegcr .gt_summary_row { #gqllsnwjsv .gt_summary_row {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
text-transform: inherit; text-transform: inherit;
@ -491,16 +488,16 @@ Probability and Likelihood
padding-right: 5px; padding-right: 5px;
} }
#ibvcfeegcr .gt_first_summary_row { #gqllsnwjsv .gt_first_summary_row {
border-top-style: solid; border-top-style: solid;
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
} }
#ibvcfeegcr .gt_first_summary_row.thick { #gqllsnwjsv .gt_first_summary_row.thick {
border-top-width: 2px; border-top-width: 2px;
} }
#ibvcfeegcr .gt_last_summary_row { #gqllsnwjsv .gt_last_summary_row {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -510,7 +507,7 @@ Probability and Likelihood
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
} }
#ibvcfeegcr .gt_grand_summary_row { #gqllsnwjsv .gt_grand_summary_row {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
text-transform: inherit; text-transform: inherit;
@ -520,7 +517,7 @@ Probability and Likelihood
padding-right: 5px; padding-right: 5px;
} }
#ibvcfeegcr .gt_first_grand_summary_row { #gqllsnwjsv .gt_first_grand_summary_row {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -530,11 +527,11 @@ Probability and Likelihood
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
} }
#ibvcfeegcr .gt_striped { #gqllsnwjsv .gt_striped {
background-color: rgba(128, 128, 128, 0.05); background-color: rgba(128, 128, 128, 0.05);
} }
#ibvcfeegcr .gt_table_body { #gqllsnwjsv .gt_table_body {
border-top-style: solid; border-top-style: solid;
border-top-width: 2px; border-top-width: 2px;
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
@ -543,7 +540,7 @@ Probability and Likelihood
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
} }
#ibvcfeegcr .gt_footnotes { #gqllsnwjsv .gt_footnotes {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
border-bottom-style: none; border-bottom-style: none;
@ -557,7 +554,7 @@ Probability and Likelihood
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#ibvcfeegcr .gt_footnote { #gqllsnwjsv .gt_footnote {
margin: 0px; margin: 0px;
font-size: 90%; font-size: 90%;
padding-left: 4px; padding-left: 4px;
@ -566,7 +563,7 @@ Probability and Likelihood
padding-right: 5px; padding-right: 5px;
} }
#ibvcfeegcr .gt_sourcenotes { #gqllsnwjsv .gt_sourcenotes {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
border-bottom-style: none; border-bottom-style: none;
@ -580,7 +577,7 @@ Probability and Likelihood
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#ibvcfeegcr .gt_sourcenote { #gqllsnwjsv .gt_sourcenote {
font-size: 90%; font-size: 90%;
padding-top: 4px; padding-top: 4px;
padding-bottom: 4px; padding-bottom: 4px;
@ -588,64 +585,64 @@ Probability and Likelihood
padding-right: 5px; padding-right: 5px;
} }
#ibvcfeegcr .gt_left { #gqllsnwjsv .gt_left {
text-align: left; text-align: left;
} }
#ibvcfeegcr .gt_center { #gqllsnwjsv .gt_center {
text-align: center; text-align: center;
} }
#ibvcfeegcr .gt_right { #gqllsnwjsv .gt_right {
text-align: right; text-align: right;
font-variant-numeric: tabular-nums; font-variant-numeric: tabular-nums;
} }
#ibvcfeegcr .gt_font_normal { #gqllsnwjsv .gt_font_normal {
font-weight: normal; font-weight: normal;
} }
#ibvcfeegcr .gt_font_bold { #gqllsnwjsv .gt_font_bold {
font-weight: bold; font-weight: bold;
} }
#ibvcfeegcr .gt_font_italic { #gqllsnwjsv .gt_font_italic {
font-style: italic; font-style: italic;
} }
#ibvcfeegcr .gt_super { #gqllsnwjsv .gt_super {
font-size: 65%; font-size: 65%;
} }
#ibvcfeegcr .gt_footnote_marks { #gqllsnwjsv .gt_footnote_marks {
font-style: italic; font-style: italic;
font-weight: normal; font-weight: normal;
font-size: 75%; font-size: 75%;
vertical-align: 0.4em; vertical-align: 0.4em;
} }
#ibvcfeegcr .gt_asterisk { #gqllsnwjsv .gt_asterisk {
font-size: 100%; font-size: 100%;
vertical-align: 0; vertical-align: 0;
} }
#ibvcfeegcr .gt_indent_1 { #gqllsnwjsv .gt_indent_1 {
text-indent: 5px; text-indent: 5px;
} }
#ibvcfeegcr .gt_indent_2 { #gqllsnwjsv .gt_indent_2 {
text-indent: 10px; text-indent: 10px;
} }
#ibvcfeegcr .gt_indent_3 { #gqllsnwjsv .gt_indent_3 {
text-indent: 15px; text-indent: 15px;
} }
#ibvcfeegcr .gt_indent_4 { #gqllsnwjsv .gt_indent_4 {
text-indent: 20px; text-indent: 20px;
} }
#ibvcfeegcr .gt_indent_5 { #gqllsnwjsv .gt_indent_5 {
text-indent: 25px; text-indent: 25px;
} }
</style> </style>
@ -854,12 +851,12 @@ Bayes Rule
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> gt<span class="sc">::</span><span class="fu">cols_width</span>(<span class="fu">everything</span>() <span class="sc">~</span> <span class="fu">px</span>(<span class="dv">100</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> <span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> gt<span class="sc">::</span><span class="fu">cols_width</span>(<span class="fu">everything</span>() <span class="sc">~</span> <span class="fu">px</span>(<span class="dv">100</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display"> <div class="cell-output-display">
<div id="dpxebxbyvj" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;"> <div id="roxupfdiiw" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>html { <style>html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
} }
#dpxebxbyvj .gt_table { #roxupfdiiw .gt_table {
display: table; display: table;
border-collapse: collapse; border-collapse: collapse;
margin-left: auto; margin-left: auto;
@ -884,7 +881,7 @@ Bayes Rule
border-left-color: #D3D3D3; border-left-color: #D3D3D3;
} }
#dpxebxbyvj .gt_heading { #roxupfdiiw .gt_heading {
background-color: #FFFFFF; background-color: #FFFFFF;
text-align: center; text-align: center;
border-bottom-color: #FFFFFF; border-bottom-color: #FFFFFF;
@ -896,7 +893,7 @@ Bayes Rule
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#dpxebxbyvj .gt_title { #roxupfdiiw .gt_title {
color: #333333; color: #333333;
font-size: 125%; font-size: 125%;
font-weight: initial; font-weight: initial;
@ -908,7 +905,7 @@ Bayes Rule
border-bottom-width: 0; border-bottom-width: 0;
} }
#dpxebxbyvj .gt_subtitle { #roxupfdiiw .gt_subtitle {
color: #333333; color: #333333;
font-size: 85%; font-size: 85%;
font-weight: initial; font-weight: initial;
@ -920,13 +917,13 @@ Bayes Rule
border-top-width: 0; border-top-width: 0;
} }
#dpxebxbyvj .gt_bottom_border { #roxupfdiiw .gt_bottom_border {
border-bottom-style: solid; border-bottom-style: solid;
border-bottom-width: 2px; border-bottom-width: 2px;
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
} }
#dpxebxbyvj .gt_col_headings { #roxupfdiiw .gt_col_headings {
border-top-style: solid; border-top-style: solid;
border-top-width: 2px; border-top-width: 2px;
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
@ -941,7 +938,7 @@ Bayes Rule
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#dpxebxbyvj .gt_col_heading { #roxupfdiiw .gt_col_heading {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -961,7 +958,7 @@ Bayes Rule
overflow-x: hidden; overflow-x: hidden;
} }
#dpxebxbyvj .gt_column_spanner_outer { #roxupfdiiw .gt_column_spanner_outer {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -973,15 +970,15 @@ Bayes Rule
padding-right: 4px; padding-right: 4px;
} }
#dpxebxbyvj .gt_column_spanner_outer:first-child { #roxupfdiiw .gt_column_spanner_outer:first-child {
padding-left: 0; padding-left: 0;
} }
#dpxebxbyvj .gt_column_spanner_outer:last-child { #roxupfdiiw .gt_column_spanner_outer:last-child {
padding-right: 0; padding-right: 0;
} }
#dpxebxbyvj .gt_column_spanner { #roxupfdiiw .gt_column_spanner {
border-bottom-style: solid; border-bottom-style: solid;
border-bottom-width: 2px; border-bottom-width: 2px;
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
@ -993,7 +990,7 @@ Bayes Rule
width: 100%; width: 100%;
} }
#dpxebxbyvj .gt_group_heading { #roxupfdiiw .gt_group_heading {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -1018,7 +1015,7 @@ Bayes Rule
vertical-align: middle; vertical-align: middle;
} }
#dpxebxbyvj .gt_empty_group_heading { #roxupfdiiw .gt_empty_group_heading {
padding: 0.5px; padding: 0.5px;
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
@ -1033,15 +1030,15 @@ Bayes Rule
vertical-align: middle; vertical-align: middle;
} }
#dpxebxbyvj .gt_from_md > :first-child { #roxupfdiiw .gt_from_md > :first-child {
margin-top: 0; margin-top: 0;
} }
#dpxebxbyvj .gt_from_md > :last-child { #roxupfdiiw .gt_from_md > :last-child {
margin-bottom: 0; margin-bottom: 0;
} }
#dpxebxbyvj .gt_row { #roxupfdiiw .gt_row {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -1060,7 +1057,7 @@ Bayes Rule
overflow-x: hidden; overflow-x: hidden;
} }
#dpxebxbyvj .gt_stub { #roxupfdiiw .gt_stub {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -1073,7 +1070,7 @@ Bayes Rule
padding-right: 5px; padding-right: 5px;
} }
#dpxebxbyvj .gt_stub_row_group { #roxupfdiiw .gt_stub_row_group {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
font-size: 100%; font-size: 100%;
@ -1087,11 +1084,11 @@ Bayes Rule
vertical-align: top; vertical-align: top;
} }
#dpxebxbyvj .gt_row_group_first td { #roxupfdiiw .gt_row_group_first td {
border-top-width: 2px; border-top-width: 2px;
} }
#dpxebxbyvj .gt_summary_row { #roxupfdiiw .gt_summary_row {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
text-transform: inherit; text-transform: inherit;
@ -1101,16 +1098,16 @@ Bayes Rule
padding-right: 5px; padding-right: 5px;
} }
#dpxebxbyvj .gt_first_summary_row { #roxupfdiiw .gt_first_summary_row {
border-top-style: solid; border-top-style: solid;
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
} }
#dpxebxbyvj .gt_first_summary_row.thick { #roxupfdiiw .gt_first_summary_row.thick {
border-top-width: 2px; border-top-width: 2px;
} }
#dpxebxbyvj .gt_last_summary_row { #roxupfdiiw .gt_last_summary_row {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -1120,7 +1117,7 @@ Bayes Rule
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
} }
#dpxebxbyvj .gt_grand_summary_row { #roxupfdiiw .gt_grand_summary_row {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
text-transform: inherit; text-transform: inherit;
@ -1130,7 +1127,7 @@ Bayes Rule
padding-right: 5px; padding-right: 5px;
} }
#dpxebxbyvj .gt_first_grand_summary_row { #roxupfdiiw .gt_first_grand_summary_row {
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 5px; padding-left: 5px;
@ -1140,11 +1137,11 @@ Bayes Rule
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
} }
#dpxebxbyvj .gt_striped { #roxupfdiiw .gt_striped {
background-color: rgba(128, 128, 128, 0.05); background-color: rgba(128, 128, 128, 0.05);
} }
#dpxebxbyvj .gt_table_body { #roxupfdiiw .gt_table_body {
border-top-style: solid; border-top-style: solid;
border-top-width: 2px; border-top-width: 2px;
border-top-color: #D3D3D3; border-top-color: #D3D3D3;
@ -1153,7 +1150,7 @@ Bayes Rule
border-bottom-color: #D3D3D3; border-bottom-color: #D3D3D3;
} }
#dpxebxbyvj .gt_footnotes { #roxupfdiiw .gt_footnotes {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
border-bottom-style: none; border-bottom-style: none;
@ -1167,7 +1164,7 @@ Bayes Rule
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#dpxebxbyvj .gt_footnote { #roxupfdiiw .gt_footnote {
margin: 0px; margin: 0px;
font-size: 90%; font-size: 90%;
padding-left: 4px; padding-left: 4px;
@ -1176,7 +1173,7 @@ Bayes Rule
padding-right: 5px; padding-right: 5px;
} }
#dpxebxbyvj .gt_sourcenotes { #roxupfdiiw .gt_sourcenotes {
color: #333333; color: #333333;
background-color: #FFFFFF; background-color: #FFFFFF;
border-bottom-style: none; border-bottom-style: none;
@ -1190,7 +1187,7 @@ Bayes Rule
border-right-color: #D3D3D3; border-right-color: #D3D3D3;
} }
#dpxebxbyvj .gt_sourcenote { #roxupfdiiw .gt_sourcenote {
font-size: 90%; font-size: 90%;
padding-top: 4px; padding-top: 4px;
padding-bottom: 4px; padding-bottom: 4px;
@ -1198,64 +1195,64 @@ Bayes Rule
padding-right: 5px; padding-right: 5px;
} }
#dpxebxbyvj .gt_left { #roxupfdiiw .gt_left {
text-align: left; text-align: left;
} }
#dpxebxbyvj .gt_center { #roxupfdiiw .gt_center {
text-align: center; text-align: center;
} }
#dpxebxbyvj .gt_right { #roxupfdiiw .gt_right {
text-align: right; text-align: right;
font-variant-numeric: tabular-nums; font-variant-numeric: tabular-nums;
} }
#dpxebxbyvj .gt_font_normal { #roxupfdiiw .gt_font_normal {
font-weight: normal; font-weight: normal;
} }
#dpxebxbyvj .gt_font_bold { #roxupfdiiw .gt_font_bold {
font-weight: bold; font-weight: bold;
} }
#dpxebxbyvj .gt_font_italic { #roxupfdiiw .gt_font_italic {
font-style: italic; font-style: italic;
} }
#dpxebxbyvj .gt_super { #roxupfdiiw .gt_super {
font-size: 65%; font-size: 65%;
} }
#dpxebxbyvj .gt_footnote_marks { #roxupfdiiw .gt_footnote_marks {
font-style: italic; font-style: italic;
font-weight: normal; font-weight: normal;
font-size: 75%; font-size: 75%;
vertical-align: 0.4em; vertical-align: 0.4em;
} }
#dpxebxbyvj .gt_asterisk { #roxupfdiiw .gt_asterisk {
font-size: 100%; font-size: 100%;
vertical-align: 0; vertical-align: 0;
} }
#dpxebxbyvj .gt_indent_1 { #roxupfdiiw .gt_indent_1 {
text-indent: 5px; text-indent: 5px;
} }
#dpxebxbyvj .gt_indent_2 { #roxupfdiiw .gt_indent_2 {
text-indent: 10px; text-indent: 10px;
} }
#dpxebxbyvj .gt_indent_3 { #roxupfdiiw .gt_indent_3 {
text-indent: 15px; text-indent: 15px;
} }
#dpxebxbyvj .gt_indent_4 { #roxupfdiiw .gt_indent_4 {
text-indent: 20px; text-indent: 20px;
} }
#dpxebxbyvj .gt_indent_5 { #roxupfdiiw .gt_indent_5 {
text-indent: 25px; text-indent: 25px;
} }
</style> </style>
@ -1275,11 +1272,11 @@ Bayes Rule
</thead> </thead>
<tbody class="gt_table_body"> <tbody class="gt_table_body">
<tr><td class="gt_row gt_left">fake</td> <tr><td class="gt_row gt_left">fake</td>
<td class="gt_row gt_right">4031</td> <td class="gt_row gt_right">3967</td>
<td class="gt_row gt_right">0.4031</td></tr> <td class="gt_row gt_right">0.3967</td></tr>
<tr><td class="gt_row gt_left">real</td> <tr><td class="gt_row gt_left">real</td>
<td class="gt_row gt_right">5969</td> <td class="gt_row gt_right">6033</td>
<td class="gt_row gt_right">0.5969</td></tr> <td class="gt_row gt_right">0.6033</td></tr>
</tbody> </tbody>
@ -1316,8 +1313,8 @@ Bayes Rule
# Groups: usage [2] # Groups: usage [2]
usage fake real usage fake real
&lt;chr&gt; &lt;int&gt; &lt;int&gt; &lt;chr&gt; &lt;int&gt; &lt;int&gt;
1 no 2955 5845 1 no 2891 5910
2 yes 1076 124</code></pre> 2 yes 1076 123</code></pre>
</div> </div>
</div> </div>
<div class="cell"> <div class="cell">
@ -1345,7 +1342,7 @@ Bayes Rule
type total prop type total prop
&lt;chr&gt; &lt;int&gt; &lt;dbl&gt; &lt;chr&gt; &lt;int&gt; &lt;dbl&gt;
1 fake 1076 0.897 1 fake 1076 0.897
2 real 124 0.103</code></pre> 2 real 123 0.103</code></pre>
</div> </div>
</div> </div>
</section> </section>
@ -1373,7 +1370,7 @@ Bayes Rule
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div class="callout-caution callout callout-style-default no-icon callout-captioned"> <div class="callout-tip callout callout-style-default no-icon callout-captioned">
<div class="callout-header d-flex align-content-center"> <div class="callout-header d-flex align-content-center">
<div class="callout-icon-container"> <div class="callout-icon-container">
<i class="callout-icon no-icon"></i> <i class="callout-icon no-icon"></i>
@ -1404,7 +1401,7 @@ Discrete Probability Model
</ol> </ol>
</div> </div>
</div> </div>
<div class="callout-caution callout callout-style-default no-icon callout-captioned"> <div class="callout-tip callout callout-style-default no-icon callout-captioned">
<div class="callout-header d-flex align-content-center"> <div class="callout-header d-flex align-content-center">
<div class="callout-icon-container"> <div class="callout-icon-container">
<i class="callout-icon no-icon"></i> <i class="callout-icon no-icon"></i>
@ -1417,8 +1414,7 @@ in emanuels words
<p>what does this mean? well its very straightforward a pmf is a function that takes in a some value y and outputs the probability that the random variable <span class="math inline">\(Y\)</span> equals <span class="math inline">\(y\)</span>.</p> <p>what does this mean? well its very straightforward a pmf is a function that takes in a some value y and outputs the probability that the random variable <span class="math inline">\(Y\)</span> equals <span class="math inline">\(y\)</span>.</p>
</div> </div>
</div> </div>
<section id="the-binomial-model" class="level3"> <p>next we would like add a the dependancy of <span class="math inline">\(Y\)</span> on <span class="math inline">\(\pi\)</span>, we do so by introducing the conditional pmf.</p>
<h3 class="anchored" data-anchor-id="the-binomial-model">The Binomial Model</h3>
<div class="callout-note callout callout-style-default no-icon callout-captioned"> <div class="callout-note callout callout-style-default no-icon callout-captioned">
<div class="callout-header d-flex align-content-center"> <div class="callout-header d-flex align-content-center">
<div class="callout-icon-container"> <div class="callout-icon-container">
@ -1438,7 +1434,7 @@ Conditional probability model of data <span class="math inline">\(Y\)</span>
</ol> </ol>
</div> </div>
</div> </div>
<div class="callout-caution callout callout-style-default no-icon callout-captioned"> <div class="callout-tip callout callout-style-default no-icon callout-captioned">
<div class="callout-header d-flex align-content-center"> <div class="callout-header d-flex align-content-center">
<div class="callout-icon-container"> <div class="callout-icon-container">
<i class="callout-icon no-icon"></i> <i class="callout-icon no-icon"></i>
@ -1451,7 +1447,145 @@ in emanuels words
<p>this is essentially the same probability model had defined above, except now we are condition probabilities by some parameter <span class="math inline">\(\pi\)</span></p> <p>this is essentially the same probability model had defined above, except now we are condition probabilities by some parameter <span class="math inline">\(\pi\)</span></p>
</div> </div>
</div> </div>
</section> <p>in the example of the chess player we must make some assumptions:</p>
<ol type="1">
<li><p>the chances of winning any match in the game stay constant. So if at match number 1 human has a .65% of winning, then that is the same for match 2-6.</p></li>
<li><p>Winning or loosing a game does not affect the chances of winning or loosing the next game, i.e matches are independent of one another.</p></li>
</ol>
<p>These two assumptions lead us to the <strong>Binomial Model</strong>.</p>
<div class="callout-note callout callout-style-default no-icon callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
The Binomial Model
</div>
</div>
<div class="callout-body-container callout-body">
<p>Let the random variable <span class="math inline">\(Y\)</span> represent the number of successes in <span class="math inline">\(n\)</span> trials. Assume that each trial is independent, and the probability of sucess in a given trial is <span class="math inline">\(\pi\)</span>. Then the conditional dependence of <span class="math inline">\(Y\)</span> on <span class="math inline">\(\pi\)</span> can be modeled by the <strong>Binomial Model</strong> with parameters <span class="math inline">\(n\)</span> and <span class="math inline">\(\pi\)</span>. We can write this as,</p>
<p><span class="math display">\[Y|\pi \sim Bin(n, \pi)\]</span></p>
<p>the binomial model is specified by the pmf:</p>
<p><span class="math display">\[f(y|\pi) = {n \choose y} \pi^y(1 - \pi)^{n-y}\]</span></p>
</div>
</div>
<p>knowing this we can represent <span class="math inline">\(Y\)</span> the total number of matches out of 6 that the human can win.</p>
<p><span class="math display">\[Y|\pi \sim Bin(6, \pi)\]</span></p>
<p>and conditional pmf:</p>
<p><span class="math display">\[f(y|\pi) = {6 \choose y}\pi^y(1 - \pi)^{6 - y}\;\; \text{for } y \in \{1, 2, 3, 4, 5, 6\}\]</span></p>
<p>with the pmf we can now determine the probability of the human winning <span class="math inline">\(Y\)</span> matches out of 6 for any given value of <span class="math inline">\(\pi\)</span></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>chess_pmf <span class="ot">&lt;-</span> <span class="cf">function</span>(y, p, <span class="at">n =</span> <span class="dv">6</span>) {</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">choose</span>(n, y) <span class="sc">*</span> (p <span class="sc">^</span> y) <span class="sc">*</span> (<span class="dv">1</span> <span class="sc">-</span> p)<span class="sc">^</span>(n <span class="sc">-</span> y)</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a><span class="co"># what is probability that human wins 6 games given a pi value of .8 </span></span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a><span class="fu">chess_pmf</span>(<span class="at">y =</span> <span class="dv">5</span>, <span class="at">p =</span> .<span class="dv">8</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.393216</code></pre>
</div>
</div>
<div class="callout-tip callout callout-style-default no-icon callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
</div>
</div>
<div class="callout-body-container callout-body">
<p>the formula for the binomial is actually pretty intuitive, first you have the scalar <span class="math inline">\({n \choose y}\)</span> this will determine the total number of ways the player can win <span class="math inline">\(y\)</span> games out of the possible <span class="math inline">\(n\)</span>. This is first multiplied by the probablility of success in the <span class="math inline">\(n\)</span> trials since <span class="math inline">\((p ^ y)\)</span> can be re-written as <span class="math inline">\(p\times p\times \cdots \times p\)</span>, and then multiplied by the probability of <span class="math inline">\(n-y\)</span> failures <span class="math inline">\((1 - p)^{n - y}\)</span></p>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>pies <span class="ot">&lt;-</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">1</span>, <span class="at">by =</span> .<span class="dv">05</span>)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>py <span class="ot">&lt;-</span> <span class="fu">chess_pmf</span>(<span class="at">y =</span> <span class="dv">4</span>, <span class="at">p =</span> pies)</span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>d <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">pies =</span> pies, <span class="at">py =</span> py)</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a>d <span class="sc">|&gt;</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(pies, py)) <span class="sc">+</span> <span class="fu">geom_col</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="ch2_files/figure-html/unnamed-chunk-14-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>pies <span class="ot">&lt;-</span> <span class="fu">c</span>(.<span class="dv">2</span>, .<span class="dv">5</span>, .<span class="dv">8</span>)</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>ys <span class="ot">&lt;-</span> <span class="dv">0</span><span class="sc">:</span><span class="dv">6</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>d <span class="ot">&lt;-</span> tidyr<span class="sc">::</span><span class="fu">expand_grid</span>(pies, ys)</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>fys <span class="ot">&lt;-</span> purrr<span class="sc">::</span><span class="fu">map2_dbl</span>(d<span class="sc">$</span>ys, d<span class="sc">$</span>pies, <span class="sc">~</span><span class="fu">chess_pmf</span>(.x, .y), <span class="at">n=</span><span class="dv">6</span>)</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>d<span class="sc">$</span>fys <span class="ot">&lt;-</span> fys</span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>d<span class="sc">$</span>display_pi <span class="ot">&lt;-</span> <span class="fu">as.factor</span>(<span class="fu">paste</span>(<span class="st">"pi ="</span>, d<span class="sc">$</span>pies))</span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a>d <span class="sc">|&gt;</span></span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> ys, <span class="at">y =</span> fys)) <span class="sc">+</span> </span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_col</span>() <span class="sc">+</span> </span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="dv">0</span><span class="sc">:</span><span class="dv">6</span>) <span class="sc">+</span> </span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">facet_wrap</span>(<span class="fu">vars</span>(display_pi))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="ch2_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>The plot shows the three possible values for <span class="math inline">\(\pi\)</span> along with the value of the pmf for each of the possible matches the human can win in a game. The values of <span class="math inline">\(f(y|\pi)\)</span> are pretty intuitive, we would expect the random variable <span class="math inline">\(Y\)</span> to be lower when the value of <span class="math inline">\(\pi\)</span> is lower and higher when the value of <span class="math inline">\(\pi\)</span> is higher.</p>
<p>For the sake of the excercise lets add more values of <span class="math inline">\(\pi\)</span> so that we can see this shift happen in more detail.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>pies <span class="ot">&lt;-</span> <span class="fu">seq</span>(.<span class="dv">1</span>, .<span class="dv">9</span>, <span class="at">by =</span> .<span class="dv">1</span>)</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>ys <span class="ot">&lt;-</span> <span class="dv">0</span><span class="sc">:</span><span class="dv">6</span></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>d <span class="ot">&lt;-</span> tidyr<span class="sc">::</span><span class="fu">expand_grid</span>(pies, ys)</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>fys <span class="ot">&lt;-</span> purrr<span class="sc">::</span><span class="fu">map2_dbl</span>(d<span class="sc">$</span>ys, d<span class="sc">$</span>pies, <span class="sc">~</span><span class="fu">chess_pmf</span>(.x, .y), <span class="at">n=</span><span class="dv">6</span>)</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a>d<span class="sc">$</span>fys <span class="ot">&lt;-</span> fys</span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a>d<span class="sc">$</span>display_pi <span class="ot">&lt;-</span> <span class="fu">as.factor</span>(<span class="fu">paste</span>(<span class="st">"pi ="</span>, d<span class="sc">$</span>pies))</span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a>d <span class="sc">|&gt;</span></span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> ys, <span class="at">y =</span> fys)) <span class="sc">+</span> </span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_col</span>() <span class="sc">+</span> </span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="dv">0</span><span class="sc">:</span><span class="dv">6</span>) <span class="sc">+</span> </span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">facet_wrap</span>(<span class="fu">vars</span>(display_pi), <span class="at">nrow =</span> <span class="dv">3</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="ch2_files/figure-html/unnamed-chunk-16-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>as it turns out we learn that the human ended up winning just one game in the 1997 rematch, <span class="math inline">\(Y = 1\)</span>. The next step in our analysis is to determine how compatible this new data is with each value of <span class="math inline">\(\pi\)</span>, the likelihood that is.</p>
<p>This is very easy to do with all the work we have done so far:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>d <span class="sc">|&gt;</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(ys <span class="sc">==</span> <span class="dv">1</span>) <span class="sc">|&gt;</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(pies, fys)) <span class="sc">+</span> </span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_col</span>() <span class="sc">+</span> </span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(.<span class="dv">1</span>, .<span class="dv">9</span>, <span class="at">by =</span> .<span class="dv">1</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="ch2_files/figure-html/unnamed-chunk-17-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>Its very important to note the following</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="co"># this will sum to a value greater than 1!!</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>d <span class="sc">|&gt;</span></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(ys <span class="sc">==</span> <span class="dv">1</span>) <span class="sc">|&gt;</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">pull</span>(fys) <span class="sc">|&gt;</span></span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">sum</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 1.37907</code></pre>
</div>
</div>
<div class="callout-important callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Important
</div>
</div>
<div class="callout-body-container callout-body">
<p>this has been mentioned before but its an important message to drive home. Note that the reason why thes values sum to a value greater than 1 is that they are <strong>not</strong> probabilities, they are likelihoods. We are determining how likely each value of <span class="math inline">\(\pi\)</span> is given that we have observed <span class="math inline">\(Y = 1\)</span>.</p>
</div>
</div>
</section> </section>
</main> </main>

161
R/ch2.qmd
View File

@ -339,7 +339,7 @@ in the book that we will learn how to build these later on):
|--------|----|----|----|-------| |--------|----|----|----|-------|
|$f(\pi)$|.10 |.25 |.65 | 1 | |$f(\pi)$|.10 |.25 |.65 | 1 |
:::{.callout-caution} :::{.callout-tip}
## Note ## Note
its important to note here that the sum of the values of $\pi$ **do its important to note here that the sum of the values of $\pi$ **do
@ -364,14 +364,15 @@ and has the following properties
::: :::
:::{.callout-caution} :::{.callout-tip}
## in emanuel's words ## in emanuel's words
what does this mean? well its very straightforward a pmf is a function that takes what does this mean? well its very straightforward a pmf is a function that takes
in a some value y and outputs the probability that the random variable in a some value y and outputs the probability that the random variable
$Y$ equals $y$. $Y$ equals $y$.
::: :::
### The Binomial Model next we would like add a the dependancy of $Y$ on $\pi$, we do so by introducing
the conditional pmf.
:::{.callout-note} :::{.callout-note}
## Conditional probability model of data $Y$ ## Conditional probability model of data $Y$
@ -388,8 +389,158 @@ and has the following properties,
2. $\sum_{\forall y}f(y|\pi) = 1$ 2. $\sum_{\forall y}f(y|\pi) = 1$
::: :::
:::{.callout-caution} :::{.callout-tip}
## in emanuel's words ## in emanuel's words
this is essentially the same probability model had defined above, except this is essentially the same probability model had defined above, except
now we are condition probabilities by some parameter $\pi$ now we are condition probabilities by some parameter $\pi$
::: :::
in the example of the chess player we must make some assumptions:
1. the chances of winning any match in the game stay constant. So if
at match number 1 human has a .65% of winning, then that is the same
for match 2-6.
2. Winning or loosing a game does not affect the chances of winning
or loosing the next game, i.e matches are independent of one another.
These two assumptions lead us to the **Binomial Model**.
:::{.callout-note}
## The Binomial Model
Let the random variable $Y$ represent the number of successes in $n$ trials.
Assume that each trial is independent, and the probability of sucess in a
given trial is $\pi$. Then the conditional dependence of $Y$ on $\pi$ can
be modeled by the **Binomial Model** with parameters $n$ and $\pi$. We can
write this as,
$$Y|\pi \sim Bin(n, \pi)$$
the binomial model is specified by the pmf:
$$f(y|\pi) = {n \choose y} \pi^y(1 - \pi)^{n-y}$$
:::
knowing this we can represent $Y$ the total number of matches out of 6
that the human can win.
$$Y|\pi \sim Bin(6, \pi)$$
and conditional pmf:
$$f(y|\pi) = {6 \choose y}\pi^y(1 - \pi)^{6 - y}\;\; \text{for } y \in \{1, 2, 3, 4, 5, 6\}$$
with the pmf we can now determine the probability of the human winning $Y$ matches
out of 6 for any given value of $\pi$
```{r}
chess_pmf <- function(y, p, n = 6) {
choose(n, y) * (p ^ y) * (1 - p)^(n - y)
}
# what is probability that human wins 6 games given a pi value of .8
chess_pmf(y = 5, p = .8)
```
:::{.callout-tip}
##
the formula for the binomial is actually pretty intuitive, first you have
the scalar ${n \choose y}$ this will determine the total number of ways
the player can win $y$ games out of the possible $n$. This is first multiplied
by the probablility of success in the $n$ trials since $(p ^ y)$ can be
re-written as $p\times p\times \cdots \times p$, and then multiplied by
the probability of $n-y$ failures $(1 - p)^{n - y}$
:::
```{r}
pies <- seq(0, 1, by = .05)
py <- chess_pmf(y = 4, p = pies)
d <- data.frame(pies = pies, py = py)
d |>
ggplot(aes(pies, py)) + geom_col()
```
```{r}
pies <- c(.2, .5, .8)
ys <- 0:6
d <- tidyr::expand_grid(pies, ys)
fys <- purrr::map2_dbl(d$ys, d$pies, ~chess_pmf(.x, .y), n=6)
d$fys <- fys
d$display_pi <- as.factor(paste("pi =", d$pies))
d |>
ggplot(aes(x = ys, y = fys)) +
geom_col() +
scale_x_continuous(breaks = 0:6) +
facet_wrap(vars(display_pi))
```
The plot shows the three possible values for $\pi$ along
with the value of the pmf for each of the possible
matches the human can win in a game. The values of $f(y|\pi)$
are pretty intuitive, we would expect the random variable $Y$
to be lower when the value of $\pi$ is lower and higher when
the value of $\pi$ is higher.
For the sake of the excercise lets add more values of $\pi$
so that we can see this shift happen in more detail.
```{r}
pies <- seq(.1, .9, by = .1)
ys <- 0:6
d <- tidyr::expand_grid(pies, ys)
fys <- purrr::map2_dbl(d$ys, d$pies, ~chess_pmf(.x, .y), n=6)
d$fys <- fys
d$display_pi <- as.factor(paste("pi =", d$pies))
d |>
ggplot(aes(x = ys, y = fys)) +
geom_col() +
scale_x_continuous(breaks = 0:6) +
facet_wrap(vars(display_pi), nrow = 3)
```
as it turns out we learn that the human ended up winning just
one game in the 1997 rematch, $Y = 1$. The next step in our
analysis is to determine how compatible this new data is with
each value of $\pi$, the likelihood that is.
This is very easy to do with all the work we have done so far:
```{r}
d |>
filter(ys == 1) |>
ggplot(aes(pies, fys)) +
geom_col() +
scale_x_continuous(breaks = seq(.1, .9, by = .1))
```
It's very important to note the following
```{r}
# this will sum to a value greater than 1!!
d |>
filter(ys == 1) |>
pull(fys) |>
sum()
```
:::{.callout-important icon="true"}
this has been mentioned before but its an important message
to drive home. Note that the reason why thes values sum to a
value greater than 1 is that they are **not** probabilities, they
are likelihoods. We are determining how likely each value of
$\pi$ is given that we have observed $Y = 1$.
:::

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB