Skip to content

robust Huber fails to converge #550

Open

Description

@josef-pkt
>>> yy2 = [150.4, 28.8, 46.6, 40.2, 46.5]


>>> rob.Huber()(yy2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new\statsmodels\statsmodels\robust\scale.py", line 146, in __call__
    return self._estimate_both(a, scale, mu, axis, est_mu, n)
  File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new\statsmodels\statsmodels\robust\scale.py", line 190, in _estimate_both
    raise ValueError('joint estimation of location and scale failed to converge in %d iterations' % self.maxiter)
ValueError: joint estimation of location and scale failed to converge in 30 iterations

possible application: robust loc and scale estimation for outlier tests
thread at https://groups.google.com/d/topic/pystatsmodels/nsz5xJqCHbg/discussion

Activity

  1. josef-pkt commented on Oct 29, 2012

    @josef-pkt
    MemberAuthor

    using initscale solve the failure to converge problem, but initscale needs to be ndarray.

    (I never know whether scale is var or std.)

    >>> rob.Huber(maxiter=100)(yy2, initscale=44)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new\statsmodels\statsmodels\robust\scale.py", line 144, in __call__
        scale = tools.unsqueeze(scale, axis, a.shape)
      File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-all-new\statsmodels\statsmodels\tools\tools.py", line 459, in unsqueeze
        return data.reshape(newshape)
    AttributeError: 'int' object has no attribute 'reshape'
    
    >>> rob.Huber(maxiter=100)(yy2, initscale=np.array(44))
    (array(50.428559081875321), array(26.409490600556758))
    >>> np.mean(yy2)
    62.5
    >>> np.mean(yy2[1:])
    40.524999999999999
    >>> np.std(yy2[1:])
    7.2489223336989896
    >>> np.var(yy2[1:])
    52.546875
    >>> rob.Huber(maxiter=100)(yy2, initscale=np.array(52))
    (array(50.428559144933502), array(26.409490710050402))
    
  2. jseabold commented on Oct 29, 2012

    @jseabold
    Member

    I have the same issue with scale. Would be willing to consider a systematic overhaul for clarity (likely after getting 0.5-final out the door).

    These functions may need a little touching up / style-type changes for expected inputs, input names, etc.. They're mostly left untouched since nipy and before.

  3. josef-pkt commented on Oct 29, 2012

    @josef-pkt
    MemberAuthor

    Until now they were mostly used internally, but with some cleanup we could advertise them better.
    One possibility for using them would be to make a copy of outliers_influence.outlier_test that uses robust mean and scale.

    I didn't get huber_scale to work on the example (I didn't try to dig, just try "obvious" way of using it)

    >>> rob.hubers_scale(3, 4, yy)
    nan
    

    np.repeat(yy) didn't help

  4. jseabold commented on Oct 29, 2012

    @jseabold
    Member

    Agreed. I underestimated usefulness of robust methods. Difference between textbooks and "real" work maybe. Some examples in the robust tutorial on using but needs more.

  5. josef-pkt commented on Jan 27, 2014

    @josef-pkt
    MemberAuthor

    continuing from comments in #55

    Huber uses mad as initial value, which uses center=median independent of mu.
    For example when I want to fix mu at zero, Huber produces 0 variance, if I use initscale mad with center=0

    also Huber and HuberScale for fixed mu are the same, except for ddof
    unittest for Huber has test names reversed return is loc, scale and not scale, loc
    Huber docstring explains the M-estimation, but from that I don't see where gamma comes from

    >>> rscale.Huber(c=2.5)(chem, mu=np.array(0))
    (array(0), array(-0.0))
    >>> rscale.Huber(c=2.5)(chem, mu=np.array(0), initscale=rscale.mad(chem, center=0))
    (array(0), array(3.788720954409638))
    >>> rscale.HuberScale()(len(chem) - 1., len(chem), chem)
    3.9011267239325544
    >>> rscale.HuberScale()(len(chem) - 0., len(chem), chem)
    3.7887209578616114
    

    extra bug: mu needs to be an ndarray or we get exceptions.
    tools.unsqueeze(mu, axis, a.shape) requires mu to be array

  6. added
    type-possible-bug
    on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-robusttype-possible-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions