﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by jkelly  / Standard Deviation  / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 07:31:30 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Thanks for clarifying this. As I said it has been a while since I used statistics :-)</description><pubDate>Mon, 17 Sep 2012 08:03:49 GMT</pubDate><dc:creator>mdv 9731</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]mdv 9731 (1/28/2011)[/b][hr]I do not agree that the answer is right. Think it is supposed to be 0.the standard deviation σ (sigma) is the square root of the average value of (X − μ)2.Which means σ = sqrt(((1-1)^2)/1) = 0Or in other words std. deviation equals sqrt of (population-avarage) sq / number of population valuesPlease correct me if im wrong on the formula it has been a while since i used my statistics :-D[/quote]What you state is correct for a population standard deviation. Then you devide by the number of samples N, which is one for a single record. You do this with the function STDEVP. When using STDEV however, you take the sample standard deviation in which you devide by N - 1 which would result in a division by zero. Hence the NULL. SELECT STDEV(100)Results in NULLSELECT STDEVP(100)Results in 0See: http://en.wikipedia.org/wiki/Standard_deviation</description><pubDate>Mon, 17 Sep 2012 07:37:56 GMT</pubDate><dc:creator>Ron Deijkers</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Thanks for the question</description><pubDate>Tue, 08 Feb 2011 12:15:04 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Thanks for the question. I learn new thing today. Discussion about the topic is really good...</description><pubDate>Mon, 07 Feb 2011 04:35:17 GMT</pubDate><dc:creator>Hardy21</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Simple Question but discussion was so detailed that you learn a loads of thing from the discussion :-D</description><pubDate>Fri, 28 Jan 2011 19:40:33 GMT</pubDate><dc:creator>Dhruvesh Shah</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Hi Tom, I see that we are on the same page. The only way I can make sense of Microsoft's nomenclature is to remember that I should use STDEVP when I'm applying the function to a data set to calculate the standard deviation of only those data points (i.e., when I'm feeding the function the whole population and not a sample), hence my reliance on the "P for population"  mnemonic device, and STDEV when I'm applying the function to a data set that serves as a sample of some larger data set for which I want to estimate the standard deviation. Otherwise, I go crazy trying to remember whether I should be using the "n" or the "n-1" method and which function goes with which!Jason</description><pubDate>Fri, 28 Jan 2011 15:13:00 GMT</pubDate><dc:creator>wolfkillj</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]wolfkillj (1/28/2011)[/b][hr]I think the "P" in STDEVP does stand for "population", as that function returns the actual standard deviation of the entire population (sometimes called the "n" method); hence, the standard deviation of a population consisting of a single value = 0, as STDEVP will return. STDEV returns the standard deviation with Bessel's correction applied (i.e., the estimated population standard deviation or the sample standard deviation, sometimes call the "n-1" method), which is why applying this function to a population consisting of a single value will not work. Can anyone who knows the programmatic bases of STDEV and STDEVP confirm my conclusion?[/quote]Up to a point you are right (certainly the code bases are the way round that you suggest), but STDEVP returns the standard deviation of the sample provided to it, not that of the population from which the sample is drawn.  I guess that what's happened is that someone chose the name STDEVP to mean a version of STDEV to which the whole population was provided, rather than a sample, and that's why the code without Bessel's correction has the P in its name. But many statisticians (and other mathematicians) talk about the standard deviation of the sample and the estimated standard deviation of the population, and (at least for distributions thought to be close to normal) instead of using the standard deviation of the sample as an estimate for the population SD they multiply it by N/(N-1) (Bessel's correction) to get a better estimate (or more usually shortcircuit that by dividing by N-1 instead of by N in the first place), so in the usual terminology the population is ony referred to in the corrected case, not in the uncorrected case, so people may be confused by the naming with P included in the name that doesn't try to provide the population (as opposed to sample) standard deviation (as I was).edit: take out superfluous quote tag</description><pubDate>Fri, 28 Jan 2011 14:51:47 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote]I thought the P in STDEVP stood for "Population", so STDEVP would be the estimated Population Standard Deviation (obtained by applying Bessel's correction to the actual Sample Standard Deviation) and STDEV the actual Sample Standard Deviation (in the SQL 2000 days you could look it up in BoL, so I never bothered to learn it - I wanted those functions rarely enough for it not to be worth making an effort to learn it); when I discovered that which is which isn't documented (at least not in any obvious manner) in BoL for SQL 2008 I just tried to work out which was which based on the name, and got it wrong because the SQL function names are misleading.[/quote]I think the "P" in STDEVP does stand for "population", as that function returns the actual standard deviation of the entire population (sometimes called the "n" method); hence, the standard deviation of a population consisting of a single value = 0, as STDEVP will return. STDEV returns the standard deviation with Bessel's correction applied (i.e., the estimated population standard deviation or the sample standard deviation, sometimes call the "n-1" method), which is why applying this function to a population consisting of a single value will not work. Can anyone who knows the programmatic bases of STDEV and STDEVP confirm my conclusion?</description><pubDate>Fri, 28 Jan 2011 14:22:09 GMT</pubDate><dc:creator>wolfkillj</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Well I got this one wrong, mainly because the SQL function naming is a little bizarre:  STDEV is the estimated Population Standard Deviation (although there's no P in the name)STDEVP is the actual Sample Standard Deviation (although there is a P in the name)I thought the P in STDEVP stood for "Population", so STDEVP would be the estimated Population Standard Deviation (obtained by applying Bessel's correction to the actual Sample Standard Deviation) and STDEV the actual Sample Standard Deviation (in the SQL 2000 days you could look it up in BoL, so I never bothered to learn it - I wanted those functions rarely enough for it not to be worth making an effort to learn it); when I discovered that which is which isn't documented (at least not in any obvious manner) in BoL for SQL 2008 I just tried to work out which was which based on the name, and got it wrong because the SQL function names are misleading.You can't apply Bessel's correction when your sample has only 1 member, so SQL Server quite correctly refuses to attempt it.  Actually it would be better to return an appropriate error (one that specifically means that STDEV has been applied to a singleton sample) than to return NULL. Returning NULL is better than returning a zero-divide error which might be caused by some other part of a select statement - eg if [code]SELECT STDEV((a+c)/b) FROM T where a &amp;gt; 37 [/code]returned a zero-divide error one couldn't tell whether the error occurred because one of the b attributes was zero or because there was at most one row with a &amp;gt; 37.  But returning NULL means you don't know whether the sample was empty or a singleton, which is why a specific error should be returned (ideally a specific error should be returned instead of NULL for the empty sample case too, but that is another story, part of a much more general one).</description><pubDate>Fri, 28 Jan 2011 14:01:51 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Thanks for the explanation wolfkillj! That makes total sense now.</description><pubDate>Fri, 28 Jan 2011 10:24:50 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>What's going on here is that the STDEV() function in T-SQL returns the sample standard deviation (which for a single value will be undefined, hence the programmatically dictated NULL result) rather than the population standard deviation (which for a single value will be 0). BOL does not clearly state this, which apparently causes some confusion. Another T-SQL function, STDEVP(), returns the population standard deviation. Developers using statistical functions in T-SQL definitely should be aware of this!</description><pubDate>Fri, 28 Jan 2011 10:12:25 GMT</pubDate><dc:creator>wolfkillj</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Thanks for the question, it is good to know that SQL Server decides to return NULL for the standard deviation for a data value, though I don't think it is alone.</description><pubDate>Fri, 28 Jan 2011 10:11:56 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Right answer, wrong explanation. The stdev function is simply programmed to return null when the sample size is less than 2. It has nothing to do with division by zero. Division by zero is an invalid calculation not an unknown result. If it were allowed to perform the zero division the proper response of the function should have been to throw an error; instead they trapped the invalid condition and returned a NULL. I would also argue that this is an inaccurate result since it ignores the fact that an invalid data set is being used without returning the appropriate error.</description><pubDate>Fri, 28 Jan 2011 07:24:23 GMT</pubDate><dc:creator>Barry McConnell</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Division by zero should be ERROR, not null. How come?</description><pubDate>Fri, 28 Jan 2011 06:13:39 GMT</pubDate><dc:creator>valeryk2000</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>That makes sence.So its really a matter of SQL Server returning NULL instead of #ERROR not having the correct syntax which obviously means that a FROM clause needs to be included.So the point proven is more like SQL Server returning a 'value' instead of an error.And not that it can't calculate :-) (and is has nothing to do with a zero division)'cause my point was that std. dev. is 0 if calculated on a single value no matter what it is (even if that makes no sence)Question good, formula good, Microsoft needs to work on documentationWe're all happyCheers</description><pubDate>Fri, 28 Jan 2011 03:57:47 GMT</pubDate><dc:creator>mdv 9731</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]sharath.chalamgari (1/28/2011)[/b][hr][quote][b]Koen (da-zero) (1/28/2011)[/b]Then why is the explanation confusing? I find it pretty clear...[/quote]It is Confusing because in his Query the parameter 1 does not mean that Number of samples.if you put 100 inplace of 1 still it gives the same null. as per his explanation it is not a divide by zero errorThe usage of the Function is wrong in the Query.see if we can use some thing like below it gives 0[code="sql"]SELECT STDEV(1) from sys.objects[/code][/quote]Allright, that makes sense. Thanks for the explanation.</description><pubDate>Fri, 28 Jan 2011 03:48:15 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]Koen (da-zero) (1/28/2011)[/b]Then why is the explanation confusing? I find it pretty clear...[/quote]It is Confusing because in his Query the parameter 1 does not mean that Number of samples.if you put 100 inplace of 1 still it gives the same null. as per his explanation it is not a divide by zero errorThe usage of the Function is wrong in the Query.see if we can use some thing like below it gives 0[code="sql"]SELECT STDEV(1) from sys.objects[/code]</description><pubDate>Fri, 28 Jan 2011 03:41:27 GMT</pubDate><dc:creator>sharath.chalamgari</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]mdv 9731 (1/28/2011)[/b][hr]I'm not really going to comment on that answer.Just happy you are not creating any kind of BI og reporting in our company :-)I might be wrong but i still question the result. Even if i know that it doesnt make much practical sence to talk deviation on 1 value.[/quote]The question was about the result of the query (ergo: what does SQL Server do with it).Not what is the theoretical result according to statistics. (however, the explanation might be lacking. I'm (luckily) not a statistician)But don't worry, if I'll do BI or reporting in your company, I will read the requirements thoroughly ;-)</description><pubDate>Fri, 28 Jan 2011 03:17:11 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]Koen (da-zero) (1/28/2011)[/b][hr]Then why is the explanation confusing? I find it pretty clear...[/quote]The explanation is "The denominator of the variance for a sample population is n - 1, resulting in division by zero."This suggests it should give an error, and doesn't explain why it results in null instead.I guessed wrong, but I'm not sure what the question was supposed to prove, other than if you apply a function wrongly then you get a meaningless answer!</description><pubDate>Fri, 28 Jan 2011 03:01:59 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>I'm not really going to comment on that answer.Just happy you are not creating any kind of BI og reporting in our company :-)I might be wrong but i still question the result. Even if i know that it doesnt make much practical sence to talk deviation on 1 value.</description><pubDate>Fri, 28 Jan 2011 02:50:25 GMT</pubDate><dc:creator>mdv 9731</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]mdv 9731 (1/28/2011)[/b][hr]I do not agree that the answer is right. Think it is supposed to be 0.the standard deviation σ (sigma) is the square root of the average value of (X − μ)2.Which means σ = sqrt(((1-1)^2)/1) = 0Or in other words std. deviation equals sqrt of (population-avarage) sq / number of population valuesPlease correct me if im wrong on the formula it has been a while since i used my statistics :-D[/quote]Even if your statistics say it is 0, SQL Server returns NULL, so the answer is still correct.You can verify it by running the query in SQL Server Management Studio.</description><pubDate>Fri, 28 Jan 2011 02:34:17 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>I do not agree that the answer is right. Think it is supposed to be 0.the standard deviation σ (sigma) is the square root of the average value of (X − μ)2.Which means σ = sqrt(((1-1)^2)/1) = 0Or in other words std. deviation equals sqrt of (population-avarage) sq / number of population valuesPlease correct me if im wrong on the formula it has been a while since i used my statistics :-D</description><pubDate>Fri, 28 Jan 2011 02:09:54 GMT</pubDate><dc:creator>mdv 9731</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Thanks for introducing new topic. I had not heard about it before</description><pubDate>Fri, 28 Jan 2011 02:01:02 GMT</pubDate><dc:creator>mohammed moinudheen</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]sharath.chalamgari (1/28/2011)[/b][hr][quote][b]Koen (da-zero) (1/28/2011)[/b][hr][quote][b]sharath.chalamgari (1/28/2011)[/b][hr]but if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value[code="sql"]select stdev(pa_Rates) From Package where pa_PackageID = 1[/code][/quote]The WHERE clause is executed first, so you are still calculating the variance over 1 row, hence the NULL.[/quote]Ya that's what i have explained above.[/quote]Then why is the explanation confusing? I find it pretty clear...</description><pubDate>Fri, 28 Jan 2011 01:50:49 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]Koen (da-zero) (1/28/2011)[/b][hr][quote][b]sharath.chalamgari (1/28/2011)[/b][hr]but if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value[code="sql"]select stdev(pa_Rates) From Package where pa_PackageID = 1[/code][/quote]The WHERE clause is executed first, so you are still calculating the variance over 1 row, hence the NULL.[/quote]Ya that's what i have explained above.</description><pubDate>Fri, 28 Jan 2011 01:45:26 GMT</pubDate><dc:creator>sharath.chalamgari</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>[quote][b]sharath.chalamgari (1/28/2011)[/b][hr]but if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value[code="sql"]select stdev(pa_Rates) From Package where pa_PackageID = 1[/code][/quote]The WHERE clause is executed first, so you are still calculating the variance over 1 row, hence the NULL.</description><pubDate>Fri, 28 Jan 2011 01:34:06 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>I think the Explanation is bit confusing.if you give any numeric value to the function without any from clause it will give NULL.[code="sql"]SELECT STDEV(100)[/code]"The STDEV function uses all of the values to calculate the standard deviation. There must be at least two values in the field or the standard deviation will not be calculated and a NULL is returned."example in my PackageTable  the standard deveation of pa_rates column can find using [code="sql"]select stdev(pa_Rates) From Package[/code]for the above Query i will get some resultbut if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value[code="sql"]select stdev(pa_Rates) From Package where pa_PackageID = 1[/code]</description><pubDate>Fri, 28 Jan 2011 01:24:38 GMT</pubDate><dc:creator>sharath.chalamgari</dc:creator></item><item><title>RE: Standard Deviation</title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Nice question, really learned something.The BOL page doesn't even mention this subject.</description><pubDate>Fri, 28 Jan 2011 00:08:39 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>Standard Deviation </title><link>http://www.sqlservercentral.com/Forums/Topic1055069-2898-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/72155/"&gt;Standard Deviation &lt;/A&gt;[/B]</description><pubDate>Thu, 27 Jan 2011 21:42:36 GMT</pubDate><dc:creator>jkelly</dc:creator></item></channel></rss>