Re: [R] Variance for Vector of Constants is STILL Not Zero

From: Thomas Lumley <>
Date: Sat 18 Feb 2006 - 09:02:57 EST

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 mailing list PLEASE do read the posting guide! Received on Sat Feb 18 09:18:16 2006

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 14:08:40 EST