Anomaly Formula: Interquartile Range
What it does:
This rule flags anomalies when the latest value falls significantly below or above the typical spread of historical data, defined by the interquartile range (IQR). It compares the latest value to a range bounded by Q1 − T × IQR and Q3 + T × IQR.
When to use it:
Use this when you want to catch values that fall outside of the usual pattern without being affected by extreme outliers. This is great for detecting anomalies in data that may not follow a normal distribution.
Mathematical Formula:
Let:
• L = Latest Value
• H = Historical Values (excluding L)
• Q1 = First Quartile of H
• Q3 = Third Quartile of H
• IQR = Q3 − Q1
• T = Threshold multiplier
Anomaly Condition:
L < Q1 − T × IQR
OR
L > Q3 + T × IQR
Direction Validation (based on Change Type):
• If Change Type = Increased, condition is valid only if L > Q3 + T × IQR
• If Change Type = Decreased, condition is valid only if L < Q1 − T × IQR
• If Change Type = Any, either condition is valid
Outcomes:
❌ Anomaly Detected → Value outside IQR bounds and direction matches Change Type
☑️ Skipped → Value outside IQR bounds but direction does not match Change Type
✅ Normal → Value within IQR bounds
Examples:
Example 1
Change Type: Increased
Threshold: 1.5
History: 100, 105, 110, 120, 130, 140, 150
- If Latest Value = 155
Result: Normal ✅
Explanation:
Q1 = 110, Q3 = 140 → IQR = 30
Upper Bound = 140 + 1.5 × 30 = 185
Latest Value (155) < Upper Bound (185)
- If Latest Value = 200
Result: Anomaly Detected ❌
Explanation:
Upper Bound = 140 + 1.5 × 30 = 185
Latest Value (200) > Upper Bound (185)
- If Latest Value = 95
Result: Skipped ☑️
Explanation:
Lower Bound = 110 − 1.5 × 30 = 65
Latest Value (95) > Lower Bound (65) but direction = Decrease → does not match “Increased”
Example 2
Change Type: Decreased
Threshold: 1.5
History: 80, 85, 90, 95, 100, 105, 110
- If Latest Value = 88
Result: Normal ✅
Explanation:
Q1 = 90, Q3 = 105 → IQR = 15
Lower Bound = 90 − 1.5 × 15 = 67.5
Latest Value (88) > Lower Bound (67.5)
- If Latest Value = 60
Result: Anomaly Detected ❌
Explanation:
Lower Bound = 90 − 1.5 × 15 = 67.5
Latest Value (60) < Lower Bound (67.5)
- If Latest Value = 120
Result: Skipped ☑️
Explanation:
Upper Bound = 105 + 1.5 × 15 = 127.5
Latest Value (120) < Upper Bound (127.5)
But direction = Increase → does not match “Decreased”
Example 3
Change Type: Any
Threshold: 1.5
History: 10, 15, 20, 25, 30, 35, 40
- If Latest Value = 32
Result: Normal ✅
Explanation:
Q1 = 20, Q3 = 35 → IQR = 15
Bounds: [Q1 − 1.5×IQR = −2.5, Q3 + 1.5×IQR = 57.5]
Latest Value (32) within bounds
- If Latest Value = 70
Result: Anomaly Detected ❌
Explanation:
Upper Bound = Q3 + 1.5 × IQR = 35 + 22.5 = 57.5
Latest Value (70) > Upper Bound (57.5) → Outlier