BUG: CovDetMCD/CovDetS/CovDetMM 在 nobs < 2*k_vars + 4 时会引发 ValueError
The first percentile appears to be "take roughly the 2*(k_vars + 2) observations closest to the center as one candidate starting set". This is not a problem in the case of nobs >= 2*k_vars + 4, but it is a problem in the case of nobs < 2*k_vars + 4.
The failure comes from the deterministic starting-set construction, not from the estimator itself, so it happens before any user parameter is consulted. In statsmodels/robust/covariance.py, _cov_starting (line 1398 on main):
percentiles = [(k_vars + 2) / nobs * 100 * 2, 25, 50, 85]
cutoffs = np.percentile(d, percentiles)The first element is 200 * (k_vars + 2) / nobs, which exceeds 100 — and so trips numpy's range check — exactly when nobs < 2 * k_vars + 4.
The affected region is inside the documented usable range of the estimators. CovDetMCD requires only h > k_vars for the subset covariance to be non-singular, and h defaults to well above k_vars here; e.g. at nobs=60, k_vars=30 the max-breakdown h = (nobs + k_vars + 1) // 2 = 45 > 30, so the estimate is well defined. R's robustbase::covMcd(x, nsamp = "deterministic") computes the same case successfully, emitting only a n < 2 * p warning.
内容来源: statsmodels/statsmodels