finish ch2 (needs review) started ch3

This commit is contained in:
Emanuel Rodriguez 2022-09-16 23:07:37 -07:00
parent 0ee8c085e8
commit 231da48b00
19 changed files with 3145 additions and 105 deletions

View File

@ -246,12 +246,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>
<div class="cell-output-display">
<div id="elqrvmpvcc" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<div id="ytbjahccmx" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
}
#elqrvmpvcc .gt_table {
#ytbjahccmx .gt_table {
display: table;
border-collapse: collapse;
margin-left: auto;
@ -276,7 +276,7 @@ Probability and Likelihood
border-left-color: #D3D3D3;
}
#elqrvmpvcc .gt_heading {
#ytbjahccmx .gt_heading {
background-color: #FFFFFF;
text-align: center;
border-bottom-color: #FFFFFF;
@ -288,7 +288,7 @@ Probability and Likelihood
border-right-color: #D3D3D3;
}
#elqrvmpvcc .gt_title {
#ytbjahccmx .gt_title {
color: #333333;
font-size: 125%;
font-weight: initial;
@ -300,7 +300,7 @@ Probability and Likelihood
border-bottom-width: 0;
}
#elqrvmpvcc .gt_subtitle {
#ytbjahccmx .gt_subtitle {
color: #333333;
font-size: 85%;
font-weight: initial;
@ -312,13 +312,13 @@ Probability and Likelihood
border-top-width: 0;
}
#elqrvmpvcc .gt_bottom_border {
#ytbjahccmx .gt_bottom_border {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#elqrvmpvcc .gt_col_headings {
#ytbjahccmx .gt_col_headings {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
@ -333,7 +333,7 @@ Probability and Likelihood
border-right-color: #D3D3D3;
}
#elqrvmpvcc .gt_col_heading {
#ytbjahccmx .gt_col_heading {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -353,7 +353,7 @@ Probability and Likelihood
overflow-x: hidden;
}
#elqrvmpvcc .gt_column_spanner_outer {
#ytbjahccmx .gt_column_spanner_outer {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -365,15 +365,15 @@ Probability and Likelihood
padding-right: 4px;
}
#elqrvmpvcc .gt_column_spanner_outer:first-child {
#ytbjahccmx .gt_column_spanner_outer:first-child {
padding-left: 0;
}
#elqrvmpvcc .gt_column_spanner_outer:last-child {
#ytbjahccmx .gt_column_spanner_outer:last-child {
padding-right: 0;
}
#elqrvmpvcc .gt_column_spanner {
#ytbjahccmx .gt_column_spanner {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
@ -385,7 +385,7 @@ Probability and Likelihood
width: 100%;
}
#elqrvmpvcc .gt_group_heading {
#ytbjahccmx .gt_group_heading {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -410,7 +410,7 @@ Probability and Likelihood
vertical-align: middle;
}
#elqrvmpvcc .gt_empty_group_heading {
#ytbjahccmx .gt_empty_group_heading {
padding: 0.5px;
color: #333333;
background-color: #FFFFFF;
@ -425,15 +425,15 @@ Probability and Likelihood
vertical-align: middle;
}
#elqrvmpvcc .gt_from_md > :first-child {
#ytbjahccmx .gt_from_md > :first-child {
margin-top: 0;
}
#elqrvmpvcc .gt_from_md > :last-child {
#ytbjahccmx .gt_from_md > :last-child {
margin-bottom: 0;
}
#elqrvmpvcc .gt_row {
#ytbjahccmx .gt_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -452,7 +452,7 @@ Probability and Likelihood
overflow-x: hidden;
}
#elqrvmpvcc .gt_stub {
#ytbjahccmx .gt_stub {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -465,7 +465,7 @@ Probability and Likelihood
padding-right: 5px;
}
#elqrvmpvcc .gt_stub_row_group {
#ytbjahccmx .gt_stub_row_group {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -479,11 +479,11 @@ Probability and Likelihood
vertical-align: top;
}
#elqrvmpvcc .gt_row_group_first td {
#ytbjahccmx .gt_row_group_first td {
border-top-width: 2px;
}
#elqrvmpvcc .gt_summary_row {
#ytbjahccmx .gt_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
@ -493,16 +493,16 @@ Probability and Likelihood
padding-right: 5px;
}
#elqrvmpvcc .gt_first_summary_row {
#ytbjahccmx .gt_first_summary_row {
border-top-style: solid;
border-top-color: #D3D3D3;
}
#elqrvmpvcc .gt_first_summary_row.thick {
#ytbjahccmx .gt_first_summary_row.thick {
border-top-width: 2px;
}
#elqrvmpvcc .gt_last_summary_row {
#ytbjahccmx .gt_last_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -512,7 +512,7 @@ Probability and Likelihood
border-bottom-color: #D3D3D3;
}
#elqrvmpvcc .gt_grand_summary_row {
#ytbjahccmx .gt_grand_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
@ -522,7 +522,7 @@ Probability and Likelihood
padding-right: 5px;
}
#elqrvmpvcc .gt_first_grand_summary_row {
#ytbjahccmx .gt_first_grand_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -532,11 +532,11 @@ Probability and Likelihood
border-top-color: #D3D3D3;
}
#elqrvmpvcc .gt_striped {
#ytbjahccmx .gt_striped {
background-color: rgba(128, 128, 128, 0.05);
}
#elqrvmpvcc .gt_table_body {
#ytbjahccmx .gt_table_body {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
@ -545,7 +545,7 @@ Probability and Likelihood
border-bottom-color: #D3D3D3;
}
#elqrvmpvcc .gt_footnotes {
#ytbjahccmx .gt_footnotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
@ -559,7 +559,7 @@ Probability and Likelihood
border-right-color: #D3D3D3;
}
#elqrvmpvcc .gt_footnote {
#ytbjahccmx .gt_footnote {
margin: 0px;
font-size: 90%;
padding-left: 4px;
@ -568,7 +568,7 @@ Probability and Likelihood
padding-right: 5px;
}
#elqrvmpvcc .gt_sourcenotes {
#ytbjahccmx .gt_sourcenotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
@ -582,7 +582,7 @@ Probability and Likelihood
border-right-color: #D3D3D3;
}
#elqrvmpvcc .gt_sourcenote {
#ytbjahccmx .gt_sourcenote {
font-size: 90%;
padding-top: 4px;
padding-bottom: 4px;
@ -590,64 +590,64 @@ Probability and Likelihood
padding-right: 5px;
}
#elqrvmpvcc .gt_left {
#ytbjahccmx .gt_left {
text-align: left;
}
#elqrvmpvcc .gt_center {
#ytbjahccmx .gt_center {
text-align: center;
}
#elqrvmpvcc .gt_right {
#ytbjahccmx .gt_right {
text-align: right;
font-variant-numeric: tabular-nums;
}
#elqrvmpvcc .gt_font_normal {
#ytbjahccmx .gt_font_normal {
font-weight: normal;
}
#elqrvmpvcc .gt_font_bold {
#ytbjahccmx .gt_font_bold {
font-weight: bold;
}
#elqrvmpvcc .gt_font_italic {
#ytbjahccmx .gt_font_italic {
font-style: italic;
}
#elqrvmpvcc .gt_super {
#ytbjahccmx .gt_super {
font-size: 65%;
}
#elqrvmpvcc .gt_footnote_marks {
#ytbjahccmx .gt_footnote_marks {
font-style: italic;
font-weight: normal;
font-size: 75%;
vertical-align: 0.4em;
}
#elqrvmpvcc .gt_asterisk {
#ytbjahccmx .gt_asterisk {
font-size: 100%;
vertical-align: 0;
}
#elqrvmpvcc .gt_indent_1 {
#ytbjahccmx .gt_indent_1 {
text-indent: 5px;
}
#elqrvmpvcc .gt_indent_2 {
#ytbjahccmx .gt_indent_2 {
text-indent: 10px;
}
#elqrvmpvcc .gt_indent_3 {
#ytbjahccmx .gt_indent_3 {
text-indent: 15px;
}
#elqrvmpvcc .gt_indent_4 {
#ytbjahccmx .gt_indent_4 {
text-indent: 20px;
}
#elqrvmpvcc .gt_indent_5 {
#ytbjahccmx .gt_indent_5 {
text-indent: 25px;
}
</style>
@ -856,12 +856,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>
<div class="cell-output-display">
<div id="szamjwnxyf" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<div id="yyakhpsztb" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
}
#szamjwnxyf .gt_table {
#yyakhpsztb .gt_table {
display: table;
border-collapse: collapse;
margin-left: auto;
@ -886,7 +886,7 @@ Bayes Rule
border-left-color: #D3D3D3;
}
#szamjwnxyf .gt_heading {
#yyakhpsztb .gt_heading {
background-color: #FFFFFF;
text-align: center;
border-bottom-color: #FFFFFF;
@ -898,7 +898,7 @@ Bayes Rule
border-right-color: #D3D3D3;
}
#szamjwnxyf .gt_title {
#yyakhpsztb .gt_title {
color: #333333;
font-size: 125%;
font-weight: initial;
@ -910,7 +910,7 @@ Bayes Rule
border-bottom-width: 0;
}
#szamjwnxyf .gt_subtitle {
#yyakhpsztb .gt_subtitle {
color: #333333;
font-size: 85%;
font-weight: initial;
@ -922,13 +922,13 @@ Bayes Rule
border-top-width: 0;
}
#szamjwnxyf .gt_bottom_border {
#yyakhpsztb .gt_bottom_border {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#szamjwnxyf .gt_col_headings {
#yyakhpsztb .gt_col_headings {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
@ -943,7 +943,7 @@ Bayes Rule
border-right-color: #D3D3D3;
}
#szamjwnxyf .gt_col_heading {
#yyakhpsztb .gt_col_heading {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -963,7 +963,7 @@ Bayes Rule
overflow-x: hidden;
}
#szamjwnxyf .gt_column_spanner_outer {
#yyakhpsztb .gt_column_spanner_outer {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -975,15 +975,15 @@ Bayes Rule
padding-right: 4px;
}
#szamjwnxyf .gt_column_spanner_outer:first-child {
#yyakhpsztb .gt_column_spanner_outer:first-child {
padding-left: 0;
}
#szamjwnxyf .gt_column_spanner_outer:last-child {
#yyakhpsztb .gt_column_spanner_outer:last-child {
padding-right: 0;
}
#szamjwnxyf .gt_column_spanner {
#yyakhpsztb .gt_column_spanner {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
@ -995,7 +995,7 @@ Bayes Rule
width: 100%;
}
#szamjwnxyf .gt_group_heading {
#yyakhpsztb .gt_group_heading {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -1020,7 +1020,7 @@ Bayes Rule
vertical-align: middle;
}
#szamjwnxyf .gt_empty_group_heading {
#yyakhpsztb .gt_empty_group_heading {
padding: 0.5px;
color: #333333;
background-color: #FFFFFF;
@ -1035,15 +1035,15 @@ Bayes Rule
vertical-align: middle;
}
#szamjwnxyf .gt_from_md > :first-child {
#yyakhpsztb .gt_from_md > :first-child {
margin-top: 0;
}
#szamjwnxyf .gt_from_md > :last-child {
#yyakhpsztb .gt_from_md > :last-child {
margin-bottom: 0;
}
#szamjwnxyf .gt_row {
#yyakhpsztb .gt_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -1062,7 +1062,7 @@ Bayes Rule
overflow-x: hidden;
}
#szamjwnxyf .gt_stub {
#yyakhpsztb .gt_stub {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -1075,7 +1075,7 @@ Bayes Rule
padding-right: 5px;
}
#szamjwnxyf .gt_stub_row_group {
#yyakhpsztb .gt_stub_row_group {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
@ -1089,11 +1089,11 @@ Bayes Rule
vertical-align: top;
}
#szamjwnxyf .gt_row_group_first td {
#yyakhpsztb .gt_row_group_first td {
border-top-width: 2px;
}
#szamjwnxyf .gt_summary_row {
#yyakhpsztb .gt_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
@ -1103,16 +1103,16 @@ Bayes Rule
padding-right: 5px;
}
#szamjwnxyf .gt_first_summary_row {
#yyakhpsztb .gt_first_summary_row {
border-top-style: solid;
border-top-color: #D3D3D3;
}
#szamjwnxyf .gt_first_summary_row.thick {
#yyakhpsztb .gt_first_summary_row.thick {
border-top-width: 2px;
}
#szamjwnxyf .gt_last_summary_row {
#yyakhpsztb .gt_last_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -1122,7 +1122,7 @@ Bayes Rule
border-bottom-color: #D3D3D3;
}
#szamjwnxyf .gt_grand_summary_row {
#yyakhpsztb .gt_grand_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
@ -1132,7 +1132,7 @@ Bayes Rule
padding-right: 5px;
}
#szamjwnxyf .gt_first_grand_summary_row {
#yyakhpsztb .gt_first_grand_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
@ -1142,11 +1142,11 @@ Bayes Rule
border-top-color: #D3D3D3;
}
#szamjwnxyf .gt_striped {
#yyakhpsztb .gt_striped {
background-color: rgba(128, 128, 128, 0.05);
}
#szamjwnxyf .gt_table_body {
#yyakhpsztb .gt_table_body {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
@ -1155,7 +1155,7 @@ Bayes Rule
border-bottom-color: #D3D3D3;
}
#szamjwnxyf .gt_footnotes {
#yyakhpsztb .gt_footnotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
@ -1169,7 +1169,7 @@ Bayes Rule
border-right-color: #D3D3D3;
}
#szamjwnxyf .gt_footnote {
#yyakhpsztb .gt_footnote {
margin: 0px;
font-size: 90%;
padding-left: 4px;
@ -1178,7 +1178,7 @@ Bayes Rule
padding-right: 5px;
}
#szamjwnxyf .gt_sourcenotes {
#yyakhpsztb .gt_sourcenotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
@ -1192,7 +1192,7 @@ Bayes Rule
border-right-color: #D3D3D3;
}
#szamjwnxyf .gt_sourcenote {
#yyakhpsztb .gt_sourcenote {
font-size: 90%;
padding-top: 4px;
padding-bottom: 4px;
@ -1200,64 +1200,64 @@ Bayes Rule
padding-right: 5px;
}
#szamjwnxyf .gt_left {
#yyakhpsztb .gt_left {
text-align: left;
}
#szamjwnxyf .gt_center {
#yyakhpsztb .gt_center {
text-align: center;
}
#szamjwnxyf .gt_right {
#yyakhpsztb .gt_right {
text-align: right;
font-variant-numeric: tabular-nums;
}
#szamjwnxyf .gt_font_normal {
#yyakhpsztb .gt_font_normal {
font-weight: normal;
}
#szamjwnxyf .gt_font_bold {
#yyakhpsztb .gt_font_bold {
font-weight: bold;
}
#szamjwnxyf .gt_font_italic {
#yyakhpsztb .gt_font_italic {
font-style: italic;
}
#szamjwnxyf .gt_super {
#yyakhpsztb .gt_super {
font-size: 65%;
}
#szamjwnxyf .gt_footnote_marks {
#yyakhpsztb .gt_footnote_marks {
font-style: italic;
font-weight: normal;
font-size: 75%;
vertical-align: 0.4em;
}
#szamjwnxyf .gt_asterisk {
#yyakhpsztb .gt_asterisk {
font-size: 100%;
vertical-align: 0;
}
#szamjwnxyf .gt_indent_1 {
#yyakhpsztb .gt_indent_1 {
text-indent: 5px;
}
#szamjwnxyf .gt_indent_2 {
#yyakhpsztb .gt_indent_2 {
text-indent: 10px;
}
#szamjwnxyf .gt_indent_3 {
#yyakhpsztb .gt_indent_3 {
text-indent: 15px;
}
#szamjwnxyf .gt_indent_4 {
#yyakhpsztb .gt_indent_4 {
text-indent: 20px;
}
#szamjwnxyf .gt_indent_5 {
#yyakhpsztb .gt_indent_5 {
text-indent: 25px;
}
</style>
@ -1277,11 +1277,11 @@ Bayes Rule
</thead>
<tbody class="gt_table_body">
<tr><td class="gt_row gt_left">fake</td>
<td class="gt_row gt_right">4130</td>
<td class="gt_row gt_right">0.413</td></tr>
<td class="gt_row gt_right">4037</td>
<td class="gt_row gt_right">0.4037</td></tr>
<tr><td class="gt_row gt_left">real</td>
<td class="gt_row gt_right">5870</td>
<td class="gt_row gt_right">0.587</td></tr>
<td class="gt_row gt_right">5963</td>
<td class="gt_row gt_right">0.5963</td></tr>
</tbody>
@ -1318,8 +1318,8 @@ Bayes Rule
# Groups: usage [2]
usage fake real
&lt;chr&gt; &lt;int&gt; &lt;int&gt;
1 no 3026 5732
2 yes 1104 138</code></pre>
1 no 2919 5824
2 yes 1118 139</code></pre>
</div>
</div>
<div class="cell">
@ -1346,8 +1346,8 @@ Bayes Rule
<pre><code># A tibble: 2 × 3
type total prop
&lt;chr&gt; &lt;int&gt; &lt;dbl&gt;
1 fake 1104 0.889
2 real 138 0.111</code></pre>
1 fake 1118 0.889
2 real 139 0.111</code></pre>
</div>
</div>
</section>
@ -1757,9 +1757,9 @@ Probability mass functions vs likelihood functions
<pre><code># A tibble: 3 × 3
pi n prop
&lt;dbl&gt; &lt;int&gt; &lt;dbl&gt;
1 0.2 401 0.631
2 0.5 224 0.352
3 0.8 11 0.0173</code></pre>
1 0.2 344 0.604
2 0.5 218 0.382
3 0.8 8 0.0140</code></pre>
</div>
</div>
</section>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,293 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.1.251">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Emanuel Rodriguez">
<title>Chapter 3 Beta-Binomial Bayesian Model Notes</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script src="ch3-beta-binomial_files/libs/clipboard/clipboard.min.js"></script>
<script src="ch3-beta-binomial_files/libs/quarto-html/quarto.js"></script>
<script src="ch3-beta-binomial_files/libs/quarto-html/popper.min.js"></script>
<script src="ch3-beta-binomial_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="ch3-beta-binomial_files/libs/quarto-html/anchor.min.js"></script>
<link href="ch3-beta-binomial_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="ch3-beta-binomial_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="ch3-beta-binomial_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="ch3-beta-binomial_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="ch3-beta-binomial_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script>window.backupDefine = window.define; window.define = undefined;</script><script src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js"></script>
<script>document.addEventListener("DOMContentLoaded", function () {
var mathElements = document.getElementsByClassName("math");
var macros = [];
for (var i = 0; i < mathElements.length; i++) {
var texText = mathElements[i].firstChild;
if (mathElements[i].tagName == "SPAN") {
katex.render(texText.data, mathElements[i], {
displayMode: mathElements[i].classList.contains('display'),
throwOnError: false,
macros: macros,
fleqn: false
});
}}});
</script>
<script>window.define = window.backupDefine; window.backupDefine = undefined;</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css">
<link rel="stylesheet" href="styles.css">
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Chapter 3 Beta-Binomial Bayesian Model Notes</h1>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p>Emanuel Rodriguez </p>
</div>
</div>
</div>
</header>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(bayesrules)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The chapter is set up with an example of polling results. We are put into the scenario where we are managig the campaing for a candidate. We know that on average her support based on recent polls is around 45%. In the next few sections well work through our Bayesian framework and incorporate a new tool the <strong>Beta-Binomial</strong> model. This model will take develop a continuous prior, as opposed to the discrete ones weve been working with so far.</p>
<section id="the-beta-prior" class="level2">
<h2 class="anchored" data-anchor-id="the-beta-prior">The Beta prior</h2>
<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">
Probability Density Function
</div>
</div>
<div class="callout-body-container callout-body">
<p>Let <span class="math inline">\pi</span> be a continuous random variable with probability density function (pdf) <span class="math inline">f(\pi)</span>. Then <span class="math inline">f(\pi)</span> has the following properties:</p>
<ol type="1">
<li><span class="math inline">f(\pi) \geq 0</span></li>
<li><span class="math inline">\int_{\pi}f(\pi)d\pi = 1</span> (this is analogous to <span class="math inline">\sum</span> in the case of pmfs)</li>
<li><span class="math inline">P(a &lt; \pi &lt; b) = \int_a^bf(\pi)d\pi</span> when <span class="math inline">a\leq b</span></li>
</ol>
</div>
</div>
<div class="callout-tip 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">
Tip
</div>
</div>
<div class="callout-body-container callout-body">
<p>a quick note on (1) above. Note that it does not place a restriction on <span class="math inline">f(\pi)</span> being less than 1. This means that we cant interpret values of <span class="math inline">f</span> as probabilities, we can however use to interpret plausability of two different events, the greater the value of <span class="math inline">f</span> the more plausible. To calculate probabilities using <span class="math inline">f</span> we must determine the area under the curve it defines, as shown in (3).</p>
</div>
</div>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
});
</script>
</div> <!-- /content -->
</body></html>

View File

@ -0,0 +1,53 @@
---
title: "Chapter 3 Beta-Binomial Bayesian Model Notes"
author: "Emanuel Rodriguez"
execute:
message: false
warning: false
format:
html:
monofont: "Cascadia Mono"
highlight-style: gruvbox-dark
css: styles.css
callout-icon: false
callout-apperance: simple
toc: false
html-math-method: katex
---
```{r}
library(bayesrules)
library(tidyverse)
```
The chapter is set up with an example of polling results. We are put into
the scenario where we are managig the campaing for a candidate. We know
that on average her support based on recent polls is around 45%. In the
next few sections we'll work through our Bayesian framework and incorporate
a new tool the **Beta-Binomial** model. This model will take develop a
continuous prior, as opposed to the discrete one's we've been working with
so far.
## The Beta prior
:::{.callout-note}
## Probability Density Function
Let $\pi$ be a continuous random variable with probability density
function (pdf) $f(\pi)$. Then $f(\pi)$ has the following properties:
1. $f(\pi) \geq 0$
2. $\int_{\pi}f(\pi)d\pi = 1$ (this is analogous to $\sum$ in the case of pmfs)
3. $P(a < \pi < b) = \int_a^bf(\pi)d\pi$ when $a\leq b$
:::
:::{.callout-tip icon="true"}
a quick note on (1) above. Note that it does not place a restriction on
$f(\pi)$ being less than 1. This means that we can't interpret values of
$f$ as probabilities, we can however use to interpret plausability of
two different events, the greater the value of $f$ the more plausible.
To calculate probabilities using $f$ we must determine the area under the
curve it defines, as shown in (3).
:::

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,182 @@
/* quarto syntax highlight colors */
:root {
--quarto-hl-kw-color: #ebdbb2;
--quarto-hl-fu-color: #689d6a;
--quarto-hl-va-color: #458588;
--quarto-hl-cf-color: #cc241d;
--quarto-hl-op-color: #ebdbb2;
--quarto-hl-bu-color: #d65d0e;
--quarto-hl-ex-color: #689d6a;
--quarto-hl-pp-color: #d65d0e;
--quarto-hl-at-color: #d79921;
--quarto-hl-ch-color: #b16286;
--quarto-hl-sc-color: #b16286;
--quarto-hl-st-color: #98971a;
--quarto-hl-vs-color: #98971a;
--quarto-hl-ss-color: #98971a;
--quarto-hl-im-color: #689d6a;
--quarto-hl-dt-color: #d79921;
--quarto-hl-dv-color: #f67400;
--quarto-hl-bn-color: #f67400;
--quarto-hl-fl-color: #f67400;
--quarto-hl-cn-color: #b16286;
--quarto-hl-co-color: #928374;
--quarto-hl-do-color: #98971a;
--quarto-hl-an-color: #98971a;
--quarto-hl-cv-color: #928374;
--quarto-hl-re-color: #928374;
--quarto-hl-in-color: #282828;
--quarto-hl-wa-color: #282828;
--quarto-hl-al-color: #282828;
--quarto-hl-er-color: #cc241d;
}
/* other quarto variables */
:root {
--quarto-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
pre > code.sourceCode > span {
color: #ebdbb2;
}
code span {
color: #ebdbb2;
}
code.sourceCode > span {
color: #ebdbb2;
}
div.sourceCode,
div.sourceCode pre.sourceCode {
color: #ebdbb2;
}
code span.kw {
color: #ebdbb2;
font-weight: bold;
}
code span.fu {
color: #689d6a;
}
code span.va {
color: #458588;
}
code span.cf {
color: #cc241d;
font-weight: bold;
}
code span.op {
color: #ebdbb2;
}
code span.bu {
color: #d65d0e;
}
code span.ex {
color: #689d6a;
font-weight: bold;
}
code span.pp {
color: #d65d0e;
}
code span.at {
color: #d79921;
}
code span.ch {
color: #b16286;
}
code span.sc {
color: #b16286;
}
code span.st {
color: #98971a;
}
code span.vs {
color: #98971a;
}
code span.ss {
color: #98971a;
}
code span.im {
color: #689d6a;
}
code span.dt {
color: #d79921;
}
code span.dv {
color: #f67400;
}
code span.bn {
color: #f67400;
}
code span.fl {
color: #f67400;
}
code span.cn {
color: #b16286;
font-weight: bold;
}
code span.co {
color: #928374;
}
code span.do {
color: #98971a;
}
code span.an {
color: #98971a;
}
code span.cv {
color: #928374;
}
code span.re {
color: #928374;
}
code span.in {
color: #282828;
}
code span.wa {
color: #282828;
}
code span.al {
color: #282828;
font-weight: bold;
}
code span.er {
color: #cc241d;
text-decoration: underline;
}
.prevent-inlining {
content: "</";
}
/*# sourceMappingURL=debc5d5d77c3f9108843748ff7464032.css.map */

View File

@ -0,0 +1,760 @@
const sectionChanged = new CustomEvent("quarto-sectionChanged", {
detail: {},
bubbles: true,
cancelable: false,
composed: false,
});
window.document.addEventListener("DOMContentLoaded", function (_event) {
const tocEl = window.document.querySelector('nav.toc-active[role="doc-toc"]');
const sidebarEl = window.document.getElementById("quarto-sidebar");
const leftTocEl = window.document.getElementById("quarto-sidebar-toc-left");
const marginSidebarEl = window.document.getElementById(
"quarto-margin-sidebar"
);
// function to determine whether the element has a previous sibling that is active
const prevSiblingIsActiveLink = (el) => {
const sibling = el.previousElementSibling;
if (sibling && sibling.tagName === "A") {
return sibling.classList.contains("active");
} else {
return false;
}
};
// fire slideEnter for bootstrap tab activations (for htmlwidget resize behavior)
function fireSlideEnter(e) {
const event = window.document.createEvent("Event");
event.initEvent("slideenter", true, true);
window.document.dispatchEvent(event);
}
const tabs = window.document.querySelectorAll('a[data-bs-toggle="tab"]');
tabs.forEach((tab) => {
tab.addEventListener("shown.bs.tab", fireSlideEnter);
});
// Track scrolling and mark TOC links as active
// get table of contents and sidebar (bail if we don't have at least one)
const tocLinks = tocEl
? [...tocEl.querySelectorAll("a[data-scroll-target]")]
: [];
const makeActive = (link) => tocLinks[link].classList.add("active");
const removeActive = (link) => tocLinks[link].classList.remove("active");
const removeAllActive = () =>
[...Array(tocLinks.length).keys()].forEach((link) => removeActive(link));
// activate the anchor for a section associated with this TOC entry
tocLinks.forEach((link) => {
link.addEventListener("click", () => {
if (link.href.indexOf("#") !== -1) {
const anchor = link.href.split("#")[1];
const heading = window.document.querySelector(
`[data-anchor-id=${anchor}]`
);
if (heading) {
// Add the class
heading.classList.add("reveal-anchorjs-link");
// function to show the anchor
const handleMouseout = () => {
heading.classList.remove("reveal-anchorjs-link");
heading.removeEventListener("mouseout", handleMouseout);
};
// add a function to clear the anchor when the user mouses out of it
heading.addEventListener("mouseout", handleMouseout);
}
}
});
});
const sections = tocLinks.map((link) => {
const target = link.getAttribute("data-scroll-target");
if (target.startsWith("#")) {
return window.document.getElementById(decodeURI(`${target.slice(1)}`));
} else {
return window.document.querySelector(decodeURI(`${target}`));
}
});
const sectionMargin = 200;
let currentActive = 0;
// track whether we've initialized state the first time
let init = false;
const updateActiveLink = () => {
// The index from bottom to top (e.g. reversed list)
let sectionIndex = -1;
if (
window.innerHeight + window.pageYOffset >=
window.document.body.offsetHeight
) {
sectionIndex = 0;
} else {
sectionIndex = [...sections].reverse().findIndex((section) => {
if (section) {
return window.pageYOffset >= section.offsetTop - sectionMargin;
} else {
return false;
}
});
}
if (sectionIndex > -1) {
const current = sections.length - sectionIndex - 1;
if (current !== currentActive) {
removeAllActive();
currentActive = current;
makeActive(current);
if (init) {
window.dispatchEvent(sectionChanged);
}
init = true;
}
}
};
const inHiddenRegion = (top, bottom, hiddenRegions) => {
for (const region of hiddenRegions) {
if (top <= region.bottom && bottom >= region.top) {
return true;
}
}
return false;
};
const categorySelector = "header.quarto-title-block .quarto-category";
const activateCategories = (href) => {
// Find any categories
// Surround them with a link pointing back to:
// #category=Authoring
try {
const categoryEls = window.document.querySelectorAll(categorySelector);
for (const categoryEl of categoryEls) {
const categoryText = categoryEl.textContent;
if (categoryText) {
const link = `${href}#category=${encodeURIComponent(categoryText)}`;
const linkEl = window.document.createElement("a");
linkEl.setAttribute("href", link);
for (const child of categoryEl.childNodes) {
linkEl.append(child);
}
categoryEl.appendChild(linkEl);
}
}
} catch {
// Ignore errors
}
};
function hasTitleCategories() {
return window.document.querySelector(categorySelector) !== null;
}
function offsetRelativeUrl(url) {
const offset = getMeta("quarto:offset");
return offset ? offset + url : url;
}
function offsetAbsoluteUrl(url) {
const offset = getMeta("quarto:offset");
const baseUrl = new URL(offset, window.location);
const projRelativeUrl = url.replace(baseUrl, "");
if (projRelativeUrl.startsWith("/")) {
return projRelativeUrl;
} else {
return "/" + projRelativeUrl;
}
}
// read a meta tag value
function getMeta(metaName) {
const metas = window.document.getElementsByTagName("meta");
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute("name") === metaName) {
return metas[i].getAttribute("content");
}
}
return "";
}
async function findAndActivateCategories() {
const currentPagePath = offsetAbsoluteUrl(window.location.href);
const response = await fetch(offsetRelativeUrl("listings.json"));
if (response.status == 200) {
return response.json().then(function (listingPaths) {
const listingHrefs = [];
for (const listingPath of listingPaths) {
const pathWithoutLeadingSlash = listingPath.listing.substring(1);
for (const item of listingPath.items) {
if (
item === currentPagePath ||
item === currentPagePath + "index.html"
) {
// Resolve this path against the offset to be sure
// we already are using the correct path to the listing
// (this adjusts the listing urls to be rooted against
// whatever root the page is actually running against)
const relative = offsetRelativeUrl(pathWithoutLeadingSlash);
const baseUrl = window.location;
const resolvedPath = new URL(relative, baseUrl);
listingHrefs.push(resolvedPath.pathname);
break;
}
}
}
// Look up the tree for a nearby linting and use that if we find one
const nearestListing = findNearestParentListing(
offsetAbsoluteUrl(window.location.pathname),
listingHrefs
);
if (nearestListing) {
activateCategories(nearestListing);
} else {
// See if the referrer is a listing page for this item
const referredRelativePath = offsetAbsoluteUrl(document.referrer);
const referrerListing = listingHrefs.find((listingHref) => {
const isListingReferrer =
listingHref === referredRelativePath ||
listingHref === referredRelativePath + "index.html";
return isListingReferrer;
});
if (referrerListing) {
// Try to use the referrer if possible
activateCategories(referrerListing);
} else if (listingHrefs.length > 0) {
// Otherwise, just fall back to the first listing
activateCategories(listingHrefs[0]);
}
}
});
}
}
if (hasTitleCategories()) {
findAndActivateCategories();
}
const findNearestParentListing = (href, listingHrefs) => {
if (!href || !listingHrefs) {
return undefined;
}
// Look up the tree for a nearby linting and use that if we find one
const relativeParts = href.substring(1).split("/");
while (relativeParts.length > 0) {
const path = relativeParts.join("/");
for (const listingHref of listingHrefs) {
if (listingHref.startsWith(path)) {
return listingHref;
}
}
relativeParts.pop();
}
return undefined;
};
const manageSidebarVisiblity = (el, placeholderDescriptor) => {
let isVisible = true;
return (hiddenRegions) => {
if (el === null) {
return;
}
// Find the last element of the TOC
const lastChildEl = el.lastElementChild;
if (lastChildEl) {
// Find the top and bottom o the element that is being managed
const elTop = el.offsetTop;
const elBottom =
elTop + lastChildEl.offsetTop + lastChildEl.offsetHeight;
// Converts the sidebar to a menu
const convertToMenu = () => {
for (const child of el.children) {
child.style.opacity = 0;
child.style.overflow = "hidden";
}
const toggleContainer = window.document.createElement("div");
toggleContainer.style.width = "100%";
toggleContainer.classList.add("zindex-over-content");
toggleContainer.classList.add("quarto-sidebar-toggle");
toggleContainer.classList.add("headroom-target"); // Marks this to be managed by headeroom
toggleContainer.id = placeholderDescriptor.id;
toggleContainer.style.position = "fixed";
const toggleIcon = window.document.createElement("i");
toggleIcon.classList.add("quarto-sidebar-toggle-icon");
toggleIcon.classList.add("bi");
toggleIcon.classList.add("bi-caret-down-fill");
const toggleTitle = window.document.createElement("div");
const titleEl = window.document.body.querySelector(
placeholderDescriptor.titleSelector
);
if (titleEl) {
toggleTitle.append(titleEl.innerText, toggleIcon);
}
toggleTitle.classList.add("zindex-over-content");
toggleTitle.classList.add("quarto-sidebar-toggle-title");
toggleContainer.append(toggleTitle);
const toggleContents = window.document.createElement("div");
toggleContents.classList = el.classList;
toggleContents.classList.add("zindex-over-content");
toggleContents.classList.add("quarto-sidebar-toggle-contents");
for (const child of el.children) {
if (child.id === "toc-title") {
continue;
}
const clone = child.cloneNode(true);
clone.style.opacity = 1;
clone.style.display = null;
toggleContents.append(clone);
}
toggleContents.style.height = "0px";
toggleContainer.append(toggleContents);
el.parentElement.prepend(toggleContainer);
// Process clicks
let tocShowing = false;
// Allow the caller to control whether this is dismissed
// when it is clicked (e.g. sidebar navigation supports
// opening and closing the nav tree, so don't dismiss on click)
const clickEl = placeholderDescriptor.dismissOnClick
? toggleContainer
: toggleTitle;
const closeToggle = () => {
if (tocShowing) {
toggleContainer.classList.remove("expanded");
toggleContents.style.height = "0px";
tocShowing = false;
}
};
const positionToggle = () => {
// position the element (top left of parent, same width as parent)
const elRect = el.getBoundingClientRect();
toggleContainer.style.left = `${elRect.left}px`;
toggleContainer.style.top = `${elRect.top}px`;
toggleContainer.style.width = `${elRect.width}px`;
};
// Get rid of any expanded toggle if the user scrolls
window.document.addEventListener(
"scroll",
throttle(() => {
closeToggle();
}, 50)
);
// Handle positioning of the toggle
window.addEventListener(
"resize",
throttle(() => {
positionToggle();
}, 50)
);
positionToggle();
// Process the click
clickEl.onclick = () => {
if (!tocShowing) {
toggleContainer.classList.add("expanded");
toggleContents.style.height = null;
tocShowing = true;
} else {
closeToggle();
}
};
};
// Converts a sidebar from a menu back to a sidebar
const convertToSidebar = () => {
for (const child of el.children) {
child.style.opacity = 1;
child.style.overflow = null;
}
const placeholderEl = window.document.getElementById(
placeholderDescriptor.id
);
if (placeholderEl) {
placeholderEl.remove();
}
el.classList.remove("rollup");
};
if (isReaderMode()) {
convertToMenu();
isVisible = false;
} else {
if (!isVisible) {
// If the element is current not visible reveal if there are
// no conflicts with overlay regions
if (!inHiddenRegion(elTop, elBottom, hiddenRegions)) {
convertToSidebar();
isVisible = true;
}
} else {
// If the element is visible, hide it if it conflicts with overlay regions
// and insert a placeholder toggle (or if we're in reader mode)
if (inHiddenRegion(elTop, elBottom, hiddenRegions)) {
convertToMenu();
isVisible = false;
}
}
}
}
};
};
// Find any conflicting margin elements and add margins to the
// top to prevent overlap
const marginChildren = window.document.querySelectorAll(
".column-margin.column-container > * "
);
let lastBottom = 0;
for (const marginChild of marginChildren) {
const top = marginChild.getBoundingClientRect().top;
if (top < lastBottom) {
const margin = lastBottom - top;
marginChild.style.marginTop = `${margin}px`;
}
const styles = window.getComputedStyle(marginChild);
const marginTop = parseFloat(styles["marginTop"]);
lastBottom = top + marginChild.getBoundingClientRect().height + marginTop;
}
// Manage the visibility of the toc and the sidebar
const marginScrollVisibility = manageSidebarVisiblity(marginSidebarEl, {
id: "quarto-toc-toggle",
titleSelector: "#toc-title",
dismissOnClick: true,
});
const sidebarScrollVisiblity = manageSidebarVisiblity(sidebarEl, {
id: "quarto-sidebarnav-toggle",
titleSelector: ".title",
dismissOnClick: false,
});
let tocLeftScrollVisibility;
if (leftTocEl) {
tocLeftScrollVisibility = manageSidebarVisiblity(leftTocEl, {
id: "quarto-lefttoc-toggle",
titleSelector: "#toc-title",
dismissOnClick: true,
});
}
// Find the first element that uses formatting in special columns
const conflictingEls = window.document.body.querySelectorAll(
'[class^="column-"], [class*=" column-"], aside, [class*="margin-caption"], [class*=" margin-caption"], [class*="margin-ref"], [class*=" margin-ref"]'
);
// Filter all the possibly conflicting elements into ones
// the do conflict on the left or ride side
const arrConflictingEls = Array.from(conflictingEls);
const leftSideConflictEls = arrConflictingEls.filter((el) => {
if (el.tagName === "ASIDE") {
return false;
}
return Array.from(el.classList).find((className) => {
return (
className !== "column-body" &&
className.startsWith("column-") &&
!className.endsWith("right") &&
!className.endsWith("container") &&
className !== "column-margin"
);
});
});
const rightSideConflictEls = arrConflictingEls.filter((el) => {
if (el.tagName === "ASIDE") {
return true;
}
const hasMarginCaption = Array.from(el.classList).find((className) => {
return className == "margin-caption";
});
if (hasMarginCaption) {
return true;
}
return Array.from(el.classList).find((className) => {
return (
className !== "column-body" &&
!className.endsWith("container") &&
className.startsWith("column-") &&
!className.endsWith("left")
);
});
});
const kOverlapPaddingSize = 10;
function toRegions(els) {
return els.map((el) => {
const top =
el.getBoundingClientRect().top +
document.documentElement.scrollTop -
kOverlapPaddingSize;
return {
top,
bottom: top + el.scrollHeight + 2 * kOverlapPaddingSize,
};
});
}
const hideOverlappedSidebars = () => {
marginScrollVisibility(toRegions(rightSideConflictEls));
sidebarScrollVisiblity(toRegions(leftSideConflictEls));
if (tocLeftScrollVisibility) {
tocLeftScrollVisibility(toRegions(leftSideConflictEls));
}
};
window.quartoToggleReader = () => {
// Applies a slow class (or removes it)
// to update the transition speed
const slowTransition = (slow) => {
const manageTransition = (id, slow) => {
const el = document.getElementById(id);
if (el) {
if (slow) {
el.classList.add("slow");
} else {
el.classList.remove("slow");
}
}
};
manageTransition("TOC", slow);
manageTransition("quarto-sidebar", slow);
};
const readerMode = !isReaderMode();
setReaderModeValue(readerMode);
// If we're entering reader mode, slow the transition
if (readerMode) {
slowTransition(readerMode);
}
highlightReaderToggle(readerMode);
hideOverlappedSidebars();
// If we're exiting reader mode, restore the non-slow transition
if (!readerMode) {
slowTransition(!readerMode);
}
};
const highlightReaderToggle = (readerMode) => {
const els = document.querySelectorAll(".quarto-reader-toggle");
if (els) {
els.forEach((el) => {
if (readerMode) {
el.classList.add("reader");
} else {
el.classList.remove("reader");
}
});
}
};
const setReaderModeValue = (val) => {
if (window.location.protocol !== "file:") {
window.localStorage.setItem("quarto-reader-mode", val);
} else {
localReaderMode = val;
}
};
const isReaderMode = () => {
if (window.location.protocol !== "file:") {
return window.localStorage.getItem("quarto-reader-mode") === "true";
} else {
return localReaderMode;
}
};
let localReaderMode = null;
// Walk the TOC and collapse/expand nodes
// Nodes are expanded if:
// - they are top level
// - they have children that are 'active' links
// - they are directly below an link that is 'active'
const walk = (el, depth) => {
// Tick depth when we enter a UL
if (el.tagName === "UL") {
depth = depth + 1;
}
// It this is active link
let isActiveNode = false;
if (el.tagName === "A" && el.classList.contains("active")) {
isActiveNode = true;
}
// See if there is an active child to this element
let hasActiveChild = false;
for (child of el.children) {
hasActiveChild = walk(child, depth) || hasActiveChild;
}
// Process the collapse state if this is an UL
if (el.tagName === "UL") {
if (depth === 1 || hasActiveChild || prevSiblingIsActiveLink(el)) {
el.classList.remove("collapse");
} else {
el.classList.add("collapse");
}
// untick depth when we leave a UL
depth = depth - 1;
}
return hasActiveChild || isActiveNode;
};
// walk the TOC and expand / collapse any items that should be shown
if (tocEl) {
walk(tocEl, 0);
updateActiveLink();
}
// Throttle the scroll event and walk peridiocally
window.document.addEventListener(
"scroll",
throttle(() => {
if (tocEl) {
updateActiveLink();
walk(tocEl, 0);
}
if (!isReaderMode()) {
hideOverlappedSidebars();
}
}, 5)
);
window.addEventListener(
"resize",
throttle(() => {
if (!isReaderMode()) {
hideOverlappedSidebars();
}
}, 10)
);
hideOverlappedSidebars();
highlightReaderToggle(isReaderMode());
});
// grouped tabsets
window.addEventListener("pageshow", (_event) => {
function getTabSettings() {
const data = localStorage.getItem("quarto-persistent-tabsets-data");
if (!data) {
localStorage.setItem("quarto-persistent-tabsets-data", "{}");
return {};
}
if (data) {
return JSON.parse(data);
}
}
function setTabSettings(data) {
localStorage.setItem(
"quarto-persistent-tabsets-data",
JSON.stringify(data)
);
}
function setTabState(groupName, groupValue) {
const data = getTabSettings();
data[groupName] = groupValue;
setTabSettings(data);
}
function toggleTab(tab, active) {
const tabPanelId = tab.getAttribute("aria-controls");
const tabPanel = document.getElementById(tabPanelId);
if (active) {
tab.classList.add("active");
tabPanel.classList.add("active");
} else {
tab.classList.remove("active");
tabPanel.classList.remove("active");
}
}
function toggleAll(selectedGroup, selectorsToSync) {
for (const [thisGroup, tabs] of Object.entries(selectorsToSync)) {
const active = selectedGroup === thisGroup;
for (const tab of tabs) {
toggleTab(tab, active);
}
}
}
function findSelectorsToSyncByLanguage() {
const result = {};
const tabs = Array.from(
document.querySelectorAll(`div[data-group] a[id^='tabset-']`)
);
for (const item of tabs) {
const div = item.parentElement.parentElement.parentElement;
const group = div.getAttribute("data-group");
if (!result[group]) {
result[group] = {};
}
const selectorsToSync = result[group];
const value = item.innerHTML;
if (!selectorsToSync[value]) {
selectorsToSync[value] = [];
}
selectorsToSync[value].push(item);
}
return result;
}
function setupSelectorSync() {
const selectorsToSync = findSelectorsToSyncByLanguage();
Object.entries(selectorsToSync).forEach(([group, tabSetsByValue]) => {
Object.entries(tabSetsByValue).forEach(([value, items]) => {
items.forEach((item) => {
item.addEventListener("click", (_event) => {
setTabState(group, value);
toggleAll(value, selectorsToSync[group]);
});
});
});
});
return selectorsToSync;
}
const selectorsToSync = setupSelectorSync();
for (const [group, selectedName] of Object.entries(getTabSettings())) {
const selectors = selectorsToSync[group];
// it's possible that stale state gives us empty selections, so we explicitly check here.
if (selectors) {
toggleAll(selectedName, selectors);
}
}
});
function throttle(func, wait) {
let waiting = false;
return function () {
if (!waiting) {
func.apply(this, arguments);
waiting = true;
setTimeout(function () {
waiting = false;
}, wait);
}
};
}

View File

@ -0,0 +1 @@
.tippy-box[data-animation=fade][data-state=hidden]{opacity:0}[data-tippy-root]{max-width:calc(100vw - 10px)}.tippy-box{position:relative;background-color:#333;color:#fff;border-radius:4px;font-size:14px;line-height:1.4;white-space:normal;outline:0;transition-property:transform,visibility,opacity}.tippy-box[data-placement^=top]>.tippy-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-arrow:before{bottom:-7px;left:0;border-width:8px 8px 0;border-top-color:initial;transform-origin:center top}.tippy-box[data-placement^=bottom]>.tippy-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:before{top:-7px;left:0;border-width:0 8px 8px;border-bottom-color:initial;transform-origin:center bottom}.tippy-box[data-placement^=left]>.tippy-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-arrow:before{border-width:8px 0 8px 8px;border-left-color:initial;right:-7px;transform-origin:center left}.tippy-box[data-placement^=right]>.tippy-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-arrow:before{left:-7px;border-width:8px 8px 8px 0;border-right-color:initial;transform-origin:center right}.tippy-box[data-inertia][data-state=visible]{transition-timing-function:cubic-bezier(.54,1.5,.38,1.11)}.tippy-arrow{width:16px;height:16px;color:#333}.tippy-arrow:before{content:"";position:absolute;border-color:transparent;border-style:solid}.tippy-content{position:relative;padding:5px 9px;z-index:1}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,6 @@
@import url('https://fonts.googleapis.com/css?family=Lora&display=swap');
@import url('https://fonts.googleapis.com/css?family=Source+Code+Pro&display=swap');
body {
font-family: 'Lora';
}