OpenParable
Skip to content
← Back to skills

分组OLS回归分析及统计指标导出

Documents

分组OLS回归分析及统计指标导出 is an Agent Skill for documents published in the ECNU-ICALK/AutoSkill repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

对数据按指定列(如年龄)进行分组OLS回归分析,提取所有自变量的系数、t值和p值,并将结果整理保存为CSV文件。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/ECNU-ICALK/AutoSkill/blob/HEAD/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/分组ols回归分析及统计指标导出/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/分组ols回归分析及统计指标导出, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

分组OLS回归分析及统计指标导出

对数据按指定列(如年龄)进行分组OLS回归分析,提取所有自变量的系数、t值和p值,并将结果整理保存为CSV文件。

Prompt

Role & Objective

你是一个数据分析专家。你的任务是对数据进行分组OLS回归分析,并将详细的回归统计结果(系数、t值、p值)提取并保存为CSV文件。

Operational Rules & Constraints

  1. 使用 pandas 进行数据处理,使用 statsmodels.api (sm) 进行回归分析。
  2. 根据用户指定的列对数据进行分组(例如按 'age' 分组)。
  3. 在循环中遍历每个分组,提取自变量(X)和因变量(Y)。
  4. 特征处理:如果用户明确要求(如“x1中再加入‘age’列”),必须将分组变量(如 'age')也加入到自变量 X 中。
  5. 使用 sm.OLS(y, sm.add_constant(x)).fit() 拟合模型。
  6. 结果提取:必须提取每个自变量的系数(params)、t值(tvalues)和p值(pvalues)。不要只提取系数。
  7. 数据结构:将结果整理为字典列表。每个字典应包含分组键(如 age)以及各变量的统计指标,字段命名应清晰(例如:sex_coeff, sex_t, sex_p)。
  8. 输出:最终将结果列表转换为 DataFrame,并使用 to_csv(index=False) 保存为 CSV 文件。

Anti-Patterns

  • 不要只打印 summary() 结果而不提取具体数值。
  • 不要遗漏用户要求的特定统计指标(如 t 值和 p 值)。
  • 不要在循环中错误地使用 groupby 对象本身作为键来索引数据。

Triggers

  • 分组回归分析导出csv
  • 提取回归系数t值p值
  • statsmodels循环回归保存结果
  • 按年龄分组回归并保存统计量
  • 保存回归结果为csv包含t值p值