Anomaly Formula: Modified Z-Score

What it does:

This formula measures how far the latest value deviates from the median of historical values, scaled by the median absolute deviation (MAD). It’s more robust than the standard Z-Score when your data has outliers.

 

When to use it:

Use this when your historical usage has occasional extreme values that might distort averages. Modified Z-Score provides a more stable baseline in such cases.

 


Mathematical Formula:

 

Let:

• L = Latest Value
 H = Historical Values (excluding L)
 M = Median of H
• MAD = Median Absolute Deviation of H
• Zₘ = Modified Z-Score
 T = Threshold
• Zₘ = 0.6745 × (L − M) / MAD

 

Anomaly Condition:

|Zₘ| ≥ T

 

Direction Validation (based on Change Type):

• If Change Type = Increased, condition is valid only if  L > M
• If Change Type = Decreased, condition is valid only if  L < M
• If Change Type = Any, direction check is not required

 

Outcomes:

❌ Anomaly Detected → |Zₘ| ≥ T and direction matches Change Type
☑️ Skipped → |Zₘ| ≥ T but direction does not match Change Type
✅ Normal → |Zₘ| < T

 


Examples:

 

Example 1

Change Type: Increased
Threshold: 3.5
History: 100, 102, 98, 101

 

  • If Latest Value = 104
    Result: Normal ✅
    Explanation:
      M = 100.5, MAD = 1
      Zₘ = 0.6745 × (104 − 100.5) / 1 = 2.36
      |Zₘ| = 2.36 < Threshold (3.5)

 

  • If Latest Value = 110
    Result: Anomaly Detected ❌
    Explanation:
      M = 100.5, MAD = 1
      Zₘ = 0.6745 × (110 − 100.5) / 1 = 6.42
      |Zₘ| = 6.42 ≥ Threshold (3.5)

 

  • If Latest Value = 90
    Result: Skipped ☑️
    Explanation:
      M = 100.5, MAD = 1
      Zₘ = 0.6745 × (90 − 100.5) / 1 = -7.08
      |Zₘ| = 7.08 ≥ Threshold (3.5)
      But direction = Decrease → does not match “Increased”

Example 2
Change Type: Decreased
Threshold: 3
History: 150, 160, 140, 155

 

  • If Latest Value = 150
    Result: Normal ✅
    Explanation:
      M = 152.5, MAD = 5
      Zₘ = 0.6745 × (150 − 152.5) / 5 = -0.34
      |Zₘ| = 0.34 < Threshold (3)

 

  • If Latest Value = 120
    Result: Anomaly Detected ❌
    Explanation:
      M = 152.5, MAD = 5
      Zₘ = 0.6745 × (120 − 152.5) / 5 = -4.34
      |Zₘ| = 4.34 ≥ Threshold (3)

 

  • If Latest Value = 180
    Result: Skipped ☑️
    Explanation:
      M = 152.5, MAD = 5
      Zₘ = 0.6745 × (180 − 152.5) / 5 = 3.71
      |Zₘ| = 3.71 ≥ Threshold (3)
      But direction = Increase → does not match “Decreased”

Example 3
Change Type: Any
Threshold: 4
History: 500, 510, 520, 530

 

  • If Latest Value = 515
    Result: Normal ✅
    Explanation:
      M = 515, MAD = 10
      Zₘ = 0.6745 × (515 − 515) / 10 = 0
      |Zₘ| = 0 < Threshold (4)

 

  • If Latest Value = 580
    Result: Anomaly Detected ❌
    Explanation:
      M = 515, MAD = 10
      Zₘ = 0.6745 × (580 − 515) / 10 = 4.38
      |Zₘ| = 4.38 ≥ Threshold (4)