From bhh at xs4all.nl  Mon Jun  3 09:01:25 2013
From: bhh at xs4all.nl (Berend Hasselman)
Date: Mon, 3 Jun 2013 09:01:25 +0200
Subject: [Rd] RFC: a "safe" uniroot() function for future R
In-Reply-To: <20904.24724.932826.199873@stat.math.ethz.ch>
References: <20903.2899.135264.914688@stat.math.ethz.ch>
	<CA+COuteo2iQHZyneAy+x7qsfB7G_Erc2GVXpcSTyxez-FVTuOQ@mail.gmail.com>
	<20903.11965.812306.509672@stat.math.ethz.ch>
	<51A773B3.8080807@gmail.com>
	<20904.24724.932826.199873@stat.math.ethz.ch>
Message-ID: <D0EFA24D-4AD5-4967-9BA8-FC75F3128AED@xs4all.nl>


On 31-05-2013, at 10:34, Martin Maechler <maechler at stat.math.ethz.ch> wrote:

?..
> From the current feedbacks, I'd come to propose / further
> discuss the following issues:
> 
> 1) the goal is to remain with one function uniroot()
> 
> 2) Instead of the 'Sig' = "sign(f'(x_0))" {not quite, but typically}
>   with 4 different value classes, namely
>   NULL, -1, 0, 1,  (where +/- 1  are equivalent to any positive
>   or negative finite number respectively),
> 
>   we should either use a string with 4 different possible values
>   or a {logical or NULL}, say 'upcrossing' 
>   (which also gives 4 values, NULL, NA, FALSE, TRUE).
> 
> 
> 3) [I'm not sure about this:]
>   The new default of the 'Sig' replacement would correspond to
>   the current  Sig = NULL  which does extend the search
>   interval when that does not constitute a sign change.
> 
>   Alternatively, implicitly proposed by Ravi Varadhan, the
>   default would correspond to  Sig = 0, i.e. to the current
>   uniroot() behavior which signals an error as soon as the initial
>   interval is not large enough.
> 
> Further opinions and suggestions for  '2)' and '3)' are still
> very welcome!

I agree with Ravi. Ravi's example shows what can go wrong.
Let the default behaviour of a new uniroot() be the current behaviour.
No harm will be done to any existent applications.

An option would be to append a suggestion to the current error message: "Consider setting argument Sig to non-zero to expand the range of x" or something similar when Sig = 0 and uniroot can't find a solution.

In addition I think that it should be possible to specify an absolute lower and upper limit for x in order to avoid evaluating a function for invalid values of its argument (e.g. log(x) for negative x)
Silly example:

xstart <- c(100,110)
unirootS(f, xstart, Sig=10,trace=2)


Berend



[Rd] RFC: a "safe" uniroot() function for future R
Berend Hasselman