| name | cross-sectional-consistency |
| description | Calculate cross-sectional consistency for categorical string variables in a QUIQ-format table using Claude CLI to group semantically equivalent values. No API key required. Use for data quality assessment when the same real-world concept may be expressed in multiple ways (e.g., 'F', 'Female', '์ฌ์'). |
Cross-Sectional Consistency
Calculates cross-sectional consistency for categorical string variables in a QUIQ-format table. Uses Claude CLI to group unique values by semantic equivalence, then measures how consistently a single canonical form is used within each semantic group.
When to Use This Skill
- The same concept is expressed in multiple forms (e.g.,
'F', 'Female', '์ฌ์')
- To detect cross-institutional or cross-user naming inconsistencies
- As part of LYDUS quality management assessment
Input Requirements
QUIQ CSV โ standard QUIQ-format output. Variables analyzed must meet all of:
Variable_type contains string or str
Mapping_info_1 does NOT contain note, code, or date
Is_categorical == 1
Value is not null
- At least 2 unique values (variables with only 1 unique value are skipped)
VIA CSV (Variable Information Annotation) โ provides natural-language descriptions per variable to help the LLM make accurate groupings.
| Column | Description |
|---|
Original_table_name | Table name (matches QUIQ) |
Variable_name | Variable name (matches QUIQ) |
Description | Natural language description of the variable |
How It Works
For each (Original_table_name, Variable_name) group:
- Unique values are sent to the LLM with a system prompt and variable description
- LLM groups semantically equivalent values (e.g.,
['F', 'Female', '์ฌ'] โ one group)
- Within each group, inner consistency is calculated:
- For each semantic group, measure how dominant the most frequent form is
- Score =
ฮฃ (countยฒ/total) / total across all groups โ closer to 1.0 = one canonical form dominates
- LLM is retried up to 5 times if no values match
Average Cross-Sectional Consistency = unweighted mean across all valid variables.
Output
| File | Description |
|---|
cross_sectional_consistency_total.txt | Average Cross-Sectional Consistency (%) |
cross_sectional_consistency_summary.csv | Per-variable consistency scores |
cross_sectional_consistency_detail.txt | LLM-assigned semantic groups per variable |
How to Run
import pandas as pd
from scripts.cross_sectional_consistency import get_cross_sectional_consistency
quiq = pd.read_csv("/path/to/quiq.csv")
via = pd.read_csv("/path/to/via.csv")
average_consistency, results_df, detail = get_cross_sectional_consistency(
quiq=quiq,
via=via
)
print(f"Average Cross-Sectional Consistency (%) = {round(average_consistency * 100, 2)}")
As a script with config
quiq_path: /path/to/quiq.csv
via_path: /path/to/via.csv
save_path: /path/to/output
python scripts/cross_sectional_consistency.py --config config.yaml
Critical Notes
-
SQL ๋ณํ ๋ถ๊ฐ โ Claude CLI ํธ์ถ ๋ฐ ์๋ต ํ์ฑ์ด ํต์ฌ ๋ก์ง์ด๋ฏ๋ก DuckDB/BigQuery SQL๋ก ํํํ ์ ์์.
-
VIA ํ์ผ ํ์ โ via_path๊ฐ ์์ผ๋ฉด ๋ชจ๋ ๋ณ์์ "No description available"์ด ์ ๋ฌ๋์ด LLM ์ ํ๋๊ฐ ๋ฎ์์ง.
-
LLM ์ฌ์๋ ๋ก์ง โ ์๋ต์ด ์ค์ ๊ฐ๊ณผ ๋งค์นญ๋์ง ์์ผ๋ฉด ์ต๋ 5ํ ์ฌ์๋. ์ฌ์ ํ ์คํจํ๋ฉด ํด๋น ๋ณ์๋ ๊ฒฐ๊ณผ์์ ์ ์ธ๋จ.
-
API ํค ๋ถํ์ โ LLM ํธ์ถ์ ํ์ฌ Claude Code ์ธ์
์ Claude CLI(claude -p)๋ฅผ ํตํด ์ฒ๋ฆฌ๋๋ฏ๋ก ๋ณ๋ API ํค๊ฐ ํ์ ์์.
-
Is_categorical ํ์
โ ์๋ณธ ์ฝ๋์์ Is_categorical == 1 ๋น๊ต ์ pd.to_numeric() ๋ณํ์ ๋๋ฝํ ๋ฒ๊ทธ๊ฐ ์์์. ์คํฌ ๋ฒ์ ์์ ์์ ๋จ.
References
- LYDUS ํ์ง๊ด๋ฆฌ ํ๋ก๊ทธ๋จ ํ์ฉ ๊ฐ์ด๋๋ผ์ธ (๋น๊ณต๊ฐ ๋ด๋ถ ๋ฌธ์)
- Original Python implementation: LYDUS_Cross_Sectional_Consistency.py (์ด์ฑ๋ฏผ ์์ฑ)