The interview problem
Two unpenalized logistic models are fitted by maximum likelihood to the same 10,000 observations. The restricted model contains an intercept and age. The full model adds two prespecified, identifiable features. Their maximized log likelihoods are −4,120 and −4,114. Compute a likelihood-ratio test, state its assumptions and explain why the same parameter-count rule can fail at a boundary.
Original fundamentals practice, not a reported company interview. All numerical examples are hypothetical. Interview date not applicable; primary technical references retrieved September 27, 2026.
1. Establish nesting before subtracting scores
The restricted parameter space must be contained in the full one. Here setting the two added coefficients to zero recovers the restricted logistic model. Both models must describe the same observed outcomes with compatible likelihood conventions.
Fit the models on the same observation IDs. If the full model silently drops rows with missing new features, its score is not directly comparable to a restricted model fitted on more rows. Differences in response transformation, likelihood constants, weights or objective definitions also require examination.
For properly optimized nested models, the full model's maximized likelihood cannot be smaller because it can choose the restricted solution. This does not mean extra features improve future predictions; it is a property of optimization over a larger parameter space.
2. Calculate the statistic with the correct sign
Λ = maximized restricted likelihood / maximized full likelihood D = −2 log(Λ) = 2 × (full log likelihood − restricted log likelihood)
Work with log likelihoods to avoid numerical underflow. In the example:
D = 2 × [−4,114 − (−4,120)] = 12 number of independent restrictions = 4 − 2 = 2
Under the regular large-sample null approximation, compare D with a chi-square distribution with two degrees of freedom. For this distribution the upper-tail probability at 12 is exp(−12/2):
p ≈ exp(−6) ≈ 0.00247875
At a prespecified 5% level, this rejects the joint null that the two added coefficients are zero, subject to the modeling and sampling assumptions. A p-value is not the probability that the null is true. Nor does rejection establish a causal effect, useful deployment improvement or correctness of the full model.
A materially negative D indicates a problem with convergence, nesting, rows or objective consistency. Do not silently clamp it to zero and report a reassuring p-value. Tiny floating-point differences need a numerical tolerance, but that tolerance is not a substitute for checking the fits.
3. Explain the chi-square approximation
The usual result relies on a smooth, identifiable model with the true null parameter in the interior, nonsingular information and suitable sampling assumptions. The model dimension stays fixed as sample size grows, and the relevant maximum-likelihood estimates must exist and be fitted adequately.
Count independent restrictions, not just displayed columns. Perfectly collinear features do not add two identifiable degrees of freedom merely because two columns were appended. Logistic separation can prevent a finite maximum-likelihood estimate, undermining a routine calculation based on a purported converged fit.
Unmodeled dependence or a misspecified likelihood can invalidate ordinary calibration. Merely attaching robust standard errors to a fitted model does not automatically make its likelihood difference follow the usual chi-square distribution. Use a justified likelihood, test or calibration procedure for the actual design.
A penalized training objective is not the ordinary maximized likelihood. The difference between two regularized losses cannot automatically be substituted into this formula. Large neural-network parameter counts and singular models also do not inherit the regular fixed-dimensional argument by default.
4. Derive a boundary counterexample
Let Xi be independent Normal(μ, 1) observations. Test μ = 0 against μ ≥ 0, with variance known. The maximum-likelihood estimate over the constrained full parameter space is max(0, X̄). The constrained alternative contains the null at its boundary.
D = n × [max(0, X̄)]² under μ = 0: Z = √n X̄ ~ Normal(0, 1) therefore D = [max(0, Z)]²
Half the time Z is nonpositive, producing D = 0. For positive values the statistic has the corresponding upper half of the squared-normal distribution. Thus this particular null distribution is a mixture of a point mass of one-half at zero and one-half of a chi-square distribution with one degree of freedom.
At an observed D = 4, the correct upper-tail probability is:
P(D ≥ 4) = P(Z ≥ 2) ≈ 0.0227501 ordinary chi-square(1) tail at 4 ≈ 0.0455003
The one-sided and two-sided full models each have one free mean parameter, while the null fixes it at zero. Their dimension difference is the same, but the constraint geometry changes calibration. If the alternative instead allowed any real μ, then D = nX̄² would be exactly chi-square with one degree of freedom in this known-variance normal example.
The half-mixture is derived for this specific case; it is not a universal rule for variance components, mixtures or unidentified parameters. At the atom D = 0, P(D ≥ 0) = 1, so the positive-statistic half-tail formula must not be applied there indiscriminately.
5. Use a reproducible comparison workflow
freeze observation IDs, response and likelihood convention
↓
verify nesting and independent restrictions
↓
fit both models and inspect convergence/identifiability
↓
calculate D from unpenalized maximized log likelihoods
↓
choose justified null calibration
↓
report test, effect and predictive evidence separatelyRecord formulas, fitting options, optimizer diagnostics, parameter ranks and sample counts. Inspect unexpectedly large coefficients or instability across starting values. A software function returning a p-value is evidence that a computation ran, not evidence that its assumptions hold.
The statsmodels reference for linear-model likelihood comparisons explicitly warns about unspecified heteroskedasticity and correlation. Its robust large-sample option is a modified score/LM procedure, not a blanket guarantee that every likelihood-ratio statistic becomes robust. Keep the distinction between a package's implementation and the mathematical test being described.
For a calibrated chi-square reference distribution, an implementation can use a survival function such as SciPy's chi2.sf(D, df), rather than subtracting a CDF from one in an extreme tail. Accurate arithmetic still requires a valid reference distribution.
6. Consider null simulation when justified
A parametric null bootstrap can estimate calibration under a fitted null model: simulate data under that null using the same design, refit both models with their constraints, and recompute D for each simulation. Preserve the relevant dependence structure and fitting procedure. Simply resampling observed rows does not automatically simulate the null hypothesis.
For 9,999 simulated statistics, suppose 24 are at least as large as the observed statistic. A common smoothed Monte Carlo tail estimate is:
estimated p = (24 + 1) / (9,999 + 1) = 0.0025 approximate Monte Carlo standard error ≈ √[0.0025 × (1 − 0.0025) / 10,000] ≈ 0.000499
This standard error describes simulation noise approximately, not the uncertainty from misspecifying the null model. Fitting a composite null and simulating at estimated parameters does not automatically create an exact finite-sample test. Report failed fits and investigate them; selectively discarding difficult replicates can change the reference distribution.
Refitting both models requires 19,998 simulation fits, in addition to the original fits. Budget computation and enough replications for the tail probability of interest. A reported zero exceedance count is not proof of zero probability.
7. Separate statistical evidence from usefulness
The full logistic model improves total log likelihood by 6 across 10,000 observations. Its average training negative log likelihood improves by only 6/10,000 = 0.0006 nats per observation. A detectable difference can still be small in operational terms.
Evaluate held-out predictive loss, calibration, relevant decision metrics and feature collection cost. Compare effect estimates with uncertainty where appropriate. The likelihood-ratio test asks about restrictions within a model family; it does not choose the best production system.
The two features in the prompt were prespecified. Trying many features and reporting only the smallest p-value changes the inference problem. Account for the search or use a properly designed confirmatory analysis. Repeated inspection and model selection are not repaired by citing a large sample size.
8. Diagnose invalid comparisons
| Problem | Why the shortcut fails | Next step |
|---|---|---|
| Different observation sets | Log likelihoods score different data | Align the sample and explain the missingness policy |
| Nonnested models | Parameter-count difference does not supply this null law | Choose an appropriate comparison method |
| Boundary or unidentified parameter | Regular local geometry fails | Derive or validate a suitable reference distribution |
| Separation or failed optimization | Reported fit may not represent a finite maximum | Diagnose estimation before testing |
| Correlated observations | Assumed likelihood omits dependence | Model the dependence or justify a robust alternative |
| Penalized objective | Loss difference is not the stated likelihood ratio | Use a method appropriate to the estimator |
Likelihood-ratio tests require both fits. Score tests can use the null fit, while Wald tests use estimated parameters and curvature at the full fit. Their finite-sample behavior can differ; none is universally best across irregular settings.
Interview follow-ups
- The full model fits worse. Check data alignment, optimization, objective definitions and actual nesting before interpreting D.
- The test does not reject. This does not prove the added features have no effect; examine power and uncertainty.
- The extra feature is a copy of another. Check rank and identifiability instead of incrementing degrees of freedom mechanically.
- The result is significant but test loss worsens. Statistical fit improvement on the analyzed sample is not held-out utility.
- Can I use the boundary mixture everywhere? No. The normal example derives one distribution for one constraint structure.
Self-review rubric
A strong answer verifies nesting and identical data, computes the sign and factor of two correctly, and counts independent restrictions. It states regularity before choosing a p-value and explains a concrete boundary failure. An excellent answer diagnoses fit problems, separates predictive usefulness from significance and reports simulation assumptions and Monte Carlo uncertainty honestly.
Sources and attribution
- statsmodels: compare_lr_test — nested-model statistic and implementation caveats; documentation displayed version 0.15.0.
- SciPy: chi2 — chi-square distribution and survival-function interface; documentation displayed version 1.18.0.
Retrieved September 27, 2026; publication dates unstated. The logistic example, constrained-normal derivation and simulation counts are original teaching material. These technical references do not establish recent company interview attribution.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.