Given a probability distribution over a range of numbers, calculate the standard deviation

I'm struggling with the following problem:

I have a range of numbers (i.e. ages from 5 to 95) and for every of those ages I have a probability (i.e. the probability that a given input has this age).

Let's take an example with ages = [10,11,12,13,14,15] probs = [0.01,0.15,0.68,0.12,0.02,0.02]

I can easily calculate the "expected" age by multiplying the number range with the probabilities.

exp_age = 12.05

However, I want a measure of uncertainty, i.e. the standard deviation of the possible ages.

One way to achieve it is to "construct" a number of 100 observations where for each age, the age occurs 100*its probability. In our above case, that would be 1*10,15*11,68*12,... I can than compute the standard deviation of those observations to get a measure for the uncertainty.

However, with many possible ages this can get quite slow and I am wondering whether there exists a direct numerical solution to my problem.

• Okay, I think I found a proper solution myself: calculate $z = (ages-age_{expected})^2$ then $stdev = \sqrt{\sum{probs * z}}$ Feb 6, 2018 at 10:27
• Yes, this is pretty much how the standard deviation is defined. If you think this answers your question, post it as an answer and accept it, so that others can easily find this information and the question is marked as resolved. Feb 6, 2018 at 11:40

$z = (ages-age_{expected})^2$
Then $stdev = \sqrt{\sum{probs * z}}$