Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 ?

share|improve this question
    
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. –  Rahul Narain Mar 4 at 6:55
    
@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. –  newbie Mar 4 at 7:31
add comment

1 Answer 1

up vote 1 down vote accepted

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 *)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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