[R] Variance for Vector of Constants is STILL Not Zero
Thomas Lumley
tlumley at u.washington.edu
Fri Feb 17 23:02:57 CET 2006
On Fri, 17 Feb 2006, Barry Zajdlik wrote:
> Hello all,
>
> Thanks for the responses but I am still annoyed by this seemingly simple
> problem; I recorded sessionInfo() as below.
>
> x<-rep(0.02,10)
>> var(x)
> [1] 1.337451e-35
Well, yes, it is accurate only to 35 digits and this is a bit unfortunate
since it could be more accurate in this case. The exact result is probably
system-dependent, but there has been a bug report for a long time
(PR#1228) that var() is not as accurate as it could possibly be, and
patches would be welcome. They obviously aren't a very high priority for
anyone.
> I Changed .Machine$double.eps to make the calculations LESS accurate.
> My thought was that if I reduced the precision, 1-eps would return 1
> instead of some number less than 1. My thought was that if eps were
> sufficiently large my sample problem would return a zero. This didn't
> happen though.
>
.Machine is a set of constants that describe your hardware and C
implementation. They are right when you start. If you change them all
that happens is that they become wrong -- R doesn't go in and re-engineer
the floating point hardware.
-thomas
More information about the R-help
mailing list