Skip to content

Commit 3bc55a5

Browse files
authored
Merge pull request #92 from snowch/claude/fix-bernoulli-rendering-mjFhe
Add explanation of survival function (sf) method
2 parents cfbc292 + d659e89 commit 3bc55a5

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

chapter_07.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ print(f"P(X > {k_or_fewer} successes out of {n_calls}): {1 - binomial_rv.cdf(k_o
721721
print(f"P(X > {k_or_fewer} successes out of {n_calls}) (using sf): {binomial_rv.sf(k_or_fewer):.4f}")
722722
```
723723

724+
**Note on Survival Function (`sf`):** The `sf()` method computes the **survival function**, which is P(X > k) = 1 - P(X ≤ k). While mathematically equivalent to `1 - cdf(k)`, using `sf(k)` directly is preferable because it provides better numerical accuracy when dealing with very small or very large probabilities, and makes the code's intent clearer.
725+
724726
```{code-cell} ipython3
725727
# Mean and Variance
726728
print(f"Mean (Expected number of successes): {binomial_rv.mean():.2f}")

0 commit comments

Comments
 (0)