Session Ready
Exercise

Summary statistics: Variance and the standard deviation

In addition to the mean, sometimes you would also like to know about the spread of the distribution. The variance is often taken as a measure of spread of a distribution. It is the squared deviation of an observation from its mean. If you want to calculate it on the basis of a probability distribution, it is the sum of the squared difference between the individual observation and their mean multiplied by their probabilities. See the following formula: \(var(X) = \sum(xi - \bar{x})^2 * Pi(xi)\).

If we want to turn that variance into the standard deviation, all we need to do is to take its square root. Let's go back to our probability mass function of the first exercise and see if we can get the variance.

Instructions
100 XP
  • Calculate the variance of the mass function displayed above and store this in a variable called variance. The mean of probability mass function, displayed as \(\bar{x}\) in the formula, is stored in the variable expected_score. Note that you have a dataframe data available in your console that contains a vector of outcomes called outcome and a vector of probabilities called probs. This dataframe is the exact same as the table displayed above.
  • Calculate the standard deviation of the mass function displayed above and store this in a variable called std.