Repository navigation
Conversation
|
floating point noise is machine dependent. |
e9103d7 to
ba98b72
Compare
|
new unit test fail again in all python versions. Again, floating point noise is not "reliable" |
|
test error in some version was invalid scalar indexing, most likely with older numpy. |
8a599e0 to
266de3c
Compare
|
Finally all green test coverage above 90% but still a few missing options, besides untested ValueErrors. I'm about finished here, it has all the functions I want right now. But, it would benefit from another API review. constant handling: What should the results for open enhancements:
|
There was a problem hiding this comment.
threshold is not documented
sequence of moment_matrix and standardize is reversed, also in other docstrings
|
TODO: minor cleanup, rebase, merge |
|
missing: check official import path (diagnostic ?), add to api and rst docs |
|
bump, the comments sound there is only some cosmetics left to do. What's the status? (Why are you asking me, you wrote it? |
|
bump again |
4403101 to
d79b5a5
Compare
|
rebased (no merge conflict), appveyor errors in unrelated statespace about standardized (zscored) variables: need to check what it is doing here. |
| """base class for multicollinearity measures | ||
| """ | ||
|
|
||
| def __init__(self, data, moment_matrix=None, standardize=True, |
There was a problem hiding this comment.
need separate center deman option, i.e. scale to unit norm-2 length
There was a problem hiding this comment.
and option to demean only non-constant variables
|
|
||
| """ | ||
|
|
||
| def __init__(self, data, moment_matrix=None, standardize=True, |
There was a problem hiding this comment.
option for scaling without demeaning
| self._init_moment(xm) | ||
| else: | ||
| if standardize: | ||
| x = (x - x.mean(0)) / x.std(0) |
There was a problem hiding this comment.
alternative: allow constant but don't demean it
|
|
||
| This corresponds to R^2 in a linear regression of one variable on all | ||
| others, including a constant if standarize is true, i.e. data was | ||
| demeaned. |
There was a problem hiding this comment.
explain whether or when centered or uncentered rsquared
| variables. | ||
|
|
||
| Warning: This uses the matrix inverse of the moment matrix, which can | ||
| produce nans or raise exceptions in singular or near-singular cases. |
There was a problem hiding this comment.
check is this exog-scale invariant, it should be
There was a problem hiding this comment.
possible problem here: I think this method assumes that mom_inv is demeaned to have an interpretation as correlation
(not checked, I'm working on semi-partial correlation and in an example I get a diff of around 1e-4 for semi-partial corr between corr and mom (xtx) versions.
|
|
||
| @cache_readonly | ||
| def eigenvalues(self): | ||
| """eigenvalue of the correlation matrix |
There was a problem hiding this comment.
correlation matrix only if standardize, otherwise it's of the moment matrix
| return evals | ||
|
|
||
| @cache_readonly | ||
| def condition_number(self): |
There was a problem hiding this comment.
add condition_index or replace by that
np.sqrt(eigvals.max() / eigvals)
|
|
||
| """ | ||
|
|
||
| def __init__(self, data, moment_matrix=None, standardize=True): |
There was a problem hiding this comment.
same her, allow demean and scaling separately
| return 1 - self.rss / self.tss | ||
|
|
||
|
|
||
| def vif(data, standardize=True, moment_matrix=None, ridge_factor=1e-14): |
There was a problem hiding this comment.
replace standardize as above
|
not sure:
Those two could be in a |
|
To the last point, methods that require correlation (i.e. standardized moment matrix) We can just add a warning, if we don't have enough information to determine whether we have a correlation matrix or not, and maybe raise if we know we don't and cannot reconstruct it internally. |
|
move to milestone 0.14. The main open issue is design, how to handle both cases with and without constant, and possibly with scaling. AFAIR, there is no clean separation for methods that apply to only one or the other cases. edit it might be easier to split into two classes normalized (cov, corr) and raw (with constant in x) |
|
2 options here for refactoring to disentangle with and without constant
scaling:
for first option, an all-in-one class
Problem with this is that some cached properties need to be methods instead, we will need to add options for scaling/constant treatment. I guess it will be easier to first try out 2 subclasses. Also update update2 but there is no cond_index in the PR on github. |
|
I pushed the old cond_index commit new cond_index code has no unit test coverage, |
|
based on R log, to compare results with R packages, I had used initially olsrr function but then only |
|
From an answer by myself on the mailing list to different condition numbers in the OLS notebook Something like this should make it as introduction into the docs "
Each measure alerts to different effects. |
…ar_index Continue the work of #2380 and #7711 with a smaller API that is exported from statsmodels.stats.api. - vif computes the variance inflation factors of all columns from the eigendecomposition of the correlation matrix. It accepts a data matrix or a covariance or correlation matrix (is_moment), returns a Series for a DataFrame, raises for constant columns or skips them (has_constant), and returns inf for columns that are collinear with other columns. - vif_ridge computes the ridge VIF of all penalization factors with one decomposition and has the same arguments. - collinear_index flags columns that are collinear with preceding columns using Gram-Schmidt with reorthogonalization and a relative tolerance. - The MultiCollinearity classes and vif_selection are removed. The classes duplicated the functions, did not return pandas objects and had unfinished handling of constants and singular data. vif_selection returned a placeholder. - cache_readonly, which no longer exists, and np.corrcoef(bias=...), which was removed in NumPy 2, are not used anymore. The tests are rewritten. They compare with R (car::vif and the aliased columns of lm, in tests/results/results_multicollinearity.py), with OLS, with variance_inflation_factor and with the SAS output for ridge VIF of the original pull request. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
additional measures for multicollinearity and enhanced variance inflation factor
relevant issues
#2376 treatment of constant for variance inflation factor
#1669 vif for ridge regression, base for non-loop calculation
#2157 general request for multicollinearity measures
#6249 problems with implicit or no constant
#2378 condition number, scaling
related issues
#1744 diagnostic messages including multicollinearity
#2062 use reduced column space for singular design matrices, I started to work on this with
fit_transformedfit_constrainedpattern#1534 partially related for dropping singular, perfectly collinear columns
#4582 sequential dropping of large vif columns
Note:
Definition of "perfect collinearity" and "singular", "reduced rank" design matrices are subject to floating point noise and have different thresholds. see #1662