By Rohan Deshpande — Stumped Analytics, Nagpur
A batter has a 50% boundary rate. Another has 30%. Your dashboard puts the first player on top and colours the card green.
Then somebody asks: off how many balls?
Six boundaries in twelve eligible deliveries versus seventy-two in two hundred and forty. Both percentages are correct. Treating them as equally supported evidence is not.
For developers building cricket products, the denominator belongs beside the headline number—not in a tooltip.
Form is not matchup; exposure is not independence
Form describes performance in a declared recent window. It does not, by itself, establish a change in ability or predict the next innings.
Matchup narrows the question: this batter against this bowler, bowling type or phase. Every filter changes the comparison and the evidence available.
Sample size reports observed exposure behind that particular statistic. It does not automatically report independent observations.
Recompute boundaries, eligible balls, distinct innings and distinct matches after matchup filtering. Never attach a season-wide denominator to a head-to-head percentage calculated from a tiny subset.
A matchup association is not an isolated bowler effect: pitch, phase, role and match situation can change together. More slicing also creates more opportunities to select a noisy extreme.
Define the event before counting it
Use one deliberately narrow signal:
legal-delivery boundary rate = actual off-bat boundary deliveries / eligible legal deliveries faced Count actual fours and sixes off the bat. Exclude wides and no-balls from both counts, including boundaries hit from no-balls. Legal deliveries producing byes or leg-byes remain denominator observations, not successes. This is a custom metric, not an official balls-faced definition.
All-run fours and overthrows must not become boundaries merely because a runs field contains four. The saved Cricsheet JSON documentation describes runs.non_boundary and delivery extras. Pin the provider's format version, test the fields, deduplicate deliveries and preserve correction history.
Keep the first comparison within one declared T20 competition and cohort. Boundaries omit strike rotation, dismissal risk and match value: this is not an overall batting rating.
For illustration, use an unweighted 90-day window with a declared cutoff and boundary-day policy. Ninety days is not a validated cricket default. Cricsheet's info.dates supplies match dates, not per-delivery timestamps. Do not invent timestamp precision: use completed matches and declare how cutoff-day and multi-day matches are handled.
No magic stabilisation count
“Only show players after 30 balls” may be a product policy. It is not proof that form has stabilised. The saved discussion of n = 30 establishes no universal adequacy threshold, let alone a cricket-specific one.
Nor are 240 balls necessarily 240 independent trials. Deliveries share innings, surfaces, opponents and game states. bschneidr's effective-sample-size explanation makes effective sample size estimator- and design-dependent. A row count, sum of recency weights or number of bootstrap replications is not a substitute.
Show observed balls and distinct innings and matches. Keep any effective sample size separately labelled and justified.
Show the shrinkage calculation
For a deliberately simple model, assume binary outcomes are conditionally independent with one common boundary probability p inside the window:
k | p, n ~ Binomial(n, p) p ~ Beta(m * p0, m * (1 - p0)) p | k, n ~ Beta(m * p0 + k, m * (1 - p0) + n - k) posterior_mean = (k + m * p0) / (n + m) = [n / (n + m)] * (k / n) + [m / (n + m)] * p0 # n > 0 Multiplying the beta prior density by the binomial likelihood gives this posterior. This is a binary-event model, not a model for runs per ball. The SciPy beta documentation supplies the implementation reference; it does not validate the cricket assumptions.
For the toy calculation, set p0 = 0.20 and m = 40, giving a Beta(8, 32) prior. Here p0 is the prior mean and m is its concentration. In this posterior-mean formula, m acts like prior pseudo-deliveries. It is not forty observed balls, a model-free effective sample size, or a validated cricket parameter.
Show n / (n + m) as the data's weight in this particular mean calculation, not as confidence that a player rating is correct.
Model limitation: Deliveries within an innings can be dependent, and scoring probabilities change with opposition, pitch, phase, and match state. The intervals below are conditional on this simplified model and fixed prior. Their real-cricket calibration has not been established.
Invented data: a point-estimate reversal
In this fictional aggregate dataset, each innings belongs to a different fictional match. No real players or matches are represented.
| Fictional batter | Innings / matches | Boundaries k | Legal balls n | Raw rate | Shrunk mean | 95% model-conditional credible interval | Data weight |
|---|---|---|---|---|---|---|---|
| A | 1 / 1 | 6 | 12 | 50.0% | 26.9% | 15.9%–39.6% | 23.1% |
| B | 6 / 6 | 30 | 120 | 25.0% | 23.8% | 17.5%–30.6% | 75.0% |
| C | 12 / 12 | 72 | 240 | 30.0% | 28.6% | 23.4%–34.0% | 85.7% |
A leads on the raw rate; C leads on the shrunk point estimate. That reversal follows from the disclosed prior and invented counts—not evidence that C is truly the better batter. A's estimate is especially prior-sensitive.
Implement the summary in Python
Install SciPy:
python -m pip install scipy This function starts after eligibility filtering, deduplication, window selection, and aggregation. It is not a complete match-data ingestion pipeline.
from math import isfinite from scipy.stats import beta def summarize(k: int, n: int, *, p0: float, m: float) -> dict: if type(k) is not int or type(n) is not int or not 0 <= k <= n: raise ValueError("Require integer counts with 0 <= k <= n") if not (isfinite(p0) and 0 < p0 < 1 and isfinite(m) and m > 0): raise ValueError("Require finite 0 < p0 < 1 and m > 0") if n == 0: return dict(k=k, n=n, raw=None, estimate=None, interval95=None, data_weight=0.0, status="no_data") a, b = m * p0 + k, m * (1 - p0) + n - k lo, hi = beta.ppf([0.025, 0.975], a, b) return dict(k=k, n=n, raw=k / n, estimate=a / (a + b), interval95=(float(lo), float(hi)), data_weight=n / (n + m), status="model_conditional") # Invented counts and settings, not measured cricket results. for name, k, n in [("A", 6, 12), ("B", 30, 120), ("C", 72, 240)]: print(name, summarize(k, n, p0=0.20, m=40)) The interval uses the beta posterior's 2.5th and 97.5th percentiles: an equal-tailed credible interval, not a frequentist confidence interval. With no observations, the UI reports no_data rather than displaying a prior-only number as player form. Impossible counts are errors, not values to silently clamp.
Ship the evidence, not just the rating
Show the raw rate, adjusted estimate, interval type, observed balls, innings, matches, cutoff and prior together. Missing coverage is not zero. Minimum-count or interval-width display policies need a declared purpose; they do not certify that form has stabilised.
A credible interval for boundary probability is not a prediction interval for next-innings runs. The saved posterior-predictive discussion explains the parameter-versus-future-outcome distinction. Future opportunities and conditions need modelling too.
Before forecasting claims, select windows, priors and context adjustments on chronological training/validation data, then freeze them for a later untouched test. Keep innings and matches together instead of randomly splitting their deliveries across train and test. Prevent post-cutoff information and later corrections from leaking into historical features. Avoid counting the same observations in both prior and update.
Do not independently bootstrap balls and declare dependence fixed. The accessible abstract of Field and Welsh, Bootstrapping clustered data, highlights model-dependent behaviour. Choosing innings, matches, time blocks or a hierarchical model requires a defensible target and dependence structure. Very few clusters limit what resampling can establish.
The improvement is not another decimal place. It is making the claim auditable:
Which performance? Against whom? Across how much evidence?
If the card cannot answer all three, it is displaying a result—not establishing form.