Skip to content

Added fit params for the poisson model inside the NB - #3578

Closed
denadai2 wants to merge 1 commit into
statsmodels:masterfrom
denadai2:master
Closed

denadai2 wants to merge 1 commit into
statsmodels:masterfrom
denadai2:master

Conversation

@denadai2

@denadai2 denadai2 commented Mar 25, 2017 •

Copy link
Copy Markdown

I added the minimum amount of parameter to fit the Poisson inside the NB fit. They are inherent from the NB paramters.

This solve many potential problems with the convergence, including #3572

thx

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.007%) to 90.29% when pulling 78112d6 on denadai2:master into c906881 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

some test failures in test_sandwich_cov.TestNegbinCluExposure

needs decision for 0.9

I kind of like the solution, but I'm not sure yet whether I prefer an alternative with explicit keywords, or some kind of fit_difficult solution.
related #3921 should fix llnull convergence problems

@josef-pkt

josef-pkt commented Sep 22, 2017 •

Copy link
Copy Markdown
Member

about the test failure in test_sandwich_cov.TestNegbinCluExposure
The test fails on scipy < 0.18, AFAICS, which is the same problem with bfgs that I had in #3921
The dataset for test case is ships.csv in discrete.tests.results

In the test case the optimization option are not changed in the fit call. However, Poisson defaults to "newton" and NegativeBinomial defaults to "bfgs". After the change in this PR, method="bfgs" in NB gets transmitted to Poisson which doesn't seem to work in the older scipy.
AFAIR, since scipy 0.18, bfgs has worked well again, after fixing to allow smaller stepsizes.

A related possibility: If the preliminary estimator finds a good start_params for the main model, even if that optimization is difficult, the main model estimation might be easier and would work with a more efficient optimizer. In that case we would want a robust optimizer like "nm" in the preliminary and "newton" or similar in the main estimation.

A change needed if we do something like in this PR: we need to transmit other keywords, at least the option for "minimize", so we can, e.g., use dogleg for both. e.g.
fit_kwds = dict(method="minimize", min_method='dogleg')

Another issue, that I don't remember whether I tried for Poisson and Negbin is to start from the null model estimate if constant is included in the model, i.e. use mean for constant and zeros for slope coefficients.

@josef-pkt

Copy link
Copy Markdown
Member

adding another issue here:
the preliminary estimator does not skip_hessian (merged in #1952). The hessian is not needed and is an unused, possibly expensive computation.

@josef-pkt

josef-pkt commented Sep 22, 2017 •

Copy link
Copy Markdown
Member

trying out the example (without offset)

solution with an attribute for fit options

model_nb.optim_kwds_prelim = dict(method='bfgs')
res_nb_d = model_nb.fit()

Optimization terminated successfully.
         Current function value: 6.452032
         Iterations: 14
         Function evaluations: 15
         Gradient evaluations: 15

or putting it in fit **kwargs:

res_nb_prelim = model_nb.fit(optim_kwds_prelim=dict(method='bfgs'))

Optimization terminated successfully.
         Current function value: 6.452032
         Iterations: 14
         Function evaluations: 15
         Gradient evaluations: 15

I like the fit keyword better, but given the current **kwargs we cannot add it as explicit keyword, and I don't like to put it before the regular fit keywords.

@josef-pkt

Copy link
Copy Markdown
Member

just a few "nm" iterations in preliminary Poisson are enough in this case.
"nm" does not converge in 50 iterations, warn_convergence=False (as used in llnull) avoids printing the warning

res_nb_prelim = model_nb.fit(optim_kwds_prelim=dict(method='nm', maxiter=50, warn_convergence=False))`\

Optimization terminated successfully.
         Current function value: 6.452032
         Iterations: 14
         Function evaluations: 15
         Gradient evaluations: 15

with only two explanatory variables, skip_hessian does not make any difference
bfgs as prelim is faster than "nm" with maxiter=50, in this case, and with scipy 0.18.1

In [37]:
%timeit res_nb_prelim = model_nb.fit(disp=0, optim_kwds_prelim=dict(method='nm', maxiter=50, warn_convergence=False, skip_hessian=True))
10 loops, best of 3: 24.2 ms per loop

In [35]:
%timeit res_nb_prelim = model_nb.fit(disp=0, optim_kwds_prelim=dict(method='nm', maxiter=50, warn_convergence=False))
10 loops, best of 3: 25.5 ms per loop

In [38]:
%timeit res_nb_prelim = model_nb.fit(disp=0, optim_kwds_prelim=dict(method='bfgs', maxiter=50, warn_convergence=False, skip_hessian=True))
100 loops, best of 3: 14.8 ms per loop

​

josef-pkt added a commit that referenced this pull request Sep 25, 2017
ENH: add optim_kwds_prelim to count models in discrete_model closes #3578
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.

3 participants