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

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 17 Feb 2006 - 09:05:57 EST

This looks like the known problem, PR#1228.

It is possible to do better, but really users should be aware that numerical inaccuracies will occur, and not expect exact results from floating-point calculations.

On Thu, 16 Feb 2006, Uwe Ligges wrote:

> Barry Zajdlik wrote:
>
>> Hi All,
>>
>> An annoying but not critical problem I am having is that the variance of
>> a vector of constants is reported as > 0. I imagine there is a simple
>> workaround for the following but could not find it after having spent an
>> embarrassing amount of time.
>>
>> In Splus:
>>
>>
>>> x<-rep(0.02,10)
>>> var(x)
>>> 0
>>
>>
>> In R:
>>
>> x<-rep(0.02,10)
>> var(x)
>> 1.337451e-35
>
>
> Which version of R and which OS is this? I get 0 for both Linux and
> Windows with R-2.2.1.
> Anyway, 0.02 is not well representable and hence can be very well the
> cause for such a numerical inaccuracy.
>
>> I assumed the problem had to do with machine precision and suitably
>> modified .Machine$double.eps and .Machine$double.neg.eps which I thought
>> would fix the problem but without success. Any pointers to a solution
>> would be appreciated!
>
> Changing .Machine$double.eps does not help to calculate more accurate ...
>
> Uwe Ligges
>
>
>> Cheers,
>> Barry Zajdlik
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Feb 17 09:22:16 2006

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