[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: finding roots in Mata

From   Austin Nichols <>
Subject   st: finding roots in Mata
Date   Fri, 30 Jan 2009 13:05:16 -0500

Roger et al.--
Out of curiosity, I compared:
1. using Ben Jann's mm_root() (findit moremata) to find a zero of f
2. using official Stata optimize() to find a min of f^2
for a problem of occasional interest--finding the modal kth order
statistic in a sample of n draws from a standard normal distribution,
which is given by the zero of f(x)=
per Gupta (1961),
[see also ]
and in this case Ben Jann's mm_root() is far superior.

For n more than about 13, and k=n, optimize() skips over interior
solutions and skitters off toward a very large x where normalden(x)
and 1-normal(x) both approach zero.  There is an alternative
parametrization for which optimize() performs as well as mm_root(), in
terms of finding the right answer, but optimize() takes 7 msec and
mm_root takes 2 msec:

The above also illustrates a possibly common pitfall in such problems,
which frequent users of -ml- may already know well--beware of using
quantities like 1-normal(x), which can easily reach zero as x gets
large while the equivalent normal(-x) is nonzero.

On Thu, Jan 29, 2009 at 3:03 AM, Roger Harbord <> wrote:
> On Thu, Jan 29, 2009 at 12:57 AM, Austin Nichols
> <> wrote:
> <snip>
>> I think Mata's optimizer is probably the best option for this problem,
>> if one has Stata 10 --Roger Harbord says "Mata -optimize()-  is also
>> designed as a maximizer (or minimizer) rather than a root-finder" but
>> note that Mata's optimize() can minimize (F(x)-A)^2 just fine which is
>> the same as finding a root of F(x)-A.
> I just had a gut feeling that changing a root-finding problem to a
> minimization problem in this way loses information in some ill-defined
> sense so is likely to be less efficient, and maybe less robust too. I
> have no more formal or empirical evidence either way though. Anyone?
> --
> Roger Harbord
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index