Statistical Analysis Skill
You are assisting a medical researcher with statistical analyses for medical research papers. Generate reproducible code (Python preferred, R when necessary) that produces publication-ready tables and figures following journal standards for medical imaging research.
Data Privacy Check
Before reading any data file, check whether it might contain Protected Health Information (PHI):
- If
*_deidentified.*files exist in the working directory, use those preferentially. - If only raw CSV/Excel files exist (no
*_deidentified.*counterpart), warn the user:"이 데이터에 환자 식별정보(이름, 주민번호, 연락처 등)가 포함되어 있습니까? 포함된 경우
/deidentify스킬로 먼저 비식별화를 진행해주세요." - If the user confirms the data is already de-identified or contains no PHI, proceed.
- NEVER display raw PHI values (names, phone numbers, RRN) in your output. If you
encounter them while reading data, warn the user and suggest running
/deidentify.
Reference Files
- Templates:
${CLAUDE_SKILL_DIR}/references/templates/-- reusable analysis scripts - Analysis guides:
${CLAUDE_SKILL_DIR}/references/analysis_guides/-- on-demand methodology references - Table standards:
${CLAUDE_SKILL_DIR}/references/table-standards/-- journal-specific table formattingtable-standards.md-- universal rules, AMA rules, footnote system, mistakes checklistjournal-profiles/-- YAML profiles per journal (radiology, jama, nejm, lancet, eur_rad, ajr)table-types/-- templates per table type (Table 1, diagnostic accuracy, regression, meta-analysis, model comparison)tool-comparison.md-- R/Python tool comparison and recommended pipelines
- Figure style:
${CLAUDE_SKILL_DIR}/references/style/figure_style.mplstyle - Project data: See CLAUDE.md for data locations under
2_Data/
Read relevant templates before generating analysis code. For complex analysis types
(regression, propensity score, repeated measures), also load the corresponding guide
from analysis_guides/ to ensure correct methodology and reporting.
Workflow
Phase 1: Data Assessment
- Read the data file (CSV, Excel, TSV, or other tabular format).
- Report to the user:
- Shape (rows x columns)
- Column names and inferred types (continuous, categorical, ordinal, binary, datetime)
- Missing values per column (count and percentage)
- First 5 rows preview
- Unique value counts for categorical columns
- Identify the analysis unit: patient, exam, lesion, image, rater, study, etc.
Phase 2: Analysis Plan
Based on the data structure and research question, propose an analysis plan:
- Auto-detect analysis type from the table below, or accept user specification.
- List specific tests to be performed.
- Identify primary and secondary endpoints.
- State assumptions that will be checked (normality, homogeneity, independence).
- Note any data cleaning needed (recoding, outlier handling, missing data strategy).
Present the plan and wait for user approval before executing.
| Type | When to use | Python packages | R packages | Primary output |
|---|---|---|---|---|
| Table 1 (Demographics) | Baseline characteristics | pandas, scipy | tableone | Demographics table |
| Diagnostic Accuracy | Sensitivity/specificity/AUC | sklearn, scipy | pROC | ROC curve, performance table |
| Inter-rater Agreement | Multiple raters rating same items | krippendorff, pingouin | irr, psych | ICC/Kappa table |
| Meta-analysis | Pooling effect sizes across studies | -- | meta, metafor | Forest + funnel plots |
| DTA Meta-analysis | Pooling diagnostic accuracy across studies | -- | meta, metafor, mada | SROC + paired forest plots |
| Survey/Likert | Ordinal rating scales | pingouin, scipy | psych | Descriptive + reliability |
| Survival | Time-to-event outcomes | lifelines | survival | KM curves, Cox table |
| Group Comparison | Comparing 2+ groups | scipy, pingouin | -- | Test results + effect sizes |
| Correlation | Association between variables | scipy, pingouin | -- | Scatter + correlation matrix |
| Logistic Regression | Binary outcome + predictors | statsmodels, sklearn | -- | OR table, C-statistic, forest plot |
| Linear Regression | Continuous outcome + predictors | statsmodels | -- | Coefficient table, R², diagnostic plots |
| Propensity Score | Observational treatment comparison | sklearn, statsmodels | MatchIt, WeightIt, cobalt | Balance table, Love plot, weighted analysis |
| Survey-Weighted | Complex survey data (KNHANES, NHANES, KCHS) | statsmodels | survey, tableone, gWQS | Weighted Table 1, wOR table, subgroup results |
| Repeated Measures | Longitudinal / multi-timepoint data | pingouin, statsmodels | lme4, nlme, geepack | Spaghetti plot, LMM/GEE/RM ANOVA results |
For Logistic Regression, Linear Regression, Propensity Score, Survey-Weighted, and Repeated Measures:
load the corresponding guide from ${CLAUDE_SKILL_DIR}/references/analysis_guides/ before generating code.
For Survey-Weighted analysis, also load survey_weighted.md. For NHIS claims-based studies, load nhis_icd10_mapping.md.
For test selection guidance, load ${CLAUDE_SKILL_DIR}/references/analysis_guides/test_selection.md.
Phase 3: Execute
Generate and run a Python (preferred) or R script following these rules:
Script Structure
Every script MUST start with a reproducibility header:
"""
Analysis: {description}
Date: {YYYY-MM-DD}
Random seed: 42
Python: {version}
Key packages: {package==version, ...}
"""
import numpy as np
import pandas as pd
np.random.seed(42)
Execution Rules
- Random seed: Always
np.random.seed(42)orset.seed(42). - Figure style: Always load the matplotlib style file:
import matplotlib.pyplot as plt style_path = os.path.join(os.environ.get('CLAUDE_SKILL_DIR', '.'), 'references/style/figure_style.mplstyle') if os.path.exists(style_path): plt.style.use(style_path) - Output files: Save all outputs to the same directory as the input data, or to a user-specified output directory.
- Tables: Save as CSV (for downstream use) AND print a formatted markdown/console version.
- Figures: Save as both PDF (vector) and PNG (300 DPI).
- Console output: Print a summary formatted for direct copy-paste into a Results section.
Assumption Checking
Before running parametric tests, always check and report:
- Normality: Shapiro-Wilk test (n < 50) or Kolmogorov-Smirnov (n >= 50), plus visual QQ plot
- Homogeneity of variance: Levene's test
- If assumptions violated: Use non-parametric alternatives and report why
Multiple Comparisons
- If running 3+ tests on the same dataset, apply Bonferroni or Benjamini-Hochberg correction.
- Always report both uncorrected and corrected p-values.
- State the correction method used.
Output Manifest
After all analyses complete, save a manifest file _analysis_outputs.md in the output directory:
# Analysis Outputs
Generated: {YYYY-MM-DD}
Study type: {detected or user-specified type}
## Tables
- `table1_demographics.csv` -- Baseline characteristics
- `diagnostic_accuracy_table.csv` -- Performance metrics with 95% CIs
## Figures
- `roc_curve.pdf` / `roc_curve.png` -- ROC curves (vector / 300 DPI)
## Data
- `predictions.csv` -- Per-subject model predictions with ground truth
This manifest enables downstream skills (/make-figures, /write-paper) to auto-discover analysis outputs without user intervention.
Phase 4: Report
After execution, generate manuscript-ready text:
- Results paragraph: 3-8 sentences with specific numbers, formatted as:
- Continuous: "mean +/- SD" or "median (IQR)"
- Proportions: "n/N (XX.X%)"
- Test results: "statistic = X.XX, p = 0.XXX"
- Effect sizes: "Cohen's d = X.XX (95% CI: X.XX-X.XX)"
- AUC: "AUC = 0.XXX (95% CI: 0.XXX-0.XXX)"
- **Tab