04-02: Exercises — Measures of Position and Outliers¶
Notes reference: 04-02: Measures of Position and Outliers
Q1: Compare across different scales¶
Two applicants take different aptitude tests.
- Applicant A: score 128 on a test with
μ = 110,σ = 12 - Applicant B: score 74 on a test with
μ = 65,σ = 5
Who performed better relative to their own test?
Solution
z_A = (128 − 110) / 12 = 18 / 12 = +1.50
z_B = ( 74 − 65) / 5 = 9 / 5 = +1.80
Applicant B performed better — 1.80 standard deviations above the mean
versus 1.50 — even though A's raw score is much larger.
Q2: Interpret z-scores¶
A data set has x̄ = 50 and s = 10. Interpret each value.
| Value | z |
Interpretation |
|---|---|---|
| 50 | ? | ? |
| 65 | ? | ? |
| 28 | ? | ? |
| 85 | ? | ? |
Solution
| Value | z |
Interpretation |
|---|---|---|
| 50 | (50−50)/10 = 0.0 |
Exactly at the mean |
| 65 | (65−50)/10 = +1.5 |
1.5 SD above the mean — above average, not unusual |
| 28 | (28−50)/10 = −2.2 |
2.2 SD below the mean — unusual (\|z\| > 2) |
| 85 | (85−50)/10 = +3.5 |
3.5 SD above — very unusual, a likely outlier |
Q3: Percentiles by hand¶
Data: 18, 22, 25, 27, 30, 33, 35, 38, 42, 45, 48, 52 (n = 12, already sorted)
Find P25, P50, and P80 using the textbook c = nk/100 method.
Solution
P25: c = 12 × 25 / 100 = 3 → WHOLE number
P25 = average of positions 3 and 4 = (25 + 27)/2 = 26
P50: c = 12 × 50 / 100 = 6 → WHOLE number
P50 = average of positions 6 and 7 = (33 + 35)/2 = 34 (= the median ✓)
P80: c = 12 × 80 / 100 = 9.6 → NOT whole → round UP to position 10
P80 = 45
Software may report slightly different values because it interpolates. Excel's
PERCENTILE.INC(range, 0.25)gives 26.5 here (h = 0.25 × 11 = 2.75), not 26. Say which method you used.
Q4: Percentile rank¶
Using the Q3 data, find the percentile rank of the value 38.
Solution
Values strictly below 38: 18, 22, 25, 27, 30, 33, 35 → 7 values
7 + 0.5
percentile = ─────────── × 100 = 0.625 × 100 = 62.5th percentile
12
Interpretation: a value of 38 is at roughly the 63rd percentile — about
63% of the data lies at or below it.
Q5: Five-number summary and IQR¶
Data: 14, 19, 23, 25, 28, 31, 34, 38, 41, 47 (n = 10)
Give the five-number summary (Excel QUARTILE.INC method) and the IQR.
Solution
Sorted already. Using the linear-interpolation (INC / R type 7) method:
Min = 14
Q1 h = 0.25 × (10−1) = 2.25 → x[2] + 0.25(x[3] − x[2])
= 23 + 0.25(25 − 23) = 23.5
Median = (28 + 31)/2 = 29.5
Q3 h = 0.75 × 9 = 6.75 → x[6] + 0.75(x[7] − x[6])
= 34 + 0.75(38 − 34) = 37.0
Max = 47
Five-number summary: 14, 23.5, 29.5, 37.0, 47
IQR = 37.0 − 23.5 = 13.5
=MIN(A2:A11) ' 14
=QUARTILE.INC(A2:A11,1) ' 23.5
=MEDIAN(A2:A11) ' 29.5
=QUARTILE.INC(A2:A11,3) ' 37
=MAX(A2:A11) ' 47
=QUARTILE.INC(A2:A11,3)-QUARTILE.INC(A2:A11,1) ' 13.5
Q6: Outlier detection, both rules¶
Data: 22, 24, 25, 27, 28, 30, 31, 33, 35, 89
Apply (a) the 1.5 × IQR rule and (b) the |z| > 3 rule. Do they agree?
Solution
(a) 1.5 × IQR RULE
n = 10, sorted.
Q1 h = 0.25(9) = 2.25 → 25 + 0.25(27−25) = 25.5
Q3 h = 0.75(9) = 6.75 → 31 + 0.75(33−31) = 32.5
IQR = 32.5 − 25.5 = 7.0
Lower fence = 25.5 − 1.5(7.0) = 25.5 − 10.5 = 15.0
Upper fence = 32.5 + 1.5(7.0) = 32.5 + 10.5 = 43.0
89 > 43.0 → 89 IS AN OUTLIER
(89 > 32.5 + 3(7.0) = 53.5, so it is an EXTREME outlier)
(b) Z-SCORE RULE
Σx = 344, x̄ = 34.4
Σ(x−x̄)² = 3460.4 → s² = 3460.4/9 = 384.49, s = 19.608
z = (89 − 34.4) / 19.608 = +2.78
|2.78| < 3 → NOT flagged
THEY DISAGREE — and the IQR rule is right.
The single value 89 inflated s from about 4.3 to about 19.6, so the outlier
hid itself inside its own standard deviation. This MASKING effect is why
the resistant IQR rule is preferred, especially for small samples.
Q1, Q3 = np.percentile(x, [25, 75]); iqr = Q3 - Q1
x[(x < Q1 - 1.5*iqr) | (x > Q3 + 1.5*iqr)] # array([89])
Q7: Handle the outlier¶
You confirm that the 89 in Q6 is a real measurement, not a typo. What do you do?
Solution
1. INVESTIGATE FIRST
- Data entry error? (89 typed for 39?) → check the source record
- Wrong units? (minutes vs. seconds)
- A missing-value code? (89, 99, 999 are common sentinels)
- A different population? (a wholesale order in retail data)
2. IF IT IS GENUINE, DO NOT DELETE IT.
Report BOTH analyses and say what changed:
with 89 without 89
mean 34.4 28.3
median 29.0 28.0 ← barely moves
s 19.6 4.3 ← collapses
IQR 7.0 6.0 ← barely moves
3. PREFER RESISTANT STATISTICS for the headline numbers:
median and IQR instead of mean and s.
4. DOCUMENT the decision in the codebook.
Deleting an inconvenient but genuine observation is data manipulation,
not cleaning.
Q8: Standardize a whole variable¶
Standardize a score column and flag any value beyond ±3.
Solution
=STANDARDIZE(B2, AVERAGE($B$2:$B$501), STDEV.S($B$2:$B$501)) ' C2, fill down
=IF(ABS(C2)>3, "OUTLIER", "") ' D2
=COUNTIF(D2:D501, "OUTLIER") ' how many
df$z <- as.numeric(scale(df$score)) # mean 0, sd 1
mean(df$z); sd(df$z) # ≈ 0 and 1 — a good check
df$flag <- abs(df$z) > 3
subset(df, flag)
from scipy import stats
df["z"] = stats.zscore(df["score"], ddof=1)
df["flag"] = df["z"].abs() > 3
df[df["flag"]]
Sanity check: after standardizing, the mean must be 0 and the SD must be 1. If not, you used the wrong mean or SD (population vs. sample).
⬅️ Previous: 04-01: Exercises — Measures of Variation ➡️ Next: 05-01: Exercises — Probability Basics