[Rd] NA warnings for r<distr>() {aka "patch for random.c"}

Berwin A Turlach statba at nus.edu.sg
Tue Mar 11 18:23:10 CET 2008


G'day Martin,

On Tue, 11 Mar 2008 18:07:35 +0100
Martin Maechler <maechler at stat.math.ethz.ch> wrote:

> >>>>> "BAT" == Berwin A Turlach <statba at nus.edu.sg>
> >>>>>     on Tue, 11 Mar 2008 13:19:46 +0800 writes:

[...]
>     BAT> The first two lines give identical results, as one could
>     BAT> reasonably expect.  
> 
> Yes, but I don't think a user should *rely* on the way R
> generates these random number; though I agree for the very
> specific case of rlnorm(..).
> 
>     BAT> But the other two do not and I would argue that a user could
>     BAT> reasonably expect that the commands in these two lines
>     BAT> should lead to identical results.
> 
> They now do.

Well, actually I forgot to mention one could also put another argument
forward.  As the log-mean parameter of the lognormal distribution
goes to -Inf, the distribution degenerates to something that has mean 0
and variance 0, i.e. could be taken as the constant zero and, hence,
one might expect that rlnorm(1, -Inf) returns 0.

But as the log-mean parameter goes to Inf, the distribution degenerates
to something with infinite mean and infinite variance.  Thus, perhaps
it is more sensible for rlnorm(1, Inf) to return NaN instead of Inf.....

> I don't think your change to  .../R/distn.R  was good,

I didn't like it either, but it was the simplest way I could think of
that would allow the C rexp() routine to realise that a scale parameter
of 0 actually came from a rate parameter of -Inf in the R code.  

> but the others I have more or less committed together with a few
> more similar ones.

Thanks.

>     BAT> BTW, I was surprised to realise that the *exp() functions in
>     BAT> the underlying C code use the opposite parameterisation from
>     BAT> the corresponding functions at R level.  Perhaps it would be
>     BAT> worthwhile to point this out in section 6.7.1 of the Writing
>     BAT> R extension manual?  In particular since the manual states:
> 
>     BAT> Note that these argument sequences are (apart from the names
>     BAT> and that @code{rnorm} has no @var{n}) exactly the same as
>     BAT> the corresponding @R{} functions of the same name, so the
>     BAT> documentation of the @R{} functions can be used.
> 
>     BAT> Well, as I noticed the hard way, for *exp() the
>     BAT> documentation of the corresponding R functions cannot be
>     BAT> used. ;-)
> 
> We often also gratefully accept patches for the documentation 

I know, and I am always amazed that despite this policy (or perhaps
because of it?) the documentation of R is not patchy.... ;-)

Cheers,
	
	Berwin



More information about the R-devel mailing list