Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 0 in R instead of a precise result

Tags:

r

computation

How can I get the actual precise result instead of the rounded ones?

result = ((0.61)**(10435)*(0.39)**(6565))/((0.63)**(5023)*(0.60)**(5412)*(0.37)**(2977)*(0.40)**(3588))

out:

NaN

Because, denominator is 0

like image 492
moli Avatar asked Nov 22 '25 14:11

moli


1 Answers

I think logarithm is a power tool to deal with exponential with large powers (see it properties in https://mathworld.wolfram.com/Logarithm.html)

You can try to use log first over your math expression and then apply exp in turn, i.e.,

result <- exp((10435*log(0.61)+6565*log(0.39)) - (5023*log(0.63)+5412*log(0.60)+ 2977*log(0.37)+3588*log(0.40)))

which gives

> result
[1] 0.001219116
like image 106
ThomasIsCoding Avatar answered Nov 25 '25 05:11

ThomasIsCoding