8

I have several weighted values for which I am taking a weighted average. I want to calculate a weighted standard deviation using the weighted values and weighted average. How would I modify the typical standard deviation to include weights on each measurement?

This is the standard deviation formula I am using.

enter image description here

When I simply use each weighted value for 'x' and the weighted average for '\bar{x}', the result seems smaller than it should be.

Steven C. Howell
  • 16,902
  • 15
  • 72
  • 97
  • How is this question related to this site? Isn't this belongs to [Mathematics SE](http://math.stackexchange.com/) – David Arenburg May 21 '15 at 22:00
  • 1
    @DavidArenburg This is something I am trying to program and likely others have/will also use in the future. I just added more to the answer I posted to identify how to efficiently code this. – Steven C. Howell May 21 '15 at 22:29

1 Answers1

13

I just found this wikipedia page discussing data of equal significance vs weighted data. The correct way to calculate the biased weighted estimator of variance is

,

though the following, on-the-fly implementation, is more efficient computationally as it does not require calculating the weighted average before looping over the sum on the weighted differences squared

.

Despite my skepticism, I tried both and got the exact same results.

Note, be sure to use the weighted average

.

Steven C. Howell
  • 16,902
  • 15
  • 72
  • 97
  • 1
    Note that the mean is also calculated using the weights (i.e. be careful to use the weighted mean in that formula, not the usual unweighted mean). – Robert Dodier May 21 '15 at 21:24
  • @RobertDodier good point. I did not make that explicit but I will for completeness sake. – Steven C. Howell May 21 '15 at 23:26
  • 1
    That last sentence should say "weighted mean", not "weighted error", right? I suppose the weighted error would be the difference between x_i and this value. – akavalar Sep 14 '17 at 03:15