You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do we have a way to drop redundant columns automatically from exog during model initialization? This comes up sometimes when working with formulas having complicated interactions and dummy coding. Sometimes there are linear dependencies in the design matrices that cannot easily be removed by modifying the formula. I end up splicing the code below into the model __init__ function.
q, r = np.linalg.qr(exog)
dr = np.abs(np.diag(r))
if np.any(dr < 1e-10):
ii = np.flatnonzero(dr >= 1e-10)
exog = exog[:, ii]
if exog_names != None:
exog_names = [exog_names[i] for i in ii]
I added a fit_collinear, and we will get some code to identify and drop collinear columns.
However, I don't know if we can include it in model initialization.
If we drop columns, then the formula design_info does not correspond to the internal exog.
For example we would need to handle the same column dropping in predict after patsy creates a predict exog.
In fit_collinear I internally create a model with reduced exog, but the main model of the user has zeros in params and cov_params.
This is similar to OLS where the pinv sets the params of a column of zeros to zero, but I don't remember the other details of that case.
R seems to do this somehow pretty universally across models.
I need it for models like MixedLM where there is non-standard parameter packing, so it would probably need to be handled there as a special case.
Maybe we could store the indices of non-redundant columns under an attribute with a standard name, like _use_cols, then predict would look for this and if present expand or reduce the parameter vector as needed.
Regarding thresholds, no I don't know what would be a good constant.
Activity
josef-pkt commentedon Jun 2, 2018
I added a fit_collinear, and we will get some code to identify and drop collinear columns.
However, I don't know if we can include it in model initialization.
If we drop columns, then the formula design_info does not correspond to the internal exog.
For example we would need to handle the same column dropping in predict after patsy creates a predict exog.
In fit_collinear I internally create a model with reduced exog, but the main model of the user has zeros in params and cov_params.
This is similar to OLS where the pinv sets the params of a column of zeros to zero, but I don't remember the other details of that case.
josef-pkt commentedon Jun 2, 2018
I added
_fit_collinearhere https://github.com/statsmodels/statsmodels/pull/4576/files#diff-b165b4bd4e10edd0dfb485e47c562b2cR655But the main work for recreating a model and fitting it with zero-constraints is in
_fit_zerosjosef-pkt commentedon Jun 2, 2018
BTW: do you have any information about what a good default threshold for the qr version of identifying collinear columns is?
kshedden commentedon Jun 2, 2018
R seems to do this somehow pretty universally across models.
I need it for models like MixedLM where there is non-standard parameter packing, so it would probably need to be handled there as a special case.
Maybe we could store the indices of non-redundant columns under an attribute with a standard name, like
_use_cols, then predict would look for this and if present expand or reduce the parameter vector as needed.Regarding thresholds, no I don't know what would be a good constant.