2025, Dec 04 17:00
Extracting Odds Ratios from statsmodels GEE: A Simple, Reliable Method Using Coefficients
Compute odds ratios from statsmodels GEE fast: read fitted params for each predictor and exponentiate the coefficient; no GlobalOddsRatio required. Simple.
Extracting odds ratios from a statsmodels GEE fit: a quick, reliable path
Generalized Estimating Equations in statsmodels make it straightforward to fit clustered models, but it’s not always obvious how to turn fitted coefficients into odds ratios. If you’re tempted to reach for GlobalOddsRatio, pause: for per-predictor odds ratios you only need the model coefficients from the fitted result.
Problem setup
Suppose you fit a GEE and want the odds ratio for a specific predictor. The modeling code might look like this:
import statsmodels.api as sm
cov_ar = sm.cov_struct.Autoregressive()
gee_mod = sm.GEE(a_endog, b_exog, grp_ids)
gee_fit = gee_mod.fit()
print(gee_fit.summary())
After inspecting the summary, the next step is to obtain the odds ratio for the predictor of interest.
What’s going on
The fitted model stores the estimated coefficients in the params attribute. The odds ratio for a given predictor is obtained by exponentiating its coefficient. There’s no need to use GlobalOddsRatio for this.
Solution
Read the coefficient from the fitted result and exponentiate it. That’s all that is required.
import numpy as np
beta_b = gee_fit.params.b_exog
or_b = np.exp(beta_b)
print(or_b)
If you need the odds ratio for another named predictor, access that coefficient from params in the same way and exponentiate it.
Why this matters
Odds ratios are often the most interpretable quantity for stakeholders. Knowing that you can derive them directly from the fitted coefficients saves time and avoids unnecessary detours through unrelated APIs.
Takeaways
After fitting a GEE in statsmodels, use the params attribute to access the coefficient for the predictor you care about, and apply an exponential transform to get its odds ratio. It’s a direct, dependable approach that keeps your workflow simple.