Convert logistic regression coefficient confidence intervals to odds-ratio intervals

Quick Overview

Implement a NumPy function that turns logistic regression coefficient confidence intervals on the log-odds scale into odds-ratio intervals. It tests why a monotone transform keeps coverage, how to read an interval that contains 1, and where float64 exp overflows or underflows.

Convert logistic regression coefficient confidence intervals to odds-ratio intervals

Role: Data Scientist

Category: Machine Learning

Difficulty: easy

Interview Round: Other

Implement `odds_ratio_ci(coef_ci: np.ndarray) -> np.ndarray`. The input is a `(k, 2)` float array of log-odds coefficient confidence bounds (column 0 is the lower bound, column 1 the upper bound), as returned by `statsmodels` `res.conf_int()` for a fitted logistic regression. Return the odds-ratio confidence intervals by exponentiating both endpoints. Requirements: - Return a new `float64` array of shape `(k, 2)`. - Each output row is `[exp(lower), exp(upper)]` of the corresponding input row. - All returned values must be strictly positive. Example: ```python coef_ci = np.array([[-0.1, 0.5], [0.05, 0.30], [-1.2, -0.3]]) result = odds_ratio_ci(coef_ci) # result.shape == (3, 2) # row 0: [exp(-0.1), exp(0.5)] = [0.9048..., 1.6487...] contains 1.0 -> not significant ``` Be ready to explain why exponentiating the endpoints gives a valid interval for the odds ratio and how to read each row of the result. ```hint Monotone transforms Ask what a strictly increasing function does to the event $L \le \beta \le U$, and whether float64 can always keep `exp` strictly positive. ``` ### Constraints & Assumptions - `coef_ci` has shape `(k, 2)`, one row per model coefficient, with column 0 never above column 1. - Results are compared against the exact exponentials with `rtol=1e-9`, along with checks on the shape and on every value being greater than 0. ### What a Strong Answer Covers - A vectorized implementation that returns a new `float64` array of shape `(k, 2)`. - Why mapping both endpoints through a strictly increasing function keeps the interval's coverage and its lower/upper order. - How to read a row: an interval containing 1 versus one entirely above or below 1, and the link to the coefficient interval containing 0. - Why the odds-ratio interval is asymmetric around the exponentiated point estimate. - The numeric limits of `exp` in float64 and what they mean for the positivity requirement. ### Follow-up Questions - If you only had each coefficient and its standard error, how would you build the odds-ratio interval? - Why is a delta-method interval for the odds ratio worse than exponentiating the coefficient interval? - How would you report the interval for a 10-unit increase in the predictor? - What does the exponentiated interval for the intercept mean?

Overview: Implement a NumPy function that turns logistic regression coefficient confidence intervals on the log-odds scale into odds-ratio intervals. It tests why a monotone transform keeps coverage, how to read an interval that contains 1, and where float64 exp overflows or underflows.

General logo
General
Nov 25, 2026
easyData ScientistOtherMachine Learning
0
0

Implement odds_ratio_ci(coef_ci: np.ndarray) -> np.ndarray. The input is a (k, 2) float array of log-odds coefficient confidence bounds (column 0 is the lower bound, column 1 the upper bound), as returned by statsmodels res.conf_int() for a fitted logistic regression. Return the odds-ratio confidence intervals by exponentiating both endpoints.

Requirements:

  • Return a new float64 array of shape (k, 2) .
  • Each output row is [exp(lower), exp(upper)] of the corresponding input row.
  • All returned values must be strictly positive.

Example:

coef_ci = np.array([[-0.1, 0.5], [0.05, 0.30], [-1.2, -0.3]])
result = odds_ratio_ci(coef_ci)
# result.shape == (3, 2)
# row 0: [exp(-0.1), exp(0.5)] = [0.9048..., 1.6487...] contains 1.0 -> not significant

Be ready to explain why exponentiating the endpoints gives a valid interval for the odds ratio and how to read each row of the result.

Constraints & Assumptions

  • coef_ci has shape (k, 2) , one row per model coefficient, with column 0 never above column 1.
  • Results are compared against the exact exponentials with rtol=1e-9 , along with checks on the shape and on every value being greater than 0.

What a Strong Answer Covers Guidance

  • A vectorized implementation that returns a new float64 array of shape (k, 2) .
  • Why mapping both endpoints through a strictly increasing function keeps the interval's coverage and its lower/upper order.
  • How to read a row: an interval containing 1 versus one entirely above or below 1, and the link to the coefficient interval containing 0.
  • Why the odds-ratio interval is asymmetric around the exponentiated point estimate.
  • The numeric limits of exp in float64 and what they mean for the positivity requirement.

Follow-up Questions Guidance

  • If you only had each coefficient and its standard error, how would you build the odds-ratio interval?
  • Why is a delta-method interval for the odds ratio worse than exponentiating the coefficient interval?
  • How would you report the interval for a 10-unit increase in the predictor?
  • What does the exponentiated interval for the intercept mean?