Consider the following:
probs <- c(0.05, rep(0.95/99, 99))
which clearly sums to 1 according to
sum(probs).
However, when I type
sum(probs == 1)
I get 0 (i.e, boolean FALSE).
Why does this discrepancy occur? Shouldn't the two commands be equal?
As a test, I compared these with all.equal():
all.equal(sum(probs), sum(probs == 1))
[1] "Mean relative difference: 1"
all.equal(sum(probs == 1), sum(probs))
[1] "Mean absolute difference: 1",
which seems to suggest inequality, but why?
My guess would be numerical precision handling in R (i.e., Machine epsilon) is not stringent enough.
Any thoughts?