When applying variance (Variance[10]) or standard deviation (StandardDeviation[10]) to a constant value in Mathematica, Should the return be zero ?

What I get from StandardDeviation[10] is the error saying that standardDeviation::rectt: Rectangular array expected at position 1 in StandardDeviation[10].

How do I fix it ?

  • $\begingroup$ For one thing, Variance expects a list, so you'd need to do Variance[{10}] instead. But for another thing, Variance returns the sample variance, with $n-1$ in the denominator, so the variance of a sample of length $n=1$ is not defined at all. $\endgroup$ – user484 Mar 4 '14 at 6:55
  • $\begingroup$ @RahulNarain I guess the way to fix it is to replicate 10 so that I will have a list of {10,10}. Then, applying Variance[{10,10}] returns me 0. $\endgroup$ – newbie Mar 4 '14 at 7:31

As mentioned, a list of one single item has no sample variance but it does have a population variance. The population variance has to be defined, though :

PopulationVariance[list_] := Mean[(list - Mean[list])^2];
PopulationVariance[{10}] (* 0 *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.