Skip to content

BF: use proper scale into HuberScale estimator instead of stand_mad. - #1355

Open
VirgileFritsch wants to merge 3 commits into
statsmodels:mainfrom
VirgileFritsch:rlm_convergence
Open

VirgileFritsch wants to merge 3 commits into
statsmodels:mainfrom
VirgileFritsch:rlm_convergence

Conversation

@VirgileFritsch

Copy link
Copy Markdown
Contributor

In the IRLS algorithm, Huber's scale update is:

"sigma^{n+1} = 1/n_a * sum(\chi(r_i/s)) * s *_ 2,"

where "s = sigma^{n}".

Actual statsmodels' master branch uses "s = mad(r)" by default instead and there is no possibility to change this. In the literature, mad(r) is sometimes used directly to perform the scale update (I guess for code simplification purpose), but I cannot find any reason why we would use mad(r) in combination with an HuberScale estimator.

For backward compatibility reasons, MAD stay the default init scale estimator in HuberScale iterations when None is provided.

MAD stay the default init scale estimator in HuberScale iterations
when None is provided.
@josef-pkt

Copy link
Copy Markdown
Member

This conflicts with some changes that I made in #1341

The use of mad as starting value is wrong, it should be mad with center=0. Changed in my PR.

adding an optional starting value is good.
I haven't figured out the impact of the other changes in this PR yet.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling 130f69d on VirgileFritsch:rlm_convergence into 541d746 on statsmodels:master.

@VirgileFritsch

Copy link
Copy Markdown
Contributor Author

The changes in terms of results were very small as far as I experienced. This confirms that using the HuberScale update is mainly a theoretical thing that does not have a strong impact in practice (or rather, that as never been shown to have a strong impact...).

Except for the "center=0" argument in mad, I could not find any conflict with you PR.

@josef-pkt

Copy link
Copy Markdown
Member

In some of the almost degenerate, almost perfect prediction cases mad or HuberScale with different cutoff value makes a difference. see the second example on the mailing list thread "RLM all combinations"

What I haven't figured out yet, is whether HuberScale converges to a unique solution, even with different starting values, especially in the degenerate cases.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling 76f3663 on VirgileFritsch:rlm_convergence into 541d746 on statsmodels:master.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only point where I have conceptual problems.
wls_results.scale is not a robust estimator, It could be far off if there are large outliers.
I think we should still start with mad, center=0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think it is better to start with a mad. If the initial scale
estimate is to small, the residuals can indeed become large and every
observation be assigned a null weight.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I realise from what I just wrote that the danger is to
underestimate the initial scale. If we overestimate it instead, it may take
one iteration more to converge (since the weights will all be 1 at the
first step) but IRLS would still succeed. On the contrary, if the scale is
underestimated, we are in the degenerated case I mentioned before.
I am afraid that if a sufficient number of observations fall on the
regression hyperplane, then mad could be equal to zero (could it?) and then
we are in trouble.

I am sorry, I am a bit tired :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that mad can be equal to zero (and even worse when mad without center is equal to zero) was the reason for my PR 1341. Adding center=0 for mad rules out the second case, And I added some special treatment for scale=0.

The problem with overestimating the scale is that redescending norms, loss functions, might end up in a local minimum, that doesn't remove many outliers. Standard recommendation (as far as I have seen) is to start with a robust, high breakdown scale estimate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: I edited your comments to remove the previous comments that were left in the reply.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be careful next time I reply by mail. Sorry for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Huber's "Robust Statistics" book:

"As starting values (\theta^(0), \sigma^(0)), we usually take the ordinary least squares estimate, despite its known poor properties [cf. Andrews et al. (1972), for the simple location case].
Redescending \psi-functions are tricky, especially when the starting values for the iterations are non-robust. Residuals that are accidentally large because of the poor starting parameters then may stay large forever because they exert zero pull. It is therefore preferable to start with a monotone \psi, iterate to death, and then append a few (1 or 2) iterations with the nonmonotone \psi."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1354 :) The only quote I kept track of
note the words "usually" and "poor properties" in the first sentence in your quote.
I don't have a counter quote, because I didn't keep track, I'm browsing or reading chapters in several books (skipping allmost all the theoretical parts for influence functions and so on)

From the plot it looks like HuberT and RamseyE are the only not redescending, and RamseyE is (re)descending at infinity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we agree on the fact the we could use mad(resid, center=0). I changed this into the PR code.
Alternatively, we can give the choice to the user by using the 'init' keyword argument. I think it was partly created for this kind of purpose, so why not accepting "init='ols'/None/False" for an initialization with OLS scale, and "init='mad'" for an initialization with MAD?

Interestingly, changing the OLS scale for a MAD did not change the results of the tests I performed...

@josef-pkt

Copy link
Copy Markdown
Member

@VirgileFritsch background questions: How did you find this? Do you have some examples where you ran into problems with this?

Now that you pointed it out, I also think starting from the previous scale during updating is better than always starting from mad.

@VirgileFritsch

Copy link
Copy Markdown
Contributor Author

In my applications, I have thousands of targets and I figure out that I
could speed up RLM by fitting and testing the targets simultaneously. Yet,
it was difficult to implement within statsmodels given the complexity of
the code structure: the API afford fine-tuning RLM and is very general (the
user can choose a loss function, a covariance type, a stopping criterion,
the scale estimate, ...).
So I came up with my own implementation and used half statsmodels and
Huber's book to do it. This gave me the opportunity to browse statsmodels
code into details. As my tests (including a comparison with statsmodels
results) were failing, I realized that there was this scale estimation
problem.

I could not experience a large difference in term of results between both
implementations (using the mad or the previous estimate) except maybe a
bias in the robust F-test nominal control. I cannot remember now if the
test was too conservative or anti conservative with the MAD but from
empirical considerations I trust more Huber's version (previous estimate).

@josef-pkt josef-pkt added the PR label Feb 19, 2014
@jseabold

jseabold commented Apr 3, 2014

Copy link
Copy Markdown
Member

@josef-pkt merge this or do you want to cherry-pick as part of your other PR?

@josef-pkt josef-pkt added this to the 0.6 milestone May 22, 2014
@josef-pkt josef-pkt modified the milestones: 0.6, 0.7 Sep 22, 2014
@josef-pkt josef-pkt modified the milestones: 0.8, 0.7 Feb 4, 2015
@josef-pkt josef-pkt removed the PR label Mar 5, 2016
@jseabold jseabold removed this from the 0.8 milestone Apr 2, 2021
@josef-pkt josef-pkt added this to the 0.15 milestone May 2, 2024
@josef-pkt

Copy link
Copy Markdown
Member

I guess this can be closed.
But it would be better to compare it to the current implementation before closing.

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.

4 participants