Sub topic 2
Weighted averages and finding a missing value
This chapter assumes you can compute fractions, decimals, and negative numbers, solve a linear equation, and take square roots. The Python snippets use only the standard math module.
Weighted averages and finding a missing value
A weighted average gives each value a share based on how often it occurs or how large its group is. If one group of 10 people averages 70 and another group of 30 people averages 90, the combined average is not 80. It is the total score divided by the total count:
(10 × 70 + 30 × 90) / 40 = 85
To find a missing value, multiply the known average by the count to get the total, then subtract the known values. Four scores average 75, and three of them are 70, 80, and 90. The total is 4 × 75 = 300. The known values sum to 240, so the missing score is 60.
Deviations from the mean
A deviation is how far one value sits from the mean: value minus mean. For the data set 2, 4, 4, 4, 5, 5, 7, 9, the mean is 5, so the deviations are −3, −1, −1, −1, 0, 0, 2, and 4. Their sum is always 0, which is why you square them before averaging.
Standard deviation step by step
Follow these steps:
- Find the mean.
- Find each deviation.
- Square each deviation.
- Average the squares. This is the variance.
- Take the square root of the variance.
For the data above, the squares sum to 32. Dividing by 8 gives a variance of 4, so the standard deviation is 2.
import math
# Weighted average: 10 people average 70, 30 people average 90
combined = (10 * 70 + 30 * 90) / (10 + 30)
print(combined) # 85.0
# Missing value: four scores average 75, three are known
known = [70, 80, 90]
missing = 4 * 75 - sum(known)
print(missing) # 60
# Standard deviation, step by step
data = [2, 4, 4, 4, 5, 5, 7, 9]
mean = sum(data) / len(data)
deviations = [x - mean for x in data]
variance = sum(d ** 2 for d in deviations) / len(data)
print(math.sqrt(variance)) # 2.0> Note: The chapter uses the population form, which divides by n.
Comparing spread without calculating
You can often rank standard deviations without computing them. When two sets share a mean, the set whose values sit farther from that mean has the larger standard deviation. Both {4, 5, 6} and {1, 5, 9} have mean 5, but the second set's values are farther from 5, so its standard deviation is larger.
Exercise
Four numbers have a mean of 20. Three of them are 15, 22, and 25. What is the fourth number?
Show answer
The total is 4 × 20 = 80. The three known values sum to 62. The fourth number is 80 − 62 = 18.