Skip to content

Commit a09b59b

Browse files
committed
Add SD shading to remaining distributions and enhance documentation
- Add mean ± 1 SD shaded region to Bernoulli PMF - Add mean ± 1 SD shaded region to Hypergeometric PMF - Add visualization aids bullet to "Reading the PMF" section explaining mean line and SD region - Add visualization aids bullet to "Reading the CDF" section explaining mean line - Ensures consistent visualization across all discrete distributions
1 parent ce7ea9e commit a09b59b

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

chapter_07.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ plt.bar(k_values_viz, pmf_values_viz, tick_label=["Failure (0)", "Success (1)"],
147147
# Add mean line
148148
plt.axvline(mean_viz, color='red', linestyle='--', linewidth=2, label=f'Mean = {mean_viz:.2f}')
149149
150+
# Add mean ± 1 std region
151+
plt.axvspan(mean_viz - std_viz, mean_viz + std_viz, alpha=0.2, color='orange',
152+
label=f'Mean ± 1 SD = [{mean_viz - std_viz:.2f}, {mean_viz + std_viz:.2f}]')
153+
150154
plt.title(f"Bernoulli PMF (p={p_viz})")
151155
plt.xlabel("Outcome")
152156
plt.ylabel("Probability")
@@ -159,7 +163,7 @@ plt.show()
159163

160164
![Bernoulli PMF](ch07_bernoulli_pmf_generic.svg)
161165

162-
The PMF shows two bars: P(X=0) = 0.7 for a negative test and P(X=1) = 0.3 for a positive test. The red dashed line marks the mean ($p = 0.3$).
166+
The PMF shows two bars: P(X=0) = 0.7 for a negative test and P(X=1) = 0.3 for a positive test. The red dashed line marks the mean ($p = 0.3$), and the orange shaded region shows mean ± 1 standard deviation.
163167

164168
```{code-cell} ipython3
165169
:tags: [remove-input, remove-output]
@@ -199,6 +203,7 @@ Note: Here, P(X ≤ 0) = P(X = 0) = 0.7 because X can't take negative values; in
199203
- **How to read:** Look at the bar height to find P(X = k) for any specific value k
200204
- **Practical use:** Answer questions like "What's the probability of success?" or "What's the probability of exactly 1 positive test?"
201205
- **Key property:** All bar heights must sum to 1.0 (total probability)
206+
- **Visualization aids:** The red dashed line marks the mean (expected value), and the orange shaded region shows mean ± 1 standard deviation (where ~68% of values typically fall)
202207

203208
**Reading the CDF**
204209

@@ -211,6 +216,7 @@ Note: Here, P(X ≤ 0) = P(X = 0) = 0.7 because X can't take negative values; in
211216
- Find P(X > k) by calculating 1 - P(X ≤ k)
212217
- Find P(a < X ≤ b) by calculating P(X ≤ b) - P(X ≤ a)
213218
- **Key property:** The CDF is right-continuous, always increases (or stays flat), and approaches 1.0
219+
- **Visualization aids:** The red dashed line marks the mean (expected value) as a reference point
214220

215221
**Note on CDF visualization:** The charts use `where='post'` in the step plot to create proper right-continuous step functions. This means the CDF jumps up at each value and includes that value in the cumulative probability.
216222

@@ -1768,6 +1774,10 @@ plt.bar(k_values_viz, pmf_values_viz, color='skyblue', edgecolor='black', alpha=
17681774
# Add mean line
17691775
plt.axvline(mean_viz, color='red', linestyle='--', linewidth=2, label=f'Mean = {mean_viz:.2f}')
17701776
1777+
# Add mean ± 1 std region
1778+
plt.axvspan(mean_viz - std_viz, mean_viz + std_viz, alpha=0.2, color='orange',
1779+
label=f'Mean ± 1 SD = [{mean_viz - std_viz:.2f}, {mean_viz + std_viz:.2f}]')
1780+
17711781
plt.title(f"Hypergeometric PMF (N={N_viz}, K={K_viz}, n={n_viz})")
17721782
plt.xlabel("Number of Successes in Sample (k)")
17731783
plt.ylabel("Probability P(X=k)")
@@ -1780,7 +1790,7 @@ plt.show()
17801790

17811791
![Hypergeometric PMF](ch07_hypergeometric_pmf_generic.svg)
17821792

1783-
The PMF shows most likely to get 0 Aces (about 0.66 probability), less likely to get 1 or 2. The red dashed line marks the mean.
1793+
The PMF shows most likely to get 0 Aces (about 0.66 probability), less likely to get 1 or 2. The red dashed line marks the mean, and the orange shaded region shows mean ± 1 standard deviation.
17841794

17851795
```{code-cell} ipython3
17861796
:tags: [remove-input, remove-output]

0 commit comments

Comments
 (0)