Skip to content

BUG/ENH: support offset in truncated count models - #8845

Merged
josef-pkt merged 4 commits into
statsmodels:mainfrom
josef-pkt:discrete_offset
May 1, 2023
Merged

josef-pkt merged 4 commits into
statsmodels:mainfrom
josef-pkt:discrete_offset

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

see #8842

@josef-pkt

Copy link
Copy Markdown
Member Author

I might stop here with code changes, some unit tests still missing

I started adding offset exposure to the discrete model _derivative methods, but they will not be in use in 0.14.
delayed to 0.15 unless I write full unit tests for those, unlikely for 0.14.0

@josef-pkt

Copy link
Copy Markdown
Member Author

Andrews Wave has precision issue in unit test in pre testing
adjustment to test precision included in this PR

I don't know why this only fails in pre-testing.
precision is limited by numdiff _approx_fprime_scalar

_________________________ test_norms_consistent[case2] _________________________
[gw0] linux -- Python 3.11.3 /opt/hostedtoolcache/Python/3.11.3/x64/bin/python

case = (<class 'statsmodels.robust.norms.AndrewWave'>, ())

    @pytest.mark.parametrize("case", norms_other)
    def test_norms_consistent(case):
        # test that norm methods are consistent with each other
        ncls, args = case
        norm = ncls(*args)
        x = np.array([-9, -6, -2, -1, 0, 1, 2, 6, 9], dtype=float)
    
        weights = norm.weights(x)
        rho = norm.rho(x)  # not used
        psi = norm.psi(x)
        psi_deriv = norm.psi_deriv(x)
    
        # check location and u-shape of rho
        assert rho[4] == 0
        assert np.all(np.diff(rho[4:]) >= 0)
        assert np.all(np.diff(rho[:4]) <= 0)
    
        # avoid zero division nan:
        assert_allclose(weights, (psi + 1e-50) / (x + 1e-50), rtol=1e-6, atol=1e-8)
        psid = _approx_fprime_scalar(x, norm.rho)
>       assert_allclose(psi, psid, rtol=1e-6, atol=1e-8)

statsmodels/robust/tests/test_norms.py:94: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_allclose.<locals>.compare at 0x7fa178a85760>, array([-0.        ,  0.        , -1.33501761, -0.90960..., -9.09600019e-01,
        2.67166048e-07,  9.09600034e-01,  1.33501761e+00,  0.00000000e+00,
        0.00000000e+00]))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-06, atol=1e-08', 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-06, atol=1e-08
E           
E           Mismatched elements: 1 / 9 (11.1%)
E           Max absolute difference: 2.67166048e-07
E           Max relative difference: 1.
E            x: array([-0.      ,  0.      , -1.335018, -0.9096  ,  0.      ,  0.9096  ,
E                   1.335018, -0.      ,  0.      ])
E            y: array([ 0.000000e+00,  0.000000e+00, -1.335018e+00, -9.096000e-01,
E                   2.671660e-07,  9.096000e-01,  1.335018e+00,  0.000000e+00,
E                   0.000000e+00])

@josef-pkt
josef-pkt merged commit e32c093 into statsmodels:main May 1, 2023
@josef-pkt

Copy link
Copy Markdown
Member Author

pre-testing in main passes again except for test_bernstein_1d which is still waiting for updated scipy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant