Compute P(X = 2) for X ~ Bin(12, 0.15) with math.comb, and the mean, variance and SD from np and np(1 − p).
Compute P(X = 2) for X ~ Bin(12, 0.15) with math.comb, and the mean, variance and SD from np and np(1 − p).
Answer
import math n, p = 12, 0.15 x = 2 prob = math.comb(n, x) * p ** x * (1 - p) ** (n - x) mean = n * p var = n * p * (1 - p) print(f"P(X=2)={prob:.4f} mean={mean:.2f} var={var:.4f} sd={math.sqrt(var):.4f}")
IBS1 §4.2 (binomial), IS1 §4.3 (tilde notation, non-binomial counter-example), CC BY 4.0 — shape only; original dataset