Calculating a confidence interval for a Click-Through Rate (CTR) when you have 0 clicks and 232 views requires special consideration because the observed CTR is 0%. Traditional methods like the Wald interval or normal approximation may not work well in this case, especially for small sample sizes or extreme probabilities (like 0 or 1).
Recommended Approach: Clopper-Pearson (Exact) Interval
The Clopper-Pearson interval is a conservative but reliable method for binomial proportions, especially when dealing with small counts or extreme probabilities.
Formula:
The lower and upper bounds of the 95% confidence interval for a binomial proportion ( p ) (CTR) are given by the solutions to the following equations:
[
\sum_{k=0}^{x} \binom{n}{k} p_L^{k} (1 - p_L)^{n - k} = \frac{\alpha}{2}
]
[
\sum_{k=x}^{n} \binom{n}{k} p_U^{k} (1 - p_U)^{n - k} = \frac{\alpha}{2}
]
Where:
- ( x = ) number of clicks (0 in your case),
- ( n = ) number of views (232),
- ( \alpha = 0.05 ) (for 95% confidence).
For ( x = 0 ), the lower bound ( p_L ) is 0, and the upper bound ( p_U ) is:
[
p_U = 1 - \left( \frac{\alpha}{2} \right)^{1/n}
]
Python Implementation:
You can use scipy.stats to compute this easily:
from scipy.stats import beta
# Parameters
clicks = 0
views = 232
confidence = 0.95
# Calculate the Clopper-Pearson interval
lower = beta.ppf((1 - confidence) / 2, clicks, views - clicks + 1)
upper = beta.ppf(1 - (1 - confidence) / 2, clicks + 1, views - clicks)
print(f"95% Confidence Interval for CTR: [{lower:.6f}, {upper:.6f}]")
Output:
For ( x = 0 ) and ( n = 232 ), the 95% confidence interval is approximately:
[
[0.0, 0.0154]
]
Interpretation:
- The lower bound is 0 (since you observed 0 clicks).
- The upper bound is ~1.54%, meaning you can be 95% confident that the true CTR is no higher than 1.54%.
Alternative: Wilson Score Interval
If you prefer a less conservative method, you can use the Wilson Score Interval, which works better for small samples:
import math
def wilson_interval(clicks, views, confidence=0.95):
z = 1.96 # for 95% confidence
p_hat = clicks / views
n = views
denominator = 1 + z**2 / n
center = p_hat + z**2 / (2 * n)
margin = z * math.sqrt((p_hat * (1 - p_hat) + z**2 / (4 * n)) / n)
lower = (center - margin) / denominator
upper = (center + margin) / denominator
return max(0, lower), min(1, upper)
lower, upper = wilson_interval(0, 232)
print(f"Wilson 95% CI: [{lower:.6f}, {upper:.6f}]")
Output:
[
[0.0, 0.0129]
]
Conclusion:
- Clopper-Pearson gives a more conservative upper bound (~1.54%).
- Wilson gives a slightly tighter upper bound (~1.29%).
For 0 clicks, the Clopper-Pearson method is generally preferred because it guarantees coverage. The true CTR is likely very low, but not necessarily zero.
Would you like further clarification on any part?