Priors that regularize without dictating

Today let's understand how to pick a prior that keeps a fit honest without quietly deciding the answer for it.

A plant is piloting a new valve seal. It tests 20 valves, 10 with the old seal and 10 with the new seal, and checks every valve for a leak after a standard pressure test.

4 of the 10 old-seal valves leak. By chance, 0 of the 10 new-seal valves leak.

Here is that result as a share of valves that leaked, one bar for each seal.

Zero leaks out of 10 looks like a clean win for the new seal. But a pilot this small can get lucky, and a plain logistic fit on these same 20 valves is about to show exactly what that luck can do.

Why glm() breaks on this pilot's data

Logistic regression models the probability of a leak as a function of which seal is used. In R, you fit it with glm(), and family = binomial tells it to fit a logistic curve rather than a straight line.

The data has one row per valve, 20 rows in total: seal records "old" or "new", and y records 1 for a leak and 0 for no leak.

Fit that model on the pilot data and look at its coefficients.

RInteractive R
# Fit a logistic regression of leak on seal type, using the pilot data d <- data.frame( seal = factor(c(rep("old", 10), rep("new", 10)), levels = c("old", "new")), y = c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, # 4 of 10 old-seal valves leaked 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) # 0 of 10 new-seal valves leaked ) fit <- glm(y ~ seal, family = binomial, data = d) summary(fit) #> #> Call: #> glm(formula = y ~ seal, family = binomial, data = d) #> #> Coefficients: #> Estimate Std. Error z value Pr(>|z|) #> (Intercept) -0.4055 0.6455 -0.628 0.530 #> sealnew -19.1606 3400.7176 -0.006 0.996 #> #> (Dispersion parameter for binomial family taken to be 1) #> #> Null deviance: 20.016 on 19 degrees of freedom #> Residual deviance: 13.460 on 18 degrees of freedom #> AIC: 17.46 #> #> Number of Fisher Scoring iterations: 18 exp(coef(fit)["sealnew"]) # the same coefficient, converted to an odds ratio #> sealnew #> 4.771508e-09

  

Logistic regression works on the log-odds scale: instead of modeling the leak probability directly, it models the log of the odds of a leak, log(p / (1 - p)), as a straight line in the predictors. sealnew is the coefficient of that line for a new-seal valve relative to an old-seal one, on that log-odds scale. Exponentiating a log-odds coefficient converts it back to an odds ratio, the number you would quote to say how many times more or less likely a leak is.

Here that coefficient is -19.16, and its standard error is 3,400.72, roughly 180 times the coefficient itself. A standard error that much bigger than the estimate means the data are compatible with almost any coefficient in that range, not just -19.16. As an odds ratio, exp(-19.16) comes out to about 4.8 in a billion, which says a new-seal valve is practically incapable of ever leaking.

That is not a reasonable claim from 10 valves. It happens because every one of the 10 new-seal valves came back leak-free. With no new-seal leak to pull it back, the fit can keep pushing the new-seal coefficient further toward negative infinity and the likelihood keeps climbing, because the model's fit to the old-seal rows, which do contain both leaks and non-leaks, is all that eventually stops it. Statisticians call this quasi-complete separation: one level of a predictor is perfectly separated from the outcome, even though the whole dataset is not.

No warning message appears here, but 18 Fisher Scoring iterations is itself the tell. An ordinary, well-behaved logistic fit converges in a handful of iterations, not eighteen. Eighteen means the optimization kept pushing the coefficient toward a boundary it never reached.