Skip to content
Back to formatted view

Raw Message

Message-ID: <D9DA0EA0-018A-403C-91B4-C00063290756@gmail.com>
Date: 2011-12-08T14:20:50Z
From: michael.weylandt at gmail.com (R. Michael Weylandt
Subject: sum of deviations from the weighted mean
In-Reply-To: <CABcwgRS0S2=w3aKmC=sob2MVzVyura=4bt0JGFaGDt9eCmUWLQ@mail.gmail.com>

R FAQ 7.31 I'd imagine. (Floating point arithmetic and limitations thereof)

Michael

On Dec 8, 2011, at 9:15 AM, andrija djurovic <djandrija at gmail.com> wrote:

> Hi all. I tried to calculate sum of deviations from the weighted mean and i
> didn't get what i expected - 0. Here is an example:
> 
>> wt <- c(10,25,38,22,5)
>> x <- 6:10
>> wm <- weighted.mean(x,wt)
>> (x-wm)*wt
> [1] -18.70 -21.75   4.94  24.86  10.65
>> sum((x-wm)*wt)
> [1] -1.24345e-14
> 
> With simple mean I got 0:
>> sum(x-mean(x))
> [1] 0
> 
> Could someone explain me why we didn't get 0, with weighted mean, as it is
> expected?
> Thanks in advance
> 
> Andrija
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.