# Re: [R] Matrix calculations in R--erroneous?

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Sat 08 Oct 2005 - 03:12:30 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> -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]
>  Inf
>
> Yet:
>
> Browse> 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
>
> So, the logitShape component equals 1.

to within 2e-16

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

to within 2e-16

> Browse> yMat2[5,9]
>  1

to within 2e-16

to within a few parts in 10^16

You haven't actually shown us yMat2[5,9]-yMat1[5,9]*logitShape()[5,9], though

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

If "0" is really of the order of 1e-16 then this isn't surprising. If the only point of 1e-323 is as a guard value for 0 then use max(1e-323, yMat2[5,9]-yMat1[5,9]*logitShape()[5,9])

-thomas

R-help@stat.math.ethz.ch mailing list