Skip to content
Back to skills

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

ASecurity

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

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationpythonapi

Works with

  • api

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill '分组ols回归分析及统计指标导出' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 分组Ols回归分析及统计指标导出?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 分组Ols回归分析及统计指标导出
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-ols-autoskill/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-ols-autoskill)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "fd2e9bea-f592-41d3-9384-8a6ab31c5f1c"
name: "分组OLS回归分析及统计指标导出"
description: "对数据按指定列(如年龄)进行分组OLS回归分析,提取所有自变量的系数、t值和p值,并将结果整理保存为CSV文件。"
version: "0.1.0"
tags:
  - "python"
  - "pandas"
  - "statsmodels"
  - "ols"
  - "回归分析"
  - "数据导出"
triggers:
  - "分组回归分析导出csv"
  - "提取回归系数t值p值"
  - "statsmodels循环回归保存结果"
  - "按年龄分组回归并保存统计量"
  - "保存回归结果为csv包含t值p值"
---

# 分组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值

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.