charlieviettq/awesome-agent-skill / .claude/skills/algo-risk-benford
"algo-risk-benford"
Verified"Apply Benford's Law to detect anomalies in numerical datasets by analyzing first-digit frequency distributions. Use this skill when the user needs to audit financial data for fraud indicators, validate data integrity, or detect fabricated numbers — even if they say 'data manipulation detection', 'first digit test', or 'accounting fraud screening'.".
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.3 KB |
| examples/sample_scenario.md | markdown | 5.0 KB |
| references/fraud-case-studies.md | markdown | 10.6 KB |
| references/higher-digit-tests.md | markdown | 10.0 KB |
examples/sample_scenario.md
View on GitHub# Example: 台灣連鎖零售商 Q3 費用報銷異常偵測
## Scenario
**公司:** 全虹家居股份有限公司(台灣中型連鎖居家用品零售商,30 家門市)
**時間:** 2025 年 10 月,Q3 稽核季
**提問者:** 財務長 Amanda Chen
財務長在例行內部稽核中發現,Q3(2025 年 7–9 月)各門市主管提交的費用報銷金額合計異常偏高,達 NT$14.2M,較去年同期成長 31%。她懷疑部分主管可能刻意分拆費用以規避 NT$5,000 單筆審核上限,要求對 4,837 筆費用申請單進行 Benford's Law 分析。
---
## Analysis
### Phase 1: 輸入驗證
| 檢查項目 | 結果 |
|----------|------|
| 記錄筆數 | 4,837 筆(通過 ≥ 500 門檻) |
| 數值範圍 | NT$12 ~ NT$48,600 |
| 數量級跨幅 | 10¹ ~ 10⁴(跨越 3 個數量級,✓ 適用 Benford's Law) |
| 資料類型 | 自然發生的費用金額(非流水號、非郵遞區號)|
| 過濾後筆數 | 移除 0 值及負值後剩 4,819 筆 |
**Phase 1 Gate:通過。** 資料型態合適,樣本數充足,可進入分析。
---
### Phase 2: 首位數頻率計算
從 4,819 筆有效記錄中提取首位數字:
| 首位數字 | 觀察次數 | 觀察頻率 (%) | Benford 預期 (%) | 偏差 (%) |
|:--------:|:--------:|:------------:|:----------------:|:--------:|
| 1 | 1,241 | 25.76 | 30.10 | **−4.34** |
| 2 | 893 | 18.53 | 17.61 | +0.92 |
| 3 | 614 | 12.74 | 12.49 | +0.25 |
| 4 | **1,032** | **21.42** | 9.69 | **+11.73** ⚠️ |
| 5 | 298 | 6.18 | 7.92 | −1.74 |
| 6 | 287 | 5.95 | 6.69 | −0.74 |
| 7 | 218 | 4.52 | 5.80 | −1.28 |
| 8 | 157 | 3.26 | 5.12 | −1.86 |
| 9 | 79 | 1.64 | 4.58 | **−2.94** |
**顯著異常:首位數字 4 的觀察頻率(21.42%)超出預期(9.69%)逾兩倍。**
---
### Phase 3: 統計檢定
**MAD(平均絕對偏差)計算:**
```
MAD = (|−4.34| + |0.92| + |0.25| + |11.73| + |1.74| + |0.74| + |1.28| + |1.86| + |2.94|) / 9
= 25.80 / 9
= 0.0287
```
> MAD 0.0287 **遠超** 非合規門檻 0.015 → 判定:**Non-Conforming(不合規)**
**卡方檢定:**
```
χ² = Σ [(觀察 − 預期)² / 預期]
= (−4.34)²/30.10 + … + (11.73)²/9.69 + …
≈ 127.4,df = 8,p < 0.0001
```
| 統計量 | 數值 | 判定 |
|--------|------|------|
| MAD | 0.0287 | Non-Conforming |
| χ² | 127.4 | 顯著(p < 0.0001) |
| KS statistic | 0.118 | 顯著(critical value 0.049 @ α=0.05)|
**Phase 3 Gate:所有統計量均顯示強烈不合規,主要異常集中在首位數字 4。**
---
### 深入調查:Approval Threshold 效應
費用單筆審核規定:
- **NT$5,000 以下**:門市主管自行核決
- **NT$5,000 以上**:需區域經理連署
首位數字 4 的 1,032 筆中,進一步篩選金額落在 **NT$4,000–NT$4,999** 的筆數:
| 金額區間 | 筆數 | 比例 |
|----------|:----:|:----:|
| NT$4,000–NT$4,499 | 134 | 13% |
| NT$4,500–NT$4,799 | 201 | 19% |
| NT$4,800–NT$4,899 | 118 | 11% |
| **NT$4,900–NT$4,999** | **412** | **40%** ⚠️ |
| NT$4,000–NT$4,999 小計 | **865** | **84%** |
**84% 的首位數字 4 費用單集中於 NT$4,000–NT$4,999 區間,其中 NT$4,900–NT$4,999 最為密集。** 這是典型的「閾值規避」行為(Threshold Avoidance),表明申請人刻意控制金額低於 NT$5,000 審核門檻。
---
## Result
```json
{
"conformity": "non-conforming",
"mad": 0.0287,
"chi_squared": {
"statistic": 127.4,
"p_value": 0.0001,
"df": 8
},
"digit_analysis": [
{"digit": 1, "observed_pct": 25.76, "expected_pct": 30.10, "deviation": -4.34},
{"digit": 2, "observed_pct": 18.53, "expected_pct": 17.61, "deviation": 0.92},
{"digit": 3, "observed_pct": 12.74, "expected_pct": 12.49, "deviation": 0.25},
{"digit": 4, "observed_pct": 21.42, "expected_pct": 9.69, "deviation": 11.73},
{"digit": 5, "observed_pct": 6.18, "expected_pct": 7.92, "deviation": -1.74},
{"digit": 6, "observed_pct": 5.95, "expected_pct": 6.69, "deviation": -0.74},
{"digit": 7, "observed_pct": 4.52, "expected_pct": 5.80, "deviation": -1.28},
{"digit": 8, "observed_pct": 3.26, "expected_pct": 5.12, "deviation": -1.86},
{"digit": 9, "observed_pct": 1.64, "expected_pct": 4.58, "deviation": -2.94}
],
"metadata": {
"records": 4819,
"dataset": "全虹家居 Q3 2025 費用報銷申請",
"flag": "首位數字 4 嚴重超標(+11.73pp),NT$4,900–NT$4,999 密集區間疑似閾值規避"
}
}
```
### 建議後續行動
1. **非結論性**:MAD 0.0287 屬強烈紅旗,但不等於確認詐欺。需進一步取證。
2. **立即抽查**:對 412 筆 NT$4,900–NT$4,999 費用單要求提供原始發票及業務說明。
3. **門市交叉比對**:按門市彙整首位數字 4 的集中度,找出貢獻最高的 3–5 家門市主管。
4. **第二位數字分析**:對首位數字 4 的子集執行第二位數字測試,進一步縮小可疑範圍(參見 `references/higher-digit-tests.md`)。
5. **時間序列**:比對 Q1、Q2 同門市的分布,確認異常是否為 Q3 新增行為。
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |