Community研究與資料分析github.com

縱向統計分析管線

用於面板資料或重複測量資料的可重複分析管線,支援描述統計、操弄檢核、線性混合模型、滯後中介效應分析與隨機效應/共變異數結構的敏感度分析。

縱向統計分析管線 是什麼?

這是一個專為縱向/面板資料設計的統計分析技能,適用於每位受試者擁有一或多個測量時間點與組間條件的情境。技能採用 YAML 設定檔驅動,可獨立啟用或跳過各個分析步驟。Python 端負責協調與資料處理,而統計建模(如線性混合模型、中介效應分析)則依賴 R 的 lme4、lavaan 等套件。若 R 或必要套件缺失,管線會優雅地跳過 R 相關步驟,並在稽核日誌中記錄原因,僅執行 Python 支援的部分。最終結果以 CSV 或 DOCX 格式輸出至 results/tables/ 目錄,並在 results/logs/ 留下完整的步驟稽核軌跡。支援 Windows、macOS 與 Linux 平台,適合需要可重複性與稽核軌跡的學術或產業研究人員使用。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/JiamingShi-JsPhys/agent-skills/tree/HEAD/skills/longitudinal-analysis

Installed? Explore more 研究與資料分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

longitudinal-analysis

一個自成一體的分析技能,用於對縱向/面板資料執行可重複的多步驟分析。每個步驟可獨立啟用並稽核;統計重計算部分由 R(lme4 / lavaan)負責,Python 端負責協調,並在 R 缺失時優雅降級。

強制工作流程

依賴項引導(首次使用時執行)

在首次執行前,探查此技能的執行時期依賴項:

  • 必要(Python):pandas、PyYAML。
  • 選用(Python):statsmodels、scipy(用於操弄檢核步驟)。
  • 必要(外部):位於 PATH 上的 R >= 4.0 與 lme4、lavaan、emmeans、jsonlite — lmm、mediation 和 sensitivity 步驟需要這些套件。

行為:

  • 缺少 Python 依賴項 -> 告知使用者缺少哪些套件,並詢問是否要執行 python -m pip install pandas pyyaml(若要進行操弄檢核則加入 statsmodels scipy)。僅在使用者確認後才進行安裝;建議使用專案本機的虛擬環境。
  • 缺少 R 或 R 套件 -> 請勿嘗試安裝 R。列出確切缺少的 R 套件,跳過所有依賴 R 的步驟,在稽核日誌中記錄原因,並交付有實際執行的 Python 步驟結果。
  1. 載入 YAML 設定檔(參考 config/examples/behavior_2x2x2.yaml)。
  2. 確認 data.input 存在,且 id_column / time_column 都存在。
  3. 執行 python -m src.cli run --config <path> [--step <name>]。
  4. 回報每個步驟的狀態;被跳過的 R 步驟表示未安裝 R — 列出缺少的套件並停止(請勿嘗試安裝)。
  5. 引導使用者前往 results/tables/*.csv 與 results/logs/analysis_log.jsonl。

何時使用

  • 使用者擁有面板/重複測量資料(每位受試者一或多個測量時間點,且有組間條件),並希望進行可重複的分析,而非一次性計算。
  • 使用者提出的技術名稱包含:「LMM」、「mixed model」、「repeated measures」、「longitudinal analysis」、「mediation over time」、「lagged mediator」或「sensitivity analysis of RE structure」。
  • 需要產出包含稽核軌跡的描述統計、操弄檢核或隨機效應/共變異數結構的敏感度分析。

使用範例

# 驗證設定檔並列出其啟用的步驟。
python -m src.cli validate --config config/examples/behavior_2x2x2.yaml
python -m src.cli list-steps --config config/examples/behavior_2x2x2.yaml

# 執行完整管線,或只執行一個指定步驟。
python -m src.cli run --config config/examples/behavior_2x2x2.yaml
python -m src.cli run --config config/examples/behavior_2x2x2.yaml --step lmm

# 匯出產出的表格(csv 或 docx)。
python -m src.cli export --config config/examples/behavior_2x2x2.yaml --format csv

結果會儲存在 results/tables/*.csv;每個步驟的稽核軌跡則在 results/logs/analysis_log.jsonl。

錯誤處理

  • 某步驟回報 skipped — 表示缺少 R 或某個 R 套件。列出缺少的套件並停止;請勿嘗試安裝,也請勿用手算替代。
  • 設定檔無效(validate 回傳非零值) — 修正所回報的欄位(通常是 data.input、id_column 或 time_column)並重新驗證。
  • 管線中途發生步驟錯誤 — 保留並稽核先前步驟的輸出;逐字回報失敗的步驟並停止,請勿盲目重新執行。
  • 非預期的結束代碼 — 逐字回報錯誤訊息。

管線步驟

類型模組R 依賴項
descriptivesrc/steps/descriptive.py無
anova(操弄檢核)src/steps/manipulation.py無(使用 statsmodels)
lmmsrc/steps/lmm.pyR/lmm.R(lme4 + emmeans)
mediation(滯後中介)src/steps/mediation.pyR/mediation.R(lavaan)
sensitivitysrc/steps/sensitivity.pyR/lmm.R

限制

  • R 套件(lme4、lavaan、emmeans、jsonlite)必須在本機安裝;若 PATH 上找不到 Rscript,管線會跳過依賴 R 的步驟,並在稽核日誌中記錄原因。
  • 中介效應的拔靴法(bootstrap)由使用者選擇(預設 5000 次);實際耗時會隨著樣本數增加而增加。

Individual skills in this repo

This repo contains 3 individual skills — each has its own dedicated page.

JiamingShi-JsPhys/agent-skills

Cross-document conflict detector. Use when the user has two or more documents, datasets, or extracted fact tables and wants to find contradictions between them. Triggers on "detect conflicts", "find contradictions", "do these documents agree", "cross-check claims", "inconsistency check", or when comparing a claim across multiple sources. Runs three detection levels: entity (numeric / boolean mismatch on the same key), clause (categorical mismatch), and argument (free-text disagreement). Emits a machine-readable conflict report in JSON / CSV / Markdown.

JiamingShi-JsPhys/agent-skills

Document evolution tracker. Use when the user has a family of document versions (timestamped or sequentially named files) and wants to see how the document changed over time -- which paragraphs / lines / sentences were added, removed, or modified between consecutive versions, and how a set of named concepts (or auto-detected headings) evolved (introduced / retained / modified / dropped). Triggers on "track document changes", "version history", "what changed between drafts", "concept lineage", "document evolution". Emits a Markdown + JSON timeline.

JiamingShi-JsPhys/agent-skills

State manager for multi-dimensional computational experiments. Iterate a parameter grid over many rounds, snapshot declared critical files each round, audit every round (params, hashes, timestamps, status), and roll back to any round non-destructively. Use it when a workflow runs hundreds of rounds across multiple parameter dimensions and needs per-round snapshots, full audit trail, and arbitrary rollback - e.g. longitudinal studies, parameter scans, or symbolic/ numerical sweeps calling external solvers (Mathematica, GAP, SymPy, custom scripts).

相關技能