Skip to content
Prev 78584 / 398502 Next

Matrix calculations in R--erroneous?

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
Peter Muhlberger wrote: