<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Comparing three methods of computing standard deviation</title>
	<atom:link href="http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/</link>
	<description>John D. Cook</description>
	<lastBuildDate>Fri, 24 May 2013 13:46:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Ashwin Jayaprakash</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-45101</link>
		<dc:creator>Ashwin Jayaprakash</dc:creator>
		<pubDate>Tue, 09 Apr 2013 20:41:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-45101</guid>
		<description><![CDATA[Apache Commons Math&#039;s Storeless Variance calculation might need an update.

(http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/stat/descriptive/moment/Variance.html)]]></description>
		<content:encoded><![CDATA[<p>Apache Commons Math&#8217;s Storeless Variance calculation might need an update.</p>
<p>(<a href="http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/stat/descriptive/moment/Variance.html" rel="nofollow">http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/stat/descriptive/moment/Variance.html</a>)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arthur</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15333</link>
		<dc:creator>Arthur</dc:creator>
		<pubDate>Thu, 14 Feb 2013 16:04:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15333</guid>
		<description><![CDATA[Hello,
thank you for that very interesting post, I&#039;m not surprised it is now referenced by a lot of other articles on the web.

I&#039;ve played around with tests similar to yours and I realized that Welford&#039;s algorithm behave differently (and less well) when the samples are sorted.

For instance with 10^6 samples generated from a uniform(0,1) distribution, plus a shift of 10^9, I get 0.08318 with the direct two-pass algorithm and 0.09143 with Welford&#039;s (the correct value being 0.08317).
If I shift the same samples by 10^10, I get 0.084 (direct) and 0.303 (Welford&#039;s), still with sorted samples, so Welford&#039;s one is starting to get really wrong here.

I don&#039;t really know why, and I haven&#039;t spent time trying to understand Welford&#039;s algorithm, but I thought it might be interesting to share.

Arthur]]></description>
		<content:encoded><![CDATA[<p>Hello,<br />
thank you for that very interesting post, I&#8217;m not surprised it is now referenced by a lot of other articles on the web.</p>
<p>I&#8217;ve played around with tests similar to yours and I realized that Welford&#8217;s algorithm behave differently (and less well) when the samples are sorted.</p>
<p>For instance with 10^6 samples generated from a uniform(0,1) distribution, plus a shift of 10^9, I get 0.08318 with the direct two-pass algorithm and 0.09143 with Welford&#8217;s (the correct value being 0.08317).<br />
If I shift the same samples by 10^10, I get 0.084 (direct) and 0.303 (Welford&#8217;s), still with sorted samples, so Welford&#8217;s one is starting to get really wrong here.</p>
<p>I don&#8217;t really know why, and I haven&#8217;t spent time trying to understand Welford&#8217;s algorithm, but I thought it might be interesting to share.</p>
<p>Arthur</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Theoretical explanation for numerical results &#8212; The Endeavour</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15332</link>
		<dc:creator>Theoretical explanation for numerical results &#8212; The Endeavour</dc:creator>
		<pubDate>Mon, 04 Feb 2013 00:21:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15332</guid>
		<description><![CDATA[[...] an earlier post, I compared three methods of computing sample variance. All would give the same result in exact arithmetic, but on a computer they can give very different [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] an earlier post, I compared three methods of computing sample variance. All would give the same result in exact arithmetic, but on a computer they can give very different [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Welford算法-方差计算 - 堂子柯</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15331</link>
		<dc:creator>Welford算法-方差计算 - 堂子柯</dc:creator>
		<pubDate>Sun, 18 Nov 2012 02:57:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15331</guid>
		<description><![CDATA[[...] http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/  Author:zktang &#124; Categories:计算机科学 &#124; Tags: [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/" rel="nofollow">http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/</a>  Author:zktang | Categories:计算机科学 | Tags: [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Wickli</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15330</link>
		<dc:creator>Rick Wickli</dc:creator>
		<pubDate>Wed, 18 Jan 2012 14:24:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15330</guid>
		<description><![CDATA[The Welford (Knuth) method is very nice and can be used to compute a running variance of a time series. A different formula appears in S. Ross, &lt;em&gt;Simulation&lt;/em&gt; (p. 116 of the 2nd edition, Eqns 7.6 and 7.7). At least I think it is different: I haven&#039;t determined been able to derive Ross&#039;s formula from Welford&#039;s.

The interesting thing about the Ross formula is that you can use it to create a &lt;em&gt;vectorized&lt;/em&gt; computation that can compute the running variance of a time series in a single operation (no loops) in languages such as R, MATLAB, and SAS/IML.  Ross&#039;s formula and the vectorized computation are both presented and discussed in a blog post:
&quot;&lt;a href=&quot;http://blogs.sas.com/content/iml/2012/01/18/compute-a-running-mean-and-variance/&quot; rel=&quot;nofollow&quot;&gt;Compute a running mean and variance&lt;/a&gt;.&quot;]]></description>
		<content:encoded><![CDATA[<p>The Welford (Knuth) method is very nice and can be used to compute a running variance of a time series. A different formula appears in S. Ross, <em>Simulation</em> (p. 116 of the 2nd edition, Eqns 7.6 and 7.7). At least I think it is different: I haven&#8217;t determined been able to derive Ross&#8217;s formula from Welford&#8217;s.</p>
<p>The interesting thing about the Ross formula is that you can use it to create a <em>vectorized</em> computation that can compute the running variance of a time series in a single operation (no loops) in languages such as R, MATLAB, and SAS/IML.  Ross&#8217;s formula and the vectorized computation are both presented and discussed in a blog post:<br />
&#8220;<a href="http://blogs.sas.com/content/iml/2012/01/18/compute-a-running-mean-and-variance/" rel="nofollow">Compute a running mean and variance</a>.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Welford&#8217;s method for calculating the sample variance: An implementation in Scheme &#124; Left Censored</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15329</link>
		<dc:creator>Welford&#8217;s method for calculating the sample variance: An implementation in Scheme &#124; Left Censored</dc:creator>
		<pubDate>Sat, 17 Dec 2011 16:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15329</guid>
		<description><![CDATA[[...] using the mathematical textbook definitions. He provides a Monte Carlo comparison of methods here, and a theoretical discussion here. He has also provides a C++ implementation of Welford&#8217;s [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] using the mathematical textbook definitions. He provides a Monte Carlo comparison of methods here, and a theoretical discussion here. He has also provides a C++ implementation of Welford&#8217;s [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Top 50 Statistics Blogs of 2011</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15328</link>
		<dc:creator>Top 50 Statistics Blogs of 2011</dc:creator>
		<pubDate>Fri, 07 Oct 2011 19:52:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15328</guid>
		<description><![CDATA[[...] The Endeavour A blog by John. D Cook, statistician, mathematician, consultant, manager and professor. While not all posts are directly concerned with statistics, they are all typically engaging and worthwhile. Warm up with &#8220;Wine, Beer and Statistics&#8221; before moving on to &#8220;Comparing Three Methods of Computing Standard Deviation&#8221;. [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] The Endeavour A blog by John. D Cook, statistician, mathematician, consultant, manager and professor. While not all posts are directly concerned with statistics, they are all typically engaging and worthwhile. Warm up with &#8220;Wine, Beer and Statistics&#8221; before moving on to &#8220;Comparing Three Methods of Computing Standard Deviation&#8221;. [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: keith allpress</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15327</link>
		<dc:creator>keith allpress</dc:creator>
		<pubDate>Sat, 27 Aug 2011 00:00:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15327</guid>
		<description><![CDATA[Hi Jaime
Yes you are correct, you can implement statistical analysers that have no memory requirements apart from a small number of state variables. Great for time series like stock market.  Totally cool.  This whole field leads into something called &quot;optimal estimation theory&quot;. The most famous algorithm is prhaps the Kalman Filter, you want to rapidly predict the best path of a missile in real time as accurately and rapidly as possible, so you don&#039;t under-correct or over correct the mean. I recall a back issue of Byte magazine discussing this way back in the 80&#039;s implemented on an HP programmable calculator. I wrote a version in BASIC but you dont need to be a code monkey, a spreadsheet will do it.
Keith]]></description>
		<content:encoded><![CDATA[<p>Hi Jaime<br />
Yes you are correct, you can implement statistical analysers that have no memory requirements apart from a small number of state variables. Great for time series like stock market.  Totally cool.  This whole field leads into something called &#8220;optimal estimation theory&#8221;. The most famous algorithm is prhaps the Kalman Filter, you want to rapidly predict the best path of a missile in real time as accurately and rapidly as possible, so you don&#8217;t under-correct or over correct the mean. I recall a back issue of Byte magazine discussing this way back in the 80&#8242;s implemented on an HP programmable calculator. I wrote a version in BASIC but you dont need to be a code monkey, a spreadsheet will do it.<br />
Keith</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Running Variance &#124; TaylorTree</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15326</link>
		<dc:creator>Running Variance &#124; TaylorTree</dc:creator>
		<pubDate>Thu, 25 Nov 2010 23:55:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15326</guid>
		<description><![CDATA[[...] Comparing three methods of computing standard deviation [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] Comparing three methods of computing standard deviation [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sesqu</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15325</link>
		<dc:creator>sesqu</dc:creator>
		<pubDate>Tue, 15 Jun 2010 08:06:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15325</guid>
		<description><![CDATA[How did you compute the sample mean in the direct method? sum x[i]/n, (sum x[i])/n, welford&#039;s method, or some iterative offset? Since the direct method outperformed welford&#039;s for small offsets, I wouldn&#039;t be entirely surprised to find out it was because the mean was inaccurate at large offsets.]]></description>
		<content:encoded><![CDATA[<p>How did you compute the sample mean in the direct method? sum x[i]/n, (sum x[i])/n, welford&#8217;s method, or some iterative offset? Since the direct method outperformed welford&#8217;s for small offsets, I wouldn&#8217;t be entirely surprised to find out it was because the mean was inaccurate at large offsets.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shootout between SQL Server, Matlab and C# on Standard Deviation (STDEV) &#8211; Cheesy Code</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15324</link>
		<dc:creator>Shootout between SQL Server, Matlab and C# on Standard Deviation (STDEV) &#8211; Cheesy Code</dc:creator>
		<pubDate>Tue, 13 Apr 2010 17:10:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15324</guid>
		<description><![CDATA[[...] Note that while STDEVP might seem like an easy enough algorithm, there are several ways to implement it and each, due to floating point precision, will give different answers. For my C# implementation I&#8217;ve used the Welford algorithm as described on Wikipedia under Rapid calculation methods. You might also be interested in this blog post: Comparing three methods of computing standard deviation. [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] Note that while STDEVP might seem like an easy enough algorithm, there are several ways to implement it and each, due to floating point precision, will give different answers. For my C# implementation I&#8217;ve used the Welford algorithm as described on Wikipedia under Rapid calculation methods. You might also be interested in this blog post: Comparing three methods of computing standard deviation. [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaime</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15323</link>
		<dc:creator>Jaime</dc:creator>
		<pubDate>Fri, 22 May 2009 12:02:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15323</guid>
		<description><![CDATA[John,

This has to be one of the coolest algorithms ever!!! I need to work out the math, but it seems that it should also be possible to keep a running mean and variance while removing data. Wouldn&#039;t that allow to do real-time elimination of outliers, and give a more accurate running average of the data stream?

I&#039;m thinking of stuff like a bicycle&#039;s speed&#039;o&#039;meter, or a heart rate monitor: along your ride or run the sensor moves, or something odd happens, and suddenly the readings drop to zero, or double... Maybe hardware is better now, but that used to happen very often when I did triathlons, some five years ago. Even if it ony lasts for a short while, it may mess your average readings big time, which may be the thing you wanted to base your day&#039;s training on.

I&#039;ll try to elaborate more on the idea, but meanwhile cast the question to ye, the statisticians: is there any fundamental theoretical flaw in the above idea?]]></description>
		<content:encoded><![CDATA[<p>John,</p>
<p>This has to be one of the coolest algorithms ever!!! I need to work out the math, but it seems that it should also be possible to keep a running mean and variance while removing data. Wouldn&#8217;t that allow to do real-time elimination of outliers, and give a more accurate running average of the data stream?</p>
<p>I&#8217;m thinking of stuff like a bicycle&#8217;s speed&#8217;o'meter, or a heart rate monitor: along your ride or run the sensor moves, or something odd happens, and suddenly the readings drop to zero, or double&#8230; Maybe hardware is better now, but that used to happen very often when I did triathlons, some five years ago. Even if it ony lasts for a short while, it may mess your average readings big time, which may be the thing you wanted to base your day&#8217;s training on.</p>
<p>I&#8217;ll try to elaborate more on the idea, but meanwhile cast the question to ye, the statisticians: is there any fundamental theoretical flaw in the above idea?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The 41st Carnival of Mathematics &#171; 360</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15322</link>
		<dc:creator>The 41st Carnival of Mathematics &#171; 360</dc:creator>
		<pubDate>Sat, 11 Oct 2008 13:30:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15322</guid>
		<description><![CDATA[[...] the error in the central limit theorem, and how close an approximation we can really get. He also compares three methods of computing standard deviation - turns out they&#8217;re not all equally [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] the error in the central limit theorem, and how close an approximation we can really get. He also compares three methods of computing standard deviation &#8211; turns out they&#8217;re not all equally [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15321</link>
		<dc:creator>John</dc:creator>
		<pubDate>Wed, 01 Oct 2008 21:30:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15321</guid>
		<description><![CDATA[I understand what you&#039;re saying.  The way I think about is is that the y&#039;s are raw data. They happen to have been generated by this N + uniform process, but you could ignore that. Given the y&#039;s, to the precision we have them, go find their sample variance.]]></description>
		<content:encoded><![CDATA[<p>I understand what you&#8217;re saying.  The way I think about is is that the y&#8217;s are raw data. They happen to have been generated by this N + uniform process, but you could ignore that. Given the y&#8217;s, to the precision we have them, go find their sample variance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EastwoodDC</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15320</link>
		<dc:creator>EastwoodDC</dc:creator>
		<pubDate>Wed, 01 Oct 2008 21:21:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15320</guid>
		<description><![CDATA[Another thought: In your example here you are adding a large constant to demonstrate the inaccuracy of the sum of squares method. Isn&#039;t there also an issue here of the accuracy of the internal binary representation (mantissa) of the number? By adding 10^12 to a value between 0 and 1, you are increasing the mantissa by 12 digits (something else in binary), and likely causing the less significant ones to be truncated in the internal representation. This could also cause different results for the variance because the data may be inaccurately represented in the first place. (Did that make any sense? Forgive me but I&#039;ve been away from this sort of thing for a long time).
This seems to be another reason why Welford&#039;s method is superior.]]></description>
		<content:encoded><![CDATA[<p>Another thought: In your example here you are adding a large constant to demonstrate the inaccuracy of the sum of squares method. Isn&#8217;t there also an issue here of the accuracy of the internal binary representation (mantissa) of the number? By adding 10^12 to a value between 0 and 1, you are increasing the mantissa by 12 digits (something else in binary), and likely causing the less significant ones to be truncated in the internal representation. This could also cause different results for the variance because the data may be inaccurately represented in the first place. (Did that make any sense? Forgive me but I&#8217;ve been away from this sort of thing for a long time).<br />
This seems to be another reason why Welford&#8217;s method is superior.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15319</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Sun, 28 Sep 2008 16:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15319</guid>
		<description><![CDATA[I&#039;ll second that. Nice work!]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ll second that. Nice work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gene</title>
		<link>http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/comment-page-1/#comment-15318</link>
		<dc:creator>Gene</dc:creator>
		<pubDate>Sat, 27 Sep 2008 14:35:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=449#comment-15318</guid>
		<description><![CDATA[Welford&#039;s method corresponds closely to a similar calculation for Pearson&#039;s correlation coefficient that is accomplished in a single pass.
http://en.wikipedia.org/wiki/Correlation

Single pass computations that are numerically stable become important when thousands of combinations of overdetermined systems must be correlated and decomposed. The computational overhead of two pass algorithms becomes prohibitive with such problems.

Thanks for pointing out your tests on these methods.]]></description>
		<content:encoded><![CDATA[<p>Welford&#8217;s method corresponds closely to a similar calculation for Pearson&#8217;s correlation coefficient that is accomplished in a single pass.<br />
<a href="http://en.wikipedia.org/wiki/Correlation" rel="nofollow">http://en.wikipedia.org/wiki/Correlation</a></p>
<p>Single pass computations that are numerically stable become important when thousands of combinations of overdetermined systems must be correlated and decomposed. The computational overhead of two pass algorithms becomes prohibitive with such problems.</p>
<p>Thanks for pointing out your tests on these methods.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
