Repository navigation
Description
(random thoughts triggered by stackoverflow question. I didn't find a directly related issue, but some cases for empty cells in exog categorical interactions are in some issues or PRs)
empty cells in categorical interactions in exog
patsy keeps all (non-reference) interaction effects even if they are a column of zeros.
https://stackoverflow.com/questions/47444502/how-to-stop-patsy-from-creating-redundant-interactions-of-categorical-variables answer reparameterizes the pair of categorical variables
- It doesn't really matter in the case of OLS with pinv because the unobserved effect gets regularized to zero. possible problem is when regularization does not kick in see REF: pinv threshold, linear regression for almost singular #2628.
- However, that does not work for estimators that require non-singular exog, e.g. in discrete models and to some extend in GLM.
- explicit handling as part of multicollinearity treatment, i.e. automatically drop columns ???
interactions with discrete or limited support endog
related empty cells in contingency tables
There was recently a stackoverflow question about non-convergence and non-invertible hessian in Logit when exog had full rank. Question was deleted and data was private, so no reproducible example is available. I guess that case is related to partial separation (empty cells in combined endog-exog contingency table) for which we don't have any checks or examples, and the explanations are vague to me. Our check for perfect separation is for perfect prediction, but SAS/SPSS have checks for partial separation. Similar effects should also occur with multinomial and poisson models.
Solution in contingency tables is to add a positive value instead of the zeros, and similar Firth penalization can handle the case in Logit.
continuous variables
A bit related to this is extrapolation with continuous variables. This was for example discussed in treatment effect (???) literature with restrictions to predict within the support points. The main problem is that prediction and forecasting outside the support "envelope" completely relies on the functional form assumption for extrapolation. Related issue is in extrapolation with splines which patsy does not allow.
Similar issue is in propensity score matching or inverse probability weighting if the sample is unbalanced in the sense that we have very few observation of the "minority" treatment level for some set or range of exog.
In the continuous case we can have some standard measures like influence measure or Mahalanobis distance to measure the outlyingness of specific exog values.
I'm not sure what we can do within statsmodels. We need diagnostics to identify problematic cases and more penalization or variable selection to work around in some cases.
Activity
josef-pkt commentedon Nov 18, 2025
bump
I run into this again when looking at nested categoricals.
If the nested categorical has unique labels per item/individual, then patsy creates interaction with each of those even if the ones that are not nested in a specific higher level category are all empty columns.
Maybe cholesky dropping of columns would be useful in this case.
#3039 (comment)
#5722 (comment)
This should automatically work if we have partial nesting, i.e. some items are nested, some items are in more than one "nest". Some perfect collinearity would be removed.
We need a workable solution, ignore that we cannot do the proper split into anova parts (sum of squares) and focus on prediction and overall effects, or just plain standard Wald, score and likelihood ratio tests for whatever parameterization or encoding has been used.