Repository navigation
Open
Milestone
Description
edit this looks more like a problem for score and profile likelihood confidence intervals with a link function that does not satisfy domain constraints.
I got an example where scoretest raises with singular matrix in np.linalg.solve
This is using #4716, and a score confidence interval example.
Maybe I need to use pinv instead of solve.
0.23119 -71.3544794856 [ 0.05000118]
Traceback (most recent call last):
File "E:\Josef_new\scripts\score_confint_naive.py", line 55, in <module>
low = optimize.brentq(diff_scoretest, wald_ci[0]*2, wald_ci[0]*0.5, xtol=1e-5)
File "...\WinPython-64bit-3.4.4.5Qt5\python-3.4.4.amd64\lib\site-packages\scipy\optimize\zeros.py", line 442, in brentq
r = _zeros._brentq(f,a,b,xtol,rtol,maxiter,args,full_output,disp)
File "E:\Josef_new\scripts\score_confint_naive.py", line 41, in diff_scoretest
pvalue = resc.score_test()[1]
File "E...\statsmodels_py34_pr\statsmodels\genmod\generalized_linear_model.py", line 1671, in score_test
observed=observed)
File "...\statsmodels_py34_pr\statsmodels\base\_parameter_inference.py", line 249, in score_test
chi2stat = score.dot(np.linalg.solve(cov_score_test, score[:, None]))
File "...\WinPython-64bit-3.4.4.5Qt5\python-3.4.4.amd64\lib\site-packages\numpy\linalg\linalg.py", line 384, in solve
r = gufunc(a, b, signature=signature, extobj=extobj)
File "...\WinPython-64bit-3.4.4.5Qt5\python-3.4.4.amd64\lib\site-packages\numpy\linalg\linalg.py", line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix
example is during score confidence interval search
2-sample proportion, second exog is indicator with 11 of 100 obs in group 0
>>> y.tolist()
[1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1]
>>> x[:,1].tolist()
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
Activity
josef-pkt commentedon Jul 17, 2018
current script file
score_confint_naive.pyjosef-pkt commentedon Jul 17, 2018
AFAICS, the problem comes from using identity link and a Domain violation, probability outside [0, 1], in GLM-Binomial.
The bounds for the brentq zero search don't take into account that parameters should imply probabilities in [0, 1].
running the example with a different seed:
That means, that score_test is just where it fails, but the cause is some more fundamental problem in the score confidence interval computation. With identity link wald confidence intervals do not necessarily imply predicted probabilities in [0, 1].
Profile confint in #1791 have most likely the same problem with using wald confint as bounds for the confint search.
josef-pkt commentedon Jul 17, 2018
parking the corrected script here
now limits the search bounds to have valid probability, but specific to two sample case. Finding bounds will be more difficult in more general cases with more regressors. But it should not be a problem with links that respect domain.
I changed the seed and relative nobs to try different cases. No exception, but warnings from in some cases.
example results with equal nobs in both samples, nobs=100
confint differ a bit more across methods with unequal sample sizes