Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard deviation of one element

When I try to execute

StandardDeviation[{1}]

I get an error

StandardDeviation::shlen: "The argument {1} should have at least two elements"

But std of one element is 0, isn't it?

like image 444
Max Avatar asked Nov 05 '11 22:11

Max


3 Answers

The standard deviation is commonly defined as the square-root of the unbiased estimator of the variance:

enter image description here

You can easily see that for a single sample, N=1 and you get 0/0, which is undefined. Hence your standard deviation is undefined for a single sample in Mathematica.

Now depending on your conventions, you might want to define a standard deviation for a single sample (either return Null or some value or 0). Here's an example that shows you how to define it for a single sample.

std[x_List] := Which[(Length[x] == 1), 0, True, StandardDeviation[x]]
std[{1}]
Out[1]= 0
like image 121
abcd Avatar answered Oct 21 '22 21:10

abcd


The standard deviation of a constant is zero.

The estimated standard deviation of one sample is undefined.

like image 37
Mats Avatar answered Oct 21 '22 19:10

Mats


If you want some formality:

p[x_] := DiracDelta[x - mu];
expValue = Integrate[x p[x] , {x, -Infinity, Infinity}]
stdDev = Sqrt[Integrate[(x - expValue)^2 p[x] , {x, -Infinity, Infinity}]]

(*
-> ConditionalExpression[mu, mu \[Element] Reals]
-> ConditionalExpression[0, mu \[Element] Reals]
*)

Edit

Or better, using Mathematica ProbabilityDistribution[]:

dist = ProbabilityDistribution[DiracDelta[x - mu], {x, -Infinity, Infinity}];
{Mean[dist], StandardDeviation[dist]}

(*
 -> { mu, ConditionalExpression[0, mu \[Element] Reals]}
*)
like image 29
Dr. belisarius Avatar answered Oct 21 '22 20:10

Dr. belisarius