Skip to content

Commit

Permalink
deploy: 676c191
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderthclark committed Feb 28, 2024
1 parent 83de70a commit 5aa9493
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 22 deletions.
78 changes: 76 additions & 2 deletions _sources/probability.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ If we follow the random current. Each island is equally likely. Two of the five

Better than listing the ways and then counting is applying (and ideally understanding) a formula.

Take the example of coin flipping. How often will three coin flips come up with just one heads? For a fair coin, this will happen with probability $\frac{3}{8}$. Why? There are eight outcomes of equal chance and three of those outcomes include just one heads. Before, we arrived at knowing there were three ways to get a sequence of one heads and two tails by simply listing the ways. We can instead use the **binomial coefficient**, written $\binom{n}{k}$.
Take the example of coin flipping. How often will three coin flips come up with just one heads? For a fair coin, this will happen with probability $\frac{3}{8}$. Why? There are eight outcomes of equal chance and three of those outcomes include just one heads. Before, we arrived at knowing there were three ways to get a sequence of one heads and two tails by simply listing the ways. We can instead use the **binomial coefficient**, sometimes written $\binom{n}{k}$.

The binomial coefficient says how many ways you can choose $k$ elements from $n$ choices if the order doesn't matter.

Expand All @@ -245,6 +245,71 @@ name: pascaltri
Pascal's Triangle
```

### Binomial Coefficient Calculator

For large enough values of $n$ and $k$, don't try to be a hero. Just use a calculator.

<div style="text-align: center;">
<label for="nValue">n: </label>
<input type="number" id="nValue" name="nValue" value="4" min="0">
<label for="kValue">k: </label>
<input type="number" id="kValue" name="kValue" value="2" min="0">
<button onclick="calculateBinomial()">Calculate</button>
</div>
<div id="result" style="text-align: center;"></div>

<script>
function calculateBinomial() {
var n = document.getElementById("nValue").value;
var k = document.getElementById("kValue").value;
var result = binomialCoefficient(n, k);
document.getElementById("result").innerHTML = "Result = " + result; // Removed "C(n, k) =" notation
}

function factorial(num) {
if (num < 0)
return -1;
else if (num == 0)
return 1;
else {
return (num * factorial(num - 1));
}
}

function binomialCoefficient(n, k) {
return factorial(n) / (factorial(k) * factorial(n - k));
}
</script>


### Binomial Formula

The binomial coefficient is just a preliminary step toward the binomial formula. The **binomial formula** gives the probability that you will flip exactly $k$ heads in $n$ independent flips of a coin with a probability $p$ of a single flip being heads ($p=0.5$ for a fair coin). The formula is

$$ \frac{n!}{k!(n-k)!} p^k (1-p)^{n-k}.$$

Think of $p^k (1-p)^{n-k}$ as the probability of a sequence of $k$ heads followed by $n-k$ tails. The binomial coefficient in front then adjusts that probability to allow for all of the other ways to get $k$ heads–$n-k$ tails followed by $k$ heads for example. This only works for coin flips or similar processes where the individual trials are independent and the probability of a heads or some substitutable event of interest is the same from one trial to the next. These trial outcomes are said to be *independent and identically distributed*, or *iid*.

**Example**
A trick coin comes up heads with probability $p = \frac{2}{3}$. Out of four flips, what is the probability of two heads?

```{dropdown} Two heads
$$ \binom{4}{2} p^2 (1-p)^2 = 6 \cdot \frac{4}{9} \cdot \frac{1}{9} = \frac{24}{81} = \frac{8}{27}$$
```

What is the probability of three or more heads?

```{dropdown} Three or four heads
Three and four heads are mutually exclusive events, so we can sum probabilities,
$$ 4 \times p^3 (1-p)^1 + 1 \times p^4$$
$$ 4\cdot \frac{8}{27}\cdot\frac{1}{3} + \frac{16}{81} = \frac{48}{81} = \frac{16}{27}.$$
```


## Exercises
Expand Down Expand Up @@ -295,7 +360,6 @@ Let $A$ and $B$ be independent. Which of these sums is equal to one? What if the
```



```{exercise-start}
:label: linda
```
Expand All @@ -306,3 +370,13 @@ Let $A$ and $B$ be independent. Which of these sums is equal to one? What if the

```{exercise-end}
```

```{exercise-start}
:label: bday
```
(Use a calculator) Ignore leap day and assume that all birthdays are equally likely and independent. What is the probability that, of 365 people, nobody is born on June 1st?

What is the probability that, of 40 people, no two people share the same birthday?
```{exercise-end}
```

12 changes: 6 additions & 6 deletions correlation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions normal.html

Large diffs are not rendered by default.

Binary file modified objects.inv
Binary file not shown.
91 changes: 87 additions & 4 deletions probability.html
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ <h2> Contents </h2>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#independence">Independence</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#addition-rule-a-or-b">Addition Rule (<span class="math notranslate nohighlight">\(A\)</span> or <span class="math notranslate nohighlight">\(B\)</span>)</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#listing-the-ways">Listing the Ways</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#binomial-formula">Binomial Formula</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#binomial-formula">Binomial Formula</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#binomial-coefficient-calculator">Binomial Coefficient Calculator</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#id5">Binomial Formula</a></li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#exercises">Exercises</a></li>
</ul>
</nav>
Expand Down Expand Up @@ -622,7 +626,7 @@ <h2>Listing the Ways<a class="headerlink" href="#listing-the-ways" title="Permal
<section id="binomial-formula">
<h2>Binomial Formula<a class="headerlink" href="#binomial-formula" title="Permalink to this heading">#</a></h2>
<p>Better than listing the ways and then counting is applying (and ideally understanding) a formula.</p>
<p>Take the example of coin flipping. How often will three coin flips come up with just one heads? For a fair coin, this will happen with probability <span class="math notranslate nohighlight">\(\frac{3}{8}\)</span>. Why? There are eight outcomes of equal chance and three of those outcomes include just one heads. Before, we arrived at knowing there were three ways to get a sequence of one heads and two tails by simply listing the ways. We can instead use the <strong>binomial coefficient</strong>, written <span class="math notranslate nohighlight">\(\binom{n}{k}\)</span>.</p>
<p>Take the example of coin flipping. How often will three coin flips come up with just one heads? For a fair coin, this will happen with probability <span class="math notranslate nohighlight">\(\frac{3}{8}\)</span>. Why? There are eight outcomes of equal chance and three of those outcomes include just one heads. Before, we arrived at knowing there were three ways to get a sequence of one heads and two tails by simply listing the ways. We can instead use the <strong>binomial coefficient</strong>, sometimes written <span class="math notranslate nohighlight">\(\binom{n}{k}\)</span>.</p>
<p>The binomial coefficient says how many ways you can choose <span class="math notranslate nohighlight">\(k\)</span> elements from <span class="math notranslate nohighlight">\(n\)</span> choices if the order doesn’t matter.</p>
<ul class="simple">
<li><p>How many ways can you get one heads from three coin flips? <span class="math notranslate nohighlight">\(n=3, k=1\)</span>, <span class="math notranslate nohighlight">\(\binom{3}{1}=3\)</span>.</p></li>
Expand All @@ -639,6 +643,73 @@ <h2>Binomial Formula<a class="headerlink" href="#binomial-formula" title="Permal
<p><span class="caption-number">Fig. 39 </span><span class="caption-text">Pascal’s Triangle</span><a class="headerlink" href="#pascaltri" title="Permalink to this image">#</a></p>
</figcaption>
</figure>
<section id="binomial-coefficient-calculator">
<h3>Binomial Coefficient Calculator<a class="headerlink" href="#binomial-coefficient-calculator" title="Permalink to this heading">#</a></h3>
<p>For large enough values of <span class="math notranslate nohighlight">\(n\)</span> and <span class="math notranslate nohighlight">\(k\)</span>, don’t try to be a hero. Just use a calculator.</p>
<div style="text-align: center;">
<label for="nValue">n: </label>
<input type="number" id="nValue" name="nValue" value="4" min="0">
<label for="kValue">k: </label>
<input type="number" id="kValue" name="kValue" value="2" min="0">
<button onclick="calculateBinomial()">Calculate</button>
</div>
<div id="result" style="text-align: center;"></div>
<script>
function calculateBinomial() {
var n = document.getElementById("nValue").value;
var k = document.getElementById("kValue").value;
var result = binomialCoefficient(n, k);
document.getElementById("result").innerHTML = "Result = " + result; // Removed "C(n, k) =" notation
}

function factorial(num) {
if (num < 0)
return -1;
else if (num == 0)
return 1;
else {
return (num * factorial(num - 1));
}
}

function binomialCoefficient(n, k) {
return factorial(n) / (factorial(k) * factorial(n - k));
}
</script>
</section>
<section id="id5">
<h3>Binomial Formula<a class="headerlink" href="#id5" title="Permalink to this heading">#</a></h3>
<p>The binomial coefficient is just a preliminary step toward the binomial formula. The <strong>binomial formula</strong> gives the probability that you will flip exactly <span class="math notranslate nohighlight">\(k\)</span> heads in <span class="math notranslate nohighlight">\(n\)</span> independent flips of a coin with a probability <span class="math notranslate nohighlight">\(p\)</span> of a single flip being heads (<span class="math notranslate nohighlight">\(p=0.5\)</span> for a fair coin). The formula is</p>
<div class="math notranslate nohighlight">
\[ \frac{n!}{k!(n-k)!} p^k (1-p)^{n-k}.\]</div>
<p>Think of <span class="math notranslate nohighlight">\(p^k (1-p)^{n-k}\)</span> as the probability of a sequence of <span class="math notranslate nohighlight">\(k\)</span> heads followed by <span class="math notranslate nohighlight">\(n-k\)</span> tails. The binomial coefficient in front then adjusts that probability to allow for all of the other ways to get <span class="math notranslate nohighlight">\(k\)</span> heads–<span class="math notranslate nohighlight">\(n-k\)</span> tails followed by <span class="math notranslate nohighlight">\(k\)</span> heads for example. This only works for coin flips or similar processes where the individual trials are independent and the probability of a heads or some substitutable event of interest is the same from one trial to the next. These trial outcomes are said to be <em>independent and identically distributed</em>, or <em>iid</em>.</p>
<p><strong>Example</strong>
A trick coin comes up heads with probability <span class="math notranslate nohighlight">\(p = \frac{2}{3}\)</span>. Out of four flips, what is the probability of two heads?</p>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
Two heads<div class="sd-summary-down docutils">
<svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
<div class="sd-summary-up docutils">
<svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
</summary><div class="sd-summary-content sd-card-body docutils">
<div class="math notranslate nohighlight">
\[ \binom{4}{2} p^2 (1-p)^2 = 6 \cdot \frac{4}{9} \cdot \frac{1}{9} = \frac{24}{81} = \frac{8}{27}\]</div>
</div>
</details><p>What is the probability of three or more heads?</p>
<details class="sd-sphinx-override sd-dropdown sd-card sd-mb-3">
<summary class="sd-summary-title sd-card-header">
Three or four heads<div class="sd-summary-down docutils">
<svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
<div class="sd-summary-up docutils">
<svg version="1.1" width="1.5em" height="1.5em" class="sd-octicon sd-octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
</summary><div class="sd-summary-content sd-card-body docutils">
<p class="sd-card-text">Three and four heads are mutually exclusive events, so we can sum probabilities,</p>
<div class="math notranslate nohighlight">
\[ 4 \times p^3 (1-p)^1 + 1 \times p^4\]</div>
<div class="math notranslate nohighlight">
\[ 4\cdot \frac{8}{27}\cdot\frac{1}{3} + \frac{16}{81} = \frac{48}{81} = \frac{16}{27}.\]</div>
</div>
</details></section>
</section>
<section id="exercises">
<h2>Exercises<a class="headerlink" href="#exercises" title="Permalink to this heading">#</a></h2>
Expand Down Expand Up @@ -688,13 +759,21 @@ <h2>Exercises<a class="headerlink" href="#exercises" title="Permalink to this he

<p class="admonition-title"><span class="caption-number">Exercise 29 </span></p>
<section id="exercise-content">
<p>(From <span id="id5">[<a class="reference internal" href="bibliography.html#id27" title="Amos Tversky and Daniel Kahneman. Extensional versus intuitive reasoning: the conjunction fallacy in probability judgment. Psychological review, 90(4):293, 1983.">TK83</a>]</span>) Linda is 31 years old, single, outspoken, and very bright. She majored in philosophy. As a student, she was deeply concerned with issues of discrimination and social justice, and also participated in anti-nuclear demonstrations. Which is more probable?</p>
<p>(From <span id="id6">[<a class="reference internal" href="bibliography.html#id27" title="Amos Tversky and Daniel Kahneman. Extensional versus intuitive reasoning: the conjunction fallacy in probability judgment. Psychological review, 90(4):293, 1983.">TK83</a>]</span>) Linda is 31 years old, single, outspoken, and very bright. She majored in philosophy. As a student, she was deeply concerned with issues of discrimination and social justice, and also participated in anti-nuclear demonstrations. Which is more probable?</p>
<ul class="simple">
<li><p>Linda is a bank teller.</p></li>
<li><p>Linda is a bank teller and is active in the feminist movement.</p></li>
</ul>
</section>
</div>
<div class="exercise admonition" id="bday">

<p class="admonition-title"><span class="caption-number">Exercise 30 </span></p>
<section id="exercise-content">
<p>(Use a calculator) Ignore leap day and assume that all birthdays are equally likely and independent. What is the probability that, of 365 people, nobody is born on June 1st?</p>
<p>What is the probability that, of 40 people, no two people share the same birthday?</p>
</section>
</div>
</section>
</section>

Expand Down Expand Up @@ -773,7 +852,11 @@ <h2>Exercises<a class="headerlink" href="#exercises" title="Permalink to this he
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#independence">Independence</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#addition-rule-a-or-b">Addition Rule (<span class="math notranslate nohighlight">\(A\)</span> or <span class="math notranslate nohighlight">\(B\)</span>)</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#listing-the-ways">Listing the Ways</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#binomial-formula">Binomial Formula</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#binomial-formula">Binomial Formula</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#binomial-coefficient-calculator">Binomial Coefficient Calculator</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#id5">Binomial Formula</a></li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#exercises">Exercises</a></li>
</ul>
</nav></div>
Expand Down
Loading

0 comments on commit 5aa9493

Please sign in to comment.