Community研究与数据分析github.com

纵向统计分析流水线

针对面板/重复测量数据(每个受试者一个或多个会话,含组间条件)运行可复现的分析:描述统计、操纵检验、线性混合模型、滞后中介或对随机效应/协方差结构的敏感性分析。

纵向统计分析流水线 是什么?

这是一个自包含的AI Agent技能,专为纵向/面板数据设计,提供完整的可复现分析流程。它支持描述统计、操纵检验(ANOVA)、线性混合模型(LMM)、滞后中介分析和随机效应/协方差结构敏感性分析。核心统计计算由R(lme4、lavaan、emmeans)完成,Python端负责编排、验证和结果导出。当R或R包缺失时,流水线会自动跳过R相关步骤,并在审计日志中记录原因,转而执行仅依赖Python的步骤。技能通过YAML配置文件驱动,每个步骤可独立启用,结果以CSV文件输出,并附带详细的审计跟踪(JSONL格式)。此技能特别适合需要严格审计追踪、避免一次性计算的科研或数据科学场景。

兼容平台~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 的新对话。

文档

纵向分析

一个自包含的技能,用于对纵向/面板数据运行可复现的多步骤分析。 每个步骤独立启用并可审计;R(lme4 / lavaan)负责统计核心计算, Python端负责编排,并在R缺失时优雅降级。

强制工作流程

依赖引导(首次使用运行)

首次运行前,探测本技能的运行时依赖:

  • 必需(Python):pandas、PyYAML。
  • 可选(Python):statsmodels、scipy(操纵检验步骤)。
  • 必需(外部):路径中需包含 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 <路径> [--step <名称>]。

  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)必须在本地安装;当 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).

相关技能