Skip to content

R truncating decimal places

2 messages · Andrea Goijman, William Dunlap

#
Hello list,

I' trying to estimate a log likelihood function from my data.
I apply the mean to all my simulations, and I get something like this:

apply(likelihood, c(2, 3, 4), mean,na.rm=TRUE)
, , 1

             [,1]       [,2]       [,3]      [,4]      [,5]        [,6]
 [,7]
  [1,] 0.73162327 0.81197093 0.58216435 0.7295733 0.8930731 0.971775402
0.8882391
  [2,] 0.73162327 0.81197093 0.00000000 0.7295733 0.8930731 0.971775402
0.8882391

If you note, there is a 0.00000000 value, and it seems that R is truncating
it as a zero, because when I apply the log

apply(likelihood, c(2, 3, 4), mean,na.rm=TRUE)

I get a "-inf" at that position...


How do I avoid R truncating this value?

Thanks!

Andrea
#
Do not compute the log likelihood as the log of the product of
probabilities.  Instead compute it as the sum of logs of probabilities.
The latter is less likely to underflow (go below c. 0^-309).

Most (all?) of the built-in probability density functions have a 'log'
argument; when log=TRUE you get the log of the density.

E.g.,
[1] -Inf
[1] -10510.64
[1] -196.0814
[1] -196.0814



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, May 22, 2017 at 12:10 PM, Andrea Goijman <andrea.goijman at gmail.com>
wrote: