8.1 Expected Values and Standard Deviations
If the probability distribution of the random variable is given by , then:
- The expected value of a random variable X is given by
- The standard deviation of the random variable X is given by
Syntax for expected value
import numpy as np
np.average(x, weights=prob)
Syntax for population standard deviation
import numpy as np
np.sqrt(np.cov(x, aweights=prob, ddof=0))
Example: The number of electronic devices per household in a neighborhood and their corresponding probabilities are given on the table below. Find the expected value and standard deviation of the number of devices per household in this neighborhood.
| x | p(x) |
|---|---|
| 0 | .01 |
| 1 | .02 |
| 2 | .13 |
| 3 | .33 |
| 4 | .51 |
import numpy as np
x = [0,1,2,3,4]
prob = [.01,.02,.13,.33,.51]
expected_value = np.average(x,weights=prob)
expected_value
Show expected output
3.31Interpretation: The mean number of electronic devices per household is 3.31.
import numpy as np
x = [0,1,2,3,4]
prob = [.01,.02,.13,.33,.51]
standard_deviation = np.sqrt(np.cov(x, aweights=prob, ddof=0))
standard_deviation
Show expected output
0.8449260322655469Interpretation: The mean number of electronic devices per household is 3.31 with a standard deviation of 0.845.
Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.