[R] Matrix calculations in R--erroneous?

Peter Muhlberger peterm at andrew.cmu.edu
Sat Oct 8 17:17:03 CEST 2005


Hi Spencer:  Thanks!  This gives me a number of other ways of thinking about
this problem.  My one concern is that these approaches would also run into
some difficulties with how long it takes to calculate.  I'm interested not
in a single value but a matrix of over 300k values that has to be recomputed
more than a million times.  If I had to apply ifelse or floor to each of
these, it might take too long.  I'll have to see.

Peter

On 10/7/05 5:55 PM, "Spencer Graves" <spencer.graves at pdf.com> wrote:

>  Rather than adding 1e-15 to all numbers, I suggest you simply make
> that the floor.  (Or use .Machine$double.eps or 2*.Machine$double.eps in
> place of 1e-15.)
> 
>  Another alternative that may or may not apply in your case is to
> develop an asymptotic expansion for the log(likelihood) for the small
> numbers.  I've had good success with this kind of method.  For example,
> consider the Box-Cox transformation:
> 
>  bc(y, b) = (y^b-1)/b
> 
>  What do we do with b = 0?  We can test for b = 0 and replace those
> cases by the limit log(y).  However, it is numerically more stable to
> use the following:
> 
>  bc(y, b) = ifelse(abs(b*log(y))>.Machine$double.eps,
> (expm1(b*log(y))/b, log(y)).
> 
>  I don't have time to study your example to see if I could see
> anything like this that could be done, but I think there should be a
> good chance of finding something like this.  Of course, if there are
> only very few 0's, then it hardly matters.  However, if there are quite
> a few, then you need something like this.
> 
>  hope this helps.
>  spencer graves




More information about the R-help mailing list