Skip to content

BUG/ENH: GMM, allow None exog and instruments in generic GMM #2633

Open

Description

@josef-pkt

working with the Gamma example for GMM in Greene.

Here we only have a single data variable, e.g. just an endog

fit and summary work if we create fake exog and instruments to provide the shape, but it doesn't work if we set exog and instrument to None.

ENH: provide better default support when we don't have the endog, exog, instrument pattern for the data and model.

problems: how and where do we infer and set k_params and k_moments, and how do we set the param names? (summary/SimpleTable truncate params list if names are not full length)

(edit) param_names handling in GMM looks a bit outdated, needs check with current implementation of generic attributes in model.data. We have now param_names separate from xnames, IIRC.

(edit 2) I'm not sure anymore it's a code or documentation problem (and missing informative ValueErrors). If I set k_moments and k_params correctly, then everything seems to work, even with GMM(y, None, None, ...).

>>> model2 = my_GMM2(X, None, None)
>>> res_c2 = model2.fit(start_params=[2.05831079,  0.06579918], inv_weights=np.eye(4), maxiter=2, optim_method='nm', wargs=dict(centered=True))
Optimization terminated successfully.
         Current function value: 0.001803
         Iterations: 30
         Function evaluations: 60
Optimization terminated successfully.
         Current function value: 0.105310
         Iterations: 37
         Function evaluations: 66
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34\statsmodels\sandbox\regression\gmm.py", line 679, in fit
    self._fix_param_names(params, param_names=None)
  File "m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34\statsmodels\sandbox\regression\gmm.py", line 531, in _fix_param_names
    if len(params) < len(xnames):
TypeError: object of type 'NoneType' has no len()

Activity

  1. josef-pkt commented on Oct 1, 2015

    @josef-pkt
    MemberAuthor

    to replicate Greene's results, requires

    >>> res_c = model.fit(start_params=[2.,  0.1], inv_weights=np.eye(4), maxiter=2, optim_method='nm', wargs=dict(centered=False))
    Optimization terminated successfully.
             Current function value: 0.001803
             Iterations: 67
             Function evaluations: 124
    Optimization terminated successfully.
             Current function value: 0.098761
             Iterations: 43
             Function evaluations: 81
    >>> print(res_c.summary(title='Gamma distr.', xname=['alpha', 'beta']))
                                     Gamma distr.                                 
    ==============================================================================
    Dep. Variable:                      y   Hansen J:                        1.975
    Model:                        my_GMM2   Prob (Hansen J):                 0.372
    Method:                           GMM                                         
    Date:                Thu, 01 Oct 2015                                         
    Time:                        17:28:47                                         
    No. Observations:                  20                                         
    ==============================================================================
                     coef    std err          z      P>|z|      [95.0% Conf. Int.]
    ------------------------------------------------------------------------------
    alpha          3.3590      0.450      7.470      0.000         2.478     4.240
    beta           0.1245      0.029      4.278      0.000         0.067     0.182
    ==============================================================================
    
    >>> res_c.params
    array([ 3.35896678,  0.12449005])
    >>> res_c.bse
    array([ 0.44968713,  0.02909953])
    
  2. josef-pkt commented on Oct 2, 2015

    @josef-pkt
    MemberAuthor

    I ran into this before see https://github.com/statsmodels/statsmodels/pull/2455/files#diff-1b3411f7d5ad604e44f690f8d7790fe0R184
    because it was just internal code I quickly worked around it. But it doesn't work for summary.

    #2455 is unfinished because I didn't have time and didn't have Stata 14 to test against

  3. josef-pkt commented on Oct 8, 2015

    @josef-pkt
    MemberAuthor

    relevant issue for setting xnames or param_names (maybe outdated) #1465

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions