File contents Skill: factorial-anova
多因子變異數分析(Factorial ANOVA / ANCOVA)與 Word 報告匯出。
Metadata
Description : 對兩個以上因子的獨立樣本設計執行 Type II / Type III ANOVA,含交互作用檢驗、事後兩兩比較(Tukey/Sidak)、簡單主效應剖析、共變量 (ANCOVA)、效應量 (η²/ω²/偏 η²)、交互作用圖。
Version : 1.0.0
Entrypoint : orchestrator.py(CLI: --source {local,sql,hadoop} + --y <col> + --factors <cols> + --covariates <cols> + --ss-type {2,3})
Related :
單因子 ANOVA / t-test / 相關性:advanced-data-analytics
迴歸建模:regression-analytics
EFA / CFA:factor-analysis
Analysis Modes
只有 一種 主要模式(factorial),依 --factors 個數與 --covariates 決定分析形態:
情境
--factors
--covariates
分析類型
Two-way ANOVA
2
0
y ~ A * B
N-way ANOVA
≥3
0
y ~ A * B * C ...
ANCOVA
≥1
≥1
y ~ cov + A * B
One-way (退化)
1
0
建議改用 advanced-data-analytics 的 auto 模式
決策流程
輸入契約校驗 (data_fetcher.py)
y 為連續數值,factors 為類別(自動 to factor),covariates 為連續數值
listwise deletion,記錄丟棄筆數
若某因子只有 1 個 level → 錯誤攔下
若 cell 數量 <2 → 警告(無法估計交互)
前置檢驗
每個 cell 的樣本量 (不平衡設計會影響 SS type 選擇)
Levene's Test 方差齊性(car::leveneTest)
殘差 Shapiro-Wilk (正態性)
主分析
Type II SS (預設,適用平衡+無交互假設;正交因子)
Type III SS (--ss-type 3,適用不平衡設計+有交互;預設 contr.sum)
car::Anova(fit, type=...)
效應量 (effectsize 套件)
每個效應項的 偏 η² (partial eta²) + 95% CI
ω² (omega²) 無偏估計
Cohen's f (給 power 分析用)
事後檢驗 (自動觸發,可由 --no-posthoc 關)
主效應顯著 → Tukey HSD(emmeans::pairs, adjust="tukey")
交互作用顯著 → 簡單主效應 (simple main effects):固定一個因子,比較另一個因子在該 level 上的差異,Sidak 校正
兩兩比較都給出 estimate + SE + t + p_adj + 顯著標記
可視化
交互作用圖 (Interaction Plot):每個因子組合的估計邊際均值 + CI
主效應圖(每個因子單獨)
殘差 vs Fitted、Q-Q(假設檢驗診斷)
Output Location
預設輸出目錄 :./outcome-temp/
fetched_data.csv:資料快照
FactorialANOVA_Report.docx:Word 報告
interaction_plot.png / main_effects_plot.png / diagnostics.png
Workflow (SOP)
fetch : schema + variance 校驗(因子至少 2 levels、y/cov 為數值)
execute : car::Anova(aov(...), type=II/III) + 每個效應項 partial η² + Levene + Shapiro
posthoc : 主效應 Tukey / 交互作用 simple effects
render : 依實際觸發項目動態組裝章節
Constraints
數值保留 4 位小數
Type III 需要 contr.sum 對比編碼 → skill 自動設定,執行完自動還原
交互作用不顯著(p ≥ 0.05)時,事後只跑主效應;顯著時只跑 simple effects(避免 double-dipping)
樣式集中於 templates/word_styles.json
Dependencies
Python 3.10+: pandas sqlalchemy python-docx openpyxl pyhive thrift thrift-sasl pure-sasl
R 4.x:
必要 : ggplot2 jsonlite car emmeans effectsize
可選 : showtext sysfonts(CJK 字型)
1 --- 2 name: factorial-anova 3 description: Skill: factorial-anova 4 --- 5 6 # Skill: factorial-anova 7 8 多因子變異數分析(Factorial ANOVA / ANCOVA)與 Word 報告匯出。 9 10 ## Metadata 11 - **Description**: 對兩個以上因子的獨立樣本設計執行 Type II / Type III ANOVA,含交互作用檢驗、事後兩兩比較(Tukey/Sidak)、簡單主效應剖析、共變量 (ANCOVA)、效應量 (η²/ω²/偏 η²)、交互作用圖。 12 - **Version**: 1.0.0 13 - **Entrypoint**: `orchestrator.py`(CLI: `--source {local,sql,hadoop}` + `--y <col>` + `--factors <cols>` + `--covariates <cols>` + `--ss-type {2,3}`) 14 - **Related**: 15 - 單因子 ANOVA / t-test / 相關性:`advanced-data-analytics` 16 - 迴歸建模:`regression-analytics` 17 - EFA / CFA:`factor-analysis` 18 19 ## Analysis Modes 20 21 只有 **一種** 主要模式(`factorial`),依 `--factors` 個數與 `--covariates` 決定分析形態: 22 23 | 情境 | `--factors` | `--covariates` | 分析類型 | 24 |---|---|---|---| 25 | Two-way ANOVA | 2 | 0 | `y ~ A * B` | 26 | N-way ANOVA | ≥3 | 0 | `y ~ A * B * C ...` | 27 | ANCOVA | ≥1 | ≥1 | `y ~ cov + A * B` | 28 | One-way (退化) | 1 | 0 | 建議改用 `advanced-data-analytics` 的 `auto` 模式 | 29 30 ### 決策流程 31 32 1. **輸入契約校驗**(`data_fetcher.py`) 33 - `y` 為連續數值,`factors` 為類別(自動 to factor),`covariates` 為連續數值 34 - listwise deletion,記錄丟棄筆數 35 - 若某因子只有 1 個 level → 錯誤攔下 36 - 若 cell 數量 <2 → 警告(無法估計交互) 37 38 2. **前置檢驗** 39 - **每個 cell 的樣本量**(不平衡設計會影響 SS type 選擇) 40 - **Levene's Test** 方差齊性(`car::leveneTest`) 41 - **殘差 Shapiro-Wilk**(正態性) 42 43 3. **主分析** 44 - **Type II SS**(預設,適用平衡+無交互假設;正交因子) 45 - **Type III SS**(`--ss-type 3`,適用不平衡設計+有交互;預設 `contr.sum`) 46 - `car::Anova(fit, type=...)` 47 48 4. **效應量**(`effectsize` 套件) 49 - 每個效應項的 **偏 η² (partial eta²)** + 95% CI 50 - **ω² (omega²)** 無偏估計 51 - **Cohen's f**(給 power 分析用) 52 53 5. **事後檢驗**(自動觸發,可由 `--no-posthoc` 關) 54 - 主效應顯著 → Tukey HSD(`emmeans::pairs`, adjust="tukey") 55 - 交互作用顯著 → **簡單主效應**(simple main effects):固定一個因子,比較另一個因子在該 level 上的差異,Sidak 校正 56 - 兩兩比較都給出 estimate + SE + t + p_adj + 顯著標記 57 58 6. **可視化** 59 - **交互作用圖**(Interaction Plot):每個因子組合的估計邊際均值 + CI 60 - 主效應圖(每個因子單獨) 61 - 殘差 vs Fitted、Q-Q(假設檢驗診斷) 62 63 ## Output Location 64 65 **預設輸出目錄**:`./outcome-temp/` 66 67 - `fetched_data.csv`:資料快照 68 - `FactorialANOVA_Report.docx`:Word 報告 69 - `interaction_plot.png` / `main_effects_plot.png` / `diagnostics.png` 70 71 ## Workflow (SOP) 72 1. **fetch**: schema + variance 校驗(因子至少 2 levels、y/cov 為數值) 73 2. **execute**: `car::Anova(aov(...), type=II/III)` + 每個效應項 partial η² + Levene + Shapiro 74 3. **posthoc**: 主效應 Tukey / 交互作用 simple effects 75 4. **render**: 依實際觸發項目動態組裝章節 76 77 ## Constraints 78 - 數值保留 4 位小數 79 - Type III 需要 `contr.sum` 對比編碼 → skill 自動設定,執行完自動還原 80 - 交互作用不顯著(p ≥ 0.05)時,事後只跑主效應;顯著時只跑 simple effects(避免 double-dipping) 81 - 樣式集中於 `templates/word_styles.json` 82 83 ## Dependencies 84 - Python 3.10+: `pandas sqlalchemy python-docx openpyxl pyhive thrift thrift-sasl pure-sasl` 85 - R 4.x: 86 - **必要**: `ggplot2 jsonlite car emmeans effectsize` 87 - **可選**: `showtext sysfonts`(CJK 字型)
kaito41418-ux/r-stats-skills/tree/main/skills/factorial-anova commit 9b17b42b29
Frequently asked questions How do I install the Factorial Anova skill? Run npx skillmds@latest add kaito41418-ux/factorial-anova in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Factorial Anova skill do? Skill: factorial-anova It is listed under Coding & Dev Tools on SkillMD.
Is Factorial Anova safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Factorial Anova? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Factorial Anova free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Factorial Anova? kaito41418-ux (@kaito41418-ux) published this skill. Their other Agent Skills are listed on their SkillMD profile.