Skip to content

Commit d659e89

Browse files
committed
Add explanation of survival function (sf) method
- Explain that sf() computes P(X > k) = 1 - P(X <= k) - Note benefits: better numerical accuracy and clearer intent - Added after first usage in Binomial distribution section
1 parent a09b59b commit d659e89

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)