[R] Matrix calculations in R--erroneous?

From: Peter Muhlberger <peterm_at_andrew.cmu.edu>
Date: Sat 08 Oct 2005 - 02:49:40 EST


Does anyone know how -log(x) can equal 743 but -log(x+0)=Inf? That's what the following stream of calculations suggest:

Browse[2]> -log ( 1e-323+yMat2 - yMat1 * logitShape(matrix(parsList$Xs, nrow = numXs, ncol=numOfCurves), matrix(means, nrow = numXs, ncol=numOfCurves, byrow=TRUE), matrix(sigmas, nrow = numXs, ncol=numOfCurves, byrow=TRUE)) )[5,9]
[1] Inf

Yet:

Browse[2]> logitShape(matrix(parsList$Xs, nrow = numXs, ncol=numOfCurves), matrix(means, nrow = numXs, ncol=numOfCurves, byrow=TRUE), matrix(sigmas, nrow = numXs, ncol=numOfCurves, byrow=TRUE))[5,9]
[1] 1

So, the logitShape component equals 1.

Browse[2]> yMat1[5,9]
[1] 1

So yMat1[5,9]*logitShape()[5,9]=1

Browse[2]> yMat2[5,9]
[1] 1

So, yMat2[5,9]-yMat1[5,9]*logitShape()[5,9]=0

Browse[2]> -log ( 1e-323)
[1] 743.7469

So, -log( 1e-323)=743 while -log( 1e-323+0)=Inf ?

Any idea of a neat way to get around this? Even if I put in 1e-50 I still get Inf. I deliberately included 1e-323 to insure the function didn't go to infinity.

Peter



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Oct 08 03:07:34 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:38 EST