Statistics
The statistical paradoxes we check for, function by function
A result can be computed without a single error and still say the opposite of the truth. Simpson’s reversal, the winner’s curse, Galton’s problem, multiplicity, Jensen’s inequality and censoring: for each, a defect we found in our own code and how it was shown; where the fix is done, its formula and the measurement after it; where not, the register entry that tracks it. The review goes function by function and is not finished.
Why we audit our own code
A statistical paradox is not a textbook curiosity. It is a result computed correctly that says the opposite of what is true. It raises no error, crashes no program and passes most reviews; a library can run for years with one inside. That is why we look for them in our own code first: the functions of our library and the steps of our pipelines go through the same review, one after another.
Our rule is strict. A suspicion is not a defect. A defect is declared only when a simulation on data where the truth is known, or a test on real data, shows the bias on the function as it is. A fix is accepted only when the same simulation shows the bias gone, with a test that fails on the former code and passes on the new one, and with the former behaviour kept so that past results can be replayed exactly. Every figure in this article comes from such simulations, unless it is said to come from a real portfolio.
The chart below gathers the false findings we measured: data with no effect, no break and no relation, and the share of simulations in which a function declared one anyway, before and after its fix. The sections that follow take them one paradox at a time.
Simpson: a pooled sign the segments contradict
A constructed example first. Method 1 was tested on 1,000 small claims and 100 large ones, method 2 on 100 small and 1,000 large. Method 2 is better in both segments (85% against 80% of small claims estimated within 10% of their final cost, 45% against 40% of large ones), yet worse in total, 49% against 76%. A total is a weighted average of the segments, and here the two methods do not carry the same weights:
where is the success rate of method in segment , its number of claims in that segment and its total. Method 1 puts 91% of its weight on easy claims, method 2 puts 91% on hard ones: the total compares two mixtures of difficulty, not two methods.
Our correlation engine had the same blind spot. On three segments in which the relation is clearly negative ( = −0.83, −0.80 and −0.79), it reported a pooled correlation of +0.80 with a p-value of the order of , and its summary listed the pair as a significant relation without its sign. Nothing flagged the reversal. The covariance of the pooled rows explains it exactly; computed with divisor , it splits into a part within the segments and a part between them:
Inside each segment the first term is negative; the segment averages rise together, so the second term is positive and larger. Whether pooling is legitimate depends on the question, which the data alone cannot decide; what an engine can do is refuse to let the pooled sign pass unnoticed. Ours now raises a reversal flag on the pooled row when the significant segments that carry most of the rows point the other way:
where is the correlation tested in segment , its number of valid rows, its p-value adjusted for the false discovery rate across every pair and segment tested, a declared minimum and the level. When the significant segments weigh the same on both sides () the status is “ambiguous”; when the pooled sign is opposite but not significant, that is reported too. On 100 simulated data sets built like the one above, the reversal was flagged in every one.
An independent review of the same engine found a second form of the paradox. When the decision rested on a partial correlation, the correlation once other variables are accounted for, the text and the direction label still read the raw correlation: a pair whose partial correlation was −0.92 was described as “positive”. Every sign, label and sentence now reads the quantity whose p-value made the decision. The backtest of our trajectory model applies the same idea to the comparison of models: a reversal between the total and the segments that carry most of the amounts blocks the adoption of a model, and a test built on a constructed reversal checks that the block fires.
Galton’s problem: the unit that counts
In 1888, discussing a study by Edward Tylor that compared customs across societies, Francis Galton objected that customs borrowed from a common source are copies of one another, not independent observations. The problem comes back wherever rows share a source: the claims of one insured, the sessions of one customer, the consecutive days of one series. Counting them as independent gives standard errors that are too small, validations that flatter and effects that do not exist.
We found it in several places in our code. A causal estimate on five rows per customer, with the treatment decided per customer and no effect at all, declared an effect at 5% in 36.5% of simulations with the doubly robust estimator (AIPW) and in 28% with inverse weighting (IPTW). The binary tests of our statistical-analysis toolkit, on a trait of the insured with no effect and five rows per insured, found one in 26% of simulations. The random validation split of our pricing models drew claims and policies separately, so that the claims of a policy kept for validation could train the severity model: a defect by construction, its size still to be measured.
The fix is the same everywhere: the unit of independence, the insured, the customer or the policy, is declared and shown with every result, and folds, tests and standard errors are built on it. Folds hold whole units, and the standard error adds up the scores of each unit before squaring them:
where is the score of row , its contribution to the estimate, which is the mean of the scores; is the number of rows and the number of units. With one row per unit, and the formula is the usual one; with several, it keeps the cross-products of rows of the same unit, which the usual formula drops. With the customer as the unit (this is the formula of the doubly robust estimate; inverse weighting uses the equivalent clustered sandwich of its weighted regression), the false effects fall to 2% and 7.5%, for a target of 5%. Over 200 simulations, 7.5% has a 95% interval of about 4% to 12%: inverse weighting is much better than before, but its calibration is not yet shown to be at the target level. With the insured as the unit, the toolkit tests one row per insured and its false findings fall to 3.5%; the pricing split puts every insured entirely on one side, claims and policies together.
The unit also decides what a model counts. Our model of the type of claim, which splits the cost of claims between their possible types, counted rows instead of claims: a row holding several claims weighed as one. On simulated portfolios where that happens, the pure premium came out 3% to 7% above the truth in total, and 8% to 14% above in one region. Weighting the likelihood by claims brought the total back within 2% of the truth on four simulated portfolios. One region is still 3% to 6% too high and another 1% to 3% too low, because a row can mix claims that were paid and claims closed without payment; that gap is recorded in the register as the next fix, not hidden.
For our trajectory model, splitting the validation by claim chain rather than by insured made the error look three times smaller than it is (1.20 against 3.62, on a simulated portfolio of 60 insureds with four chains each) and selected a memory that helped in nothing. The same principle applied to episodes, all the episodes of one insured on the same side, was then measured on a real portfolio, and there it changed nothing measurable: a held-out loss of 2.50 with the former split and 2.42 with the new one, with 1.46 episodes per insured on average. We report that too. A paradox can be real in the code and small in a given data set, and only a measurement says which.
The winner’s curse: chosen, then judged on the same data
Galton again saw that the sons of very tall fathers are tall, but less than their fathers: an extreme value holds a share of luck that does not repeat. Petroleum engineers met it at auctions, where the winning bid is often the one that overestimated most. In modelling it strikes whenever something is chosen because it looks best, a window, a date, a lag, a set of rows, and then judged on the data that chose it.
One of our functions searched for the time window where two series were most correlated, then computed every statistic on that window. On series whose true correlation is 0.6, it reported 0.667 on average, and its 95% interval missed the true value three times in ten (over 30 simulated series). Every reported statistic is now computed on the declared data, 0.604 on the same series; the chosen window is kept only as an exploration, labelled as such, with its own p-value corrected for the number of windows explored:
where is the number of points, the shortest window allowed and the number of windows of consecutive points holding at least of them. The correction is deliberately severe: the window kept is the one with the strongest correlation, and this correction holds whatever the dependence between windows.
The same curse hit our break detection. A candidate date was proposed where the gap between before and after was largest, then tested at that date as if it had been fixed in advance, with the points treated as independent. On 400 simulated series of 120 points with no break at all, that former test found one in 31.5% of series of independent noise, 83.3% when each point kept half of the previous deviation and 99% when it kept 0.8 of it. The validation now compares the statistic at the chosen date with the maximum of the same statistic over every admissible date, under a resampling that keeps the dependence:
where is the Mann–Whitney statistic comparing the points before and after date , the dates that leave enough points on each side, and the same statistic on the -th of resampled series. These are drawn by blocks of random length from the series centred on each side of its strongest split, so that a real break does not pass for dependence. Because the reference takes the maximum over every date, choosing the date is paid for. When a series is too dependent for its length, with too few independent blocks, the engine abstains instead of testing. On the same 400 series per case, counted over all the series, the false breaks fall to 2.5%, 5.3% and 0%; for the dependent series the engine abstained in 77% and 84% of cases (2% for independent noise), saying that it cannot tell rather than guessing. Counted only over the series where it did conclude, the reading is different: 2.6% for independent noise (10 of 392), 0% at 0.8 (0 of 66), but 23% at 0.5 (21 of 92). Abstention protects the total, not each conclusion, which is why we give the abstention rate next to the error rate: a break reported on a strongly dependent series deserves a second look. These figures also hold only for the configuration we measured and calibrated, a window of 120 points with at least 15 on each side. With the library’s default settings, which are not calibrated (at least three points on each side, the whole series), a later check on series of 200 points with no break found a validated false break in 20 of 60 series when each point keeps 0.8 of the previous deviation (33%), in 1% to 3% of independent series of 200 points (100 per case), and in 48 of 60 random walks (80%), where the engine abstained in only 21. That limit is open in the register: outside the configurations it has measured, the validation must either be calibrated or abstain.
The rule that removed influential claims from our severity models had a quieter form of the same flaw. It accepted a deletion when the information criterion of the model fitted without five claims was lower than that of the model fitted on all of them: two numbers computed on different samples. A criterion summed over fewer rows is almost always lower. On clean simulated data the deletion was accepted in 100% of runs, for the five largest claims as for five claims drawn at random, and removing the five largest lowered the average severity by about 1% at each pass. Both fits are now judged on one common sample, all the rows:
where is the density of the model, the dispersion of the full fit, the number of parameters, and and the parameters fitted with and without the candidate rows. The full fit maximises this likelihood, so it cannot lose on its own rows: in our simulations the deletion was never accepted, large genuine claims are kept, and a gross error is reported instead of being deleted. Our causality tests between series had the same weakness in another form, the decision reading the smallest p-value over the lags tried; they now correct over the lags of each pair, then across all the pairs.
Multiplicity: many tests, one threshold
A 5% test run 190 times finds about nine relations in pure noise. That is what our correlation matrix did: on 20 independent variables, 190 pairs, it listed 9.6 “significant” pairs per run on average, and at least one in every run. The pairs are now judged on their false discovery rate, with adjusted p-values, or q-values, computed over the whole family:
where are the p-values of the family in increasing order; a pair is kept when its is at most the level. On the same simulations: 0.06 pairs per run on average, and at least one in 6% of runs. When every relation is null, the 5% is spent on the whole family, not on each pair.
Defining the family is a decision in itself, and we fix it by the question asked, not by convenience. In our statistical-analysis toolkit, pairwise comparisons were issued as soon as the overall test was significant on its raw p-value; they are now issued only when the overall test stays significant after the adjustment of its family, and the others are listed as withheld. The verdicts that sum up a relation read the adjusted decisions, never the raw p-values.
Repeated looks are the same problem spread over time. Our A/B test function answered “continue the test” when nothing was significant yet, which invites another look. Read at each of five looks and stopped at the first win, a test with no difference declared a winner in 14.5% of simulations instead of 5%. It also sized the test from the gap observed so far, which after a lucky first look is too large. The number of looks and the effect worth detecting are now declared before the data, and the 5% is spent across the looks by a Lan–DeMets function of the O’Brien–Fleming type:
on each side, where , between 0 and 1, is the share of the planned sample already observed, the standard normal distribution function and its quantile, so that on each side and in total. The boundary of each look is solved so that the probability of crossing it first equals the share of spent since the previous look. Early looks spend almost nothing, so an early stop needs overwhelming evidence. Over 4,000 simulated tests with no difference: 5.5% false winners, within simulation error of the 5% declared.
Jensen: the average of a calculation is not the calculation on the average
Two insureds have a chance of another payment of 0.5 and 0.9. They expect 1 and 9 further payments, 5 on average. Apply the same formula to their average chance, 0.7, and it gives 2.3. For a non-linear function the average of the results is not the result on the average; for a product of two uncertain quantities, the gap is exactly their covariance:
One component of our trajectory model, the care reported late, multiplied an amount by an expected share, as if the delay and the amount were independent. On a real portfolio we tested that independence state by state: it was rejected in 59% of states, at a 5% false discovery rate. The defect is demonstrated; the fix, drawing the delay and the amount together in the simulation, is the next step recorded in the register.
A cousin of the same error is to average ratios. A claim frequency or a pure premium is a ratio of sums, and the ratio of sums is an exposure-weighted average of the individual ratios, not their plain average:
where is the number or the cost of the claims of policy and its exposure. In a plain average, a policy observed for a few days with one claim weighs as much as a policy observed for a year. In the former code of our risk-grouping engine the gap reached 20%; every rate is now a ratio of sums. Our trajectory simulations follow the same principle at a larger scale: they compute on whole paths and average afterwards, instead of feeding averages into a non-linear formula.
Censoring: what the valuation date hides
A sample can be biased by the moment it is looked at. At a valuation date, the moves that happen quickly are already visible and the slow ones are not yet: among the moves observed, the fast destinations are over-represented. In a simulation where half the episodes go to a fast destination and half to a slow one, 60.3% of the observed moves were fast, against 50% in truth.
Our trajectory model offers several ways of learning delays. Its factorised censored kernel learned when the next move happens with censoring taken into account, but where it goes from the observed moves alone: it inherited the 60.3%, whatever the time already spent waiting. A cause-specific kernel, available as an option and not yet the model’s default, learns both together, each visit contributing what it really says, “no move for so many days, then this destination”, or, for a visit still open at the date, only “no move for so many days”:
where is the contribution of one visit to the log-likelihood, the daily probability of a move in the time interval , the number of days spent in that interval without a move, the interval of the move, its destination and the share of the moves of interval that go to . The law of what comes next, given days of silence, then depends on the silence:
where is the waiting time and the next state. In the factorised kernel does not depend on , so a silence changes when the next move will come but never where it will go. With the cause-specific kernel a long silence makes the slow destination likelier, as it should: at the start, 51.0% fast against 50% in truth; after ten days of silence, 12.2% against 10.6%, where the factorised kernel still says 60.3%. One limit is stated rather than hidden: beyond the longest delay observed, a zone the data do not identify, this kernel extends the last hazard it learned; the share of simulated scenarios that go there is measured and reported, but nothing is refused, and whether to refuse is still an open decision in the register.
A register, not an impression
Each function and each step of our pipelines is entered in the register paradox by paradox, with one of four statuses: not concerned, and why; checked without defect; defect demonstrated, with its demonstration; or to be checked, never presented as a defect until it is demonstrated. Some demonstrated defects still wait for their fix and are listed as such: the joint draw of delay and amount, the rows that mix paid and unpaid claims, the behaviour beyond the longest observed delay. The review of every family of tests in our statistical-analysis toolkit is still in progress.
On real data the size of each effect is measured separately. It can be large, small or nil, as the split of episodes above shows, and we report it as it is. Our articles on correlations, on treatment effects, on our trajectory model, our time-series protocol and on data leakage describe the engines these checks are built into.
References
E. H. Simpson (1951), “The interpretation of interaction in contingency tables”, Journal of the Royal Statistical Society B; F. Galton (1886), “Regression towards mediocrity in hereditary stature”, Journal of the Anthropological Institute; E. B. Tylor (1889), with F. Galton’s remarks of November 1888, Journal of the Anthropological Institute; E. C. Capen, R. V. Clapp and W. M. Campbell (1971), “Competitive bidding in high-risk situations”, Journal of Petroleum Technology; J. M. Robins, A. Rotnitzky and L. P. Zhao (1994), “Estimation of regression coefficients when some regressors are not always observed”, Journal of the American Statistical Association; K.-Y. Liang and S. L. Zeger (1986), “Longitudinal data analysis using generalized linear models”, Biometrika; H. B. Mann and D. R. Whitney (1947), Annals of Mathematical Statistics; D. N. Politis and J. P. Romano (1994), “The stationary bootstrap”, Journal of the American Statistical Association; D. N. Politis and H. White (2004), “Automatic block-length selection for the dependent bootstrap”, Econometric Reviews, corrected by A. Patton, D. N. Politis and H. White (2009); H. Akaike (1974), “A new look at the statistical model identification”, IEEE Transactions on Automatic Control; Y. Benjamini and Y. Hochberg (1995), “Controlling the false discovery rate”, Journal of the Royal Statistical Society B; Y. Benjamini and D. Yekutieli (2001), Annals of Statistics; P. C. O’Brien and T. R. Fleming (1979), “A multiple testing procedure for clinical trials”, Biometrics; K. K. G. Lan and D. L. DeMets (1983), “Discrete sequential boundaries for clinical trials”, Biometrika; J. L. W. V. Jensen (1906), Acta Mathematica; R. L. Prentice, J. D. Kalbfleisch et al. (1978), “The analysis of failure times in the presence of competing risks”, Biometrics.
More publications
PublicationsCorrelations: deciding which relations deserve to be read
A correlation matrix can give hundreds of mathematically correct numbers and several false conclusions. Computing a correlation is not our problem; deciding which test to read, and whether the relation deserves to be read at all, is. This article follows our correlation and test engines step by step, in the order they run, with the rules that decide and the measurements that show where the usual shortcuts go wrong: what one observation is, which quantity is compared and which test it calls for, which assumptions are checked and on what, what time, controls and segments change, how many tests were really run, and what the engines refuse to compute rather than guess.
Read the articleModel validationData leakage in insurance models: the future is the easiest feature to use by accident
A datum is admissible only if it was observable at the decision date: where the future hides in insurance files, why a random split hides it, what it caught in our work.
Read the articleCausal inferenceDid it work? Measuring the effect of a decision without fooling yourself
A campaign, a new deductible, a reminder letter: did it change the outcome? Comparing those who received it with those who did not answers a different question. This article shows how we estimate the effect of a decision on observational data, what each estimate assumes, why the usual estimator can fail when the decision is rolled out in waves, what we do when only a few units received it, and how we keep a study of many segments from finding effects that do not exist.
Read the articleLet’s build better decisions together
Tell us about the decision you need to make.
A few lines are enough: your sector, the data you have and what you want to improve. We reply personally with a first view of the approach.
- A few lines are enough
- NDA on request
- Code and documentation handed over


