Logo Statistical Modeling

Statistical Modeling

Cộng đồng
WalrusQuant
statistical-modeling

Hướng dẫn mô hình hóa thống kê cho dữ liệu thể thao do người dùng cung cấp: chọn mô hình cho kết quả nhị phân, liên tục và đếm; kiểm tra giả định; kích thước hiệu ứng; suy luận có xét đến thời gian; chẩn đoán GLM; và báo cáo đầy đủ.

Add to TypingMind

Tổng quan

Nhà phát hànhWalrusQuant
Kho mãsports-analytic-skills
Tên kỹ năngstatistical-modeling
Sao
53
Bản fork
4
Tệp đi kèm
9
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 9 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được WalrusQuant công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Statistical Modeling trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/WalrusQuant/sports-analytic-skills/tree/main/skills/statistical-modeling
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/WalrusQuant/sports-analytic-skills.git /tmp/sports-analytic-skills
mkdir -p .claude/skills
cp -r /tmp/sports-analytic-skills/skills/statistical-modeling .claude/skills/statistical-modeling
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Statistical Modeling trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Statistical Modeling ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Statistical Modeling với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Statistical Modeling for Sports

Overview

This skill's job is classical statistical inference on a user-owned sports table: choose a GLM or test, check assumptions, report effects and uncertainty.

It is not a universal modeling workflow. Do not use it to load data, design walk-forward ML horse races, or certify leakage. Mixed, Bayesian, causal, and power-analysis material below is routed methodology — the bundled scripts only cover univariate assumption checks and an additive numeric binomial GLM.

Conduct the analysis the way a careful analyst would: right model family for the outcome, verified assumptions, honest effect sizes and uncertainty, and a write-up that survives review.

Typical stack: pandas, numpy, scipy, statsmodels, and scikit-learn (+ optional pingouin, seaborn, pymc, and arviz).

When to Use This Skill

Use this skill when:

  • Modeling win/loss, margins, points, goals, runs, or other sports outcomes
  • Comparing groups (home vs away, pre/post rule change, position groups)
  • Fitting logistic, linear, Poisson, or NegBin models on sports panels
  • Checking residual diagnostics and reporting effects with uncertainty
  • After the GLM path, clustered or partially pooled effects (see hierarchical section)
  • Reporting coefficients, odds ratios, effect sizes, and model fit
  • Choosing between classical stats models and jumping to ML

Do not use this skill as a substitute for:

  • raw data loading → use the appropriate loader skill, then return with a user-owned analysis table
  • pure EDA → eda-sports
  • walk-forward ML horse races → predictive-modeling
  • leakage review of feature pipelines → leakage-audit
  • rating systems as the primary object → ratings-strength-models

Installation

Install only the libraries required by the chosen analysis:

bash
python -m pip install pandas numpy scipy statsmodels scikit-learn
# Optional richer classical statistics and plots:
python -m pip install "pingouin>=0.6" "seaborn>=0.13"
# Optional Bayesian hierarchical work:
python -m pip install pymc arviz

Parquet input to the bundled helpers also needs pyarrow or fastparquet.

Compatibility notes:

  • Prefer statsmodels>=0.14 with a recent SciPy.
  • Pingouin 0.6+ uses p_val, cohen_d, and CI95.
  • Read bayesian_statistics.md before selecting Bayesian priors or diagnostics.

Analysis Workflow

Every sound sports statistical analysis follows this arc. Do not skip.

  1. Frame the question before fitting.

    • Outcome (win, margin, goals, player stat)
    • Predictors known at decision time T (if predictive)
    • Unit of analysis (game, team-game, player-game, possession)
    • Estimand: description, prediction, or causal claim (most sports work is predictive/descriptive)
  2. Inspect the data (eda-sports).

    • n by season/group
    • missingness
    • score distributions, zero inflation, outliers
    • home/away balance
  3. Choose the model family using the selection guide below (and references/test_selection_guide.md + references/sports_glm_guide.md).

  4. Enforce time safety for predictive work.

    • Features must be knowable at T
    • Use walk-forward validation (validation-design)
  5. Fit a minimal model first.

    • home indicator + one strength feature beats a kitchen sink
  6. Check assumptions / diagnostics.

    • Use scripts/assumption_checks.py and scripts/glm_diagnostics.py
    • residual plots, overdispersion, leverage, calibration for probabilities
  7. Compare to baselines.

    • constant rate, home-only, simple rating differential (baseline-models)
  8. Report completely.

    • family, formula, n, metrics, coefficients with uncertainty, limits
    • templates in references/reporting_standards.md + sports templates below

If the user only needs one step (e.g. “is home advantage real in this sample?”), jump to that section — but still state design assumptions.

Reference routing:


Model Selection Guide (Sports)

Binary outcomes (win/loss, threshold events)

SituationModel
Independent game outcomes, linear log-odds in featuresLogistic regression (statsmodels GLM Binomial or sklearn)
Clustered games within season/teamCluster-robust SE or mixed effects logistic
Severe separation / rare eventsFirth/penalized logistic, or careful Bayesian prior

Continuous outcomes (margin, rating residual)

SituationModel
Roughly symmetric marginsOLS / Gaussian GLM
Heavy tailsHuber robust regression, Student-t likelihood (Bayesian)
HeteroscedasticityHC3 robust SE, WLS

Counts (goals, runs, sacks, threes made)

SituationModel
Mean ≈ variancePoisson GLM
Over-dispersedNegative Binomial
Excess zerosHurdle / zero-inflated models

Ordered outcomes (win/draw/loss)

  • Proportional odds / ordered logit
  • Or two-stage: draw model + conditional direction

Hierarchical structure

  • Team strength as random intercepts
  • Pitcher/batter, goalie, QB effects with partial pooling
  • Prefer partial pooling over dummy-every-player with tiny n

Group comparisons (not full predictive models)

DesignStart here
Two independent groups, continuousWelch t-test / Mann-Whitney
Paired (same team pre/post)Paired t / Wilcoxon
3+ groupsANOVA / Kruskal-Wallis
Association of two continuousPearson / Spearman
See full treereferences/test_selection_guide.md

Worked Path on a User-Provided Team-Game Table

Start with one row per evaluated decision and document whether that means one row per game or one row per team-game. A useful binary-outcome frame contains:

FieldRole
season, event_time, stable IDschronology and alignment
wonbinary outcome
is_homepre-event context
rating_diff, rest_difflegal pre-event predictors
fold or test-season labelevaluation provenance

For symmetric team-game data, either model both perspectives with dependence-aware uncertainty or select one perspective per game. Never treat doubled rows as independent evidence.

Logistic model with robust inference

python
import numpy as np
import statsmodels.api as sm
import statsmodels.formula.api as smf

train = model_df[model_df["season"] < 2024].copy()
fit = smf.glm(
    "won ~ is_home + rating_diff + rest_diff",
    data=train,
    family=sm.families.Binomial(),
).fit(cov_type="HC3")

odds_ratios = np.exp(fit.params)
odds_ratio_ci = np.exp(fit.conf_int())
print(fit.summary())
print(odds_ratios)
print(odds_ratio_ci)

HC3 is useful for heteroskedasticity but does not solve team, player, or temporal dependence. Use cluster-robust uncertainty or a hierarchical model when the sampling structure requires it.

Margin model

python
home = train[train["is_home"] == 1].copy()  # one row per game
margin_fit = smf.ols(
    "point_margin ~ rating_diff + rest_diff",
    data=home,
).fit(cov_type="HC3")
print(margin_fit.summary())

Inspect residual shape, changing variance, influential games, and nonlinear patterns. If the scientific question concerns an average contrast rather than a conditional linear effect, report that estimand directly too.

Count model

python
poisson_fit = smf.glm(
    "points_for ~ is_home + rating_diff",
    data=train,
    family=sm.families.Poisson(),
).fit()
dispersion = poisson_fit.pearson_chi2 / poisson_fit.df_resid
print(poisson_fit.summary())
print("Pearson dispersion:", dispersion)

Material overdispersion, excess zeros, or correlated paired scores can require a negative-binomial, hurdle/zero-inflated, or joint score model. Select that extension from diagnostics and the data-generating process—not a better-looking p-value.

Predictive evaluation

Freeze expanding time folds before fitting. Within each fold, estimate every transform and model on earlier rows only; score the later block against a training-rate constant and a simple legal-feature baseline. Report every fold, not only the mean.

For a standalone additive binomial diagnostic report:

bash
python /path/to/statistical-modeling/scripts/glm_diagnostics.py \
  --input model_frame.csv \
  --formula "won ~ is_home + rating_diff + rest_diff" \
  --out glm_report.json

The helper reports HC3 inference, odds ratios, intervals, AIC, and in-sample calibration bins. Those bins diagnose fit; they are not held-out evidence.


Assumption Checks & Diagnostics

Always check assumptions before interpreting, and report the checks.

Standalone assumption checks

bash
python /path/to/statistical-modeling/scripts/assumption_checks.py \
  --input observations.csv --value-col margin \
  --group-col venue --out assumptions.json

The helper reports Shapiro-Wilk normality, IQR outliers, and optional median-centered Levene variance testing. Formal tests supplement plots and domain judgment; at large sample sizes they can reject practically harmless departures.

Standalone binomial GLM diagnostics

bash
python /path/to/statistical-modeling/scripts/glm_diagnostics.py \
  --input model_frame.csv \
  --formula "won ~ is_home + rating_diff + rest_diff" \
  --out glm_report.json

Inputs may be CSV, Parquet, JSON, JSONL, or NDJSON. Formulas support additive numeric predictors joined by +; use --outcome-col when the binary target is not won.

What to check by family

Logistic / classification

  • separation / extreme coefficients
  • probability calibration (calibration-check)
  • influential games (high leverage matchups)
  • stability across seasons

Gaussian margin models

  • residual vs fitted curvature
  • QQ plot of residuals
  • residual variance by season or predicted mean
  • inspect influence and leverage with the fitted library's diagnostics (for example, statsmodels OLSInfluence), and use Breusch-Pagan or another predeclared variance check when appropriate

The bundled glm_diagnostics.py fits only additive numeric binomial GLMs. It does not diagnose OLS, Poisson, negative-binomial, mixed, or Bayesian models; use the model library's diagnostics and the linked checklist for those families.

Poisson scoring models

  • overdispersion: Pearson χ² / df >> 1 → NegBin
  • excess zeros

All predictive sports models

  • leakage: any feature using same-game outcomes?
  • temporal drift: does 2019 model die in 2024?

See references/assumptions_and_diagnostics.md and references/diagnostics_checklist.md.


Effect Sizes & Metrics (Sports Defaults)

p-values are usually the wrong headline for predictive sports work. Prefer:

GoalPrimary metrics
Probability modelslog-loss, Brier, calibration curves
Binary decisionsaccuracy only as secondary; care about base rates
MarginsMAE, RMSE, residual SD
CountsMAE, Poisson deviance
Group differences (explanatory)Cohen's d, risk difference, odds ratios + CIs

Odds ratio from logistic coefficient:

python
import numpy as np
or_home = np.exp(fit.params["is_home"])
ci = np.exp(fit.conf_int().loc["is_home"])
print(or_home, ci.tolist())

For classical effect size tables, power analysis, and CI methods, use references/effect_sizes_and_power.md and pingouin:

python
import pingouin as pg
# home vs away margins on home-row frame already encodes home perspective;
# example two-sample on a continuous player metric:
# pg.ttest(group_a, group_b, correction='auto')  # returns cohen_d, CI95, etc.

Hierarchical / Partial Pooling Patterns

Read this section when the estimand is a clustered or partially pooled effect. This is not the default path of the skill, and there is no bundled mixed-model helper. Prefer the GLM/test workflow above unless grouping structure is the question.

When player or team n is uneven, complete-pooling (ignore groups) and no-pooling (dummy each group) both fail. Partial pooling is the default serious approach.

python
import statsmodels.formula.api as smf
# Mixed LM example for continuous margin; requires sufficient group size
md = smf.mixedlm("point_diff ~ is_home", data=train, groups=train["team"])
mdf = md.fit()
print(mdf.summary())

For full Bayesian hierarchical rating models, keep priors explicit and report posterior predictive checks — see references/bayesian_statistics.md.


Group Comparison Examples (Sports)

Home advantage on margins (home rows)

python
home = panel.loc[panel["is_home"].eq(1), ["season", "point_diff"]].dropna()
print(home["point_diff"].describe())  # pooled descriptive game-weighted mean
print(home.groupby("season")["point_diff"].agg(["count", "mean", "std"]))

Do not attach an ordinary one-sample t-test to clustered team/season data by default. Choose the uncertainty method from the sampling structure: a season-block bootstrap for a game-weighted mean, an equal-season estimand on season summaries when seasons are the independent units, or a model with defensible cluster/hierarchical structure. Games connect two teams, so a one-way team cluster can also be inadequate. State the estimand and number of independent clusters; with few clusters, use small-sample-aware methods and weaken the claim.

Correlation: pre-game form vs margin

python
required = {"pre_form_diff", "point_diff"}
missing = required.difference(panel.columns)
if missing:
    raise ValueError(f"build and join legal pre-game form columns first: {sorted(missing)}")
feat = panel.dropna(subset=["pre_form_diff", "point_diff"])
print(pg.corr(feat["pre_form_diff"], feat["point_diff"], method="pearson"))
print(pg.corr(feat["pre_form_diff"], feat["point_diff"], method="spearman"))

The example assumes pre_form_diff was created outside this skill with an as-of/shifted feature workflow such as time-series-sports; no bundled add_pregame_form_features function exists.

Always state that observational sports associations are not automatically causal.


Reporting Templates (Sports)

Predictive logistic win model

text
Question: Pre-game P(team win) on NFL team-game panel, seasons S0–S1.
Unit: team-game. Decision time: scheduled kickoff.
Model: logistic GLM with HC3 SE.
Formula: won ~ is_home + rating_diff + pre_form_diff
Features: all declared pre-event predictors, with construction and as-of timing documented.
Validation: walk-forward by season; train on past seasons only.
Baselines: constant train win rate; home-only logistic optional.
Results: mean walk-forward log-loss = X.XXX vs constant Y.YYY; accuracy Z.ZZ.
Coefficients (train window): is_home OR=… (95% CI …); …
Diagnostics: …; calibration: …
Limits: no opponent-adjusted EPA; roster/injury not modeled; team renames handled by raw abbreviations.

Explanatory home-advantage estimate

text
Question: Mean home margin in NFL seasons …
Design: home rows only (one row per game).
Analysis: game-weighted mean point_diff; season-block bootstrap (or another
dependence-aware method justified from the design); 95% interval.
Assumptions: one row per game; cluster definition and number of clusters stated.
Result: M=…, SD=…, dependence-aware 95% CI ….
Limits: era/rule confounds; not a causal estimate of venue alone.

APA-style general templates: references/reporting_standards.md.


Integrity Rules

  1. Commit the model family before peeking at test folds.
  2. Do not drop awkward seasons after seeing metrics.
  3. Always beat a dumb baseline before claiming value.
  4. Never use same-game score components as predictors for pre-game models.
  5. Separate exploratory coefficient fishing from confirmatory walk-forward evaluation.
  6. Report failures and non-improvements.
  7. Distinguish confirmatory from exploratory analyses (see statistical integrity notes in references).
  8. Make it reproducible — seasons, formula, package versions, seeds.

Bundled Resources

references/

FileContents
sports_glm_guide.mdSports outcome → GLM family map and formulas
diagnostics_checklist.mdSports-specific diagnostic checklist
test_selection_guide.mdFull test selection tree (group comparisons, etc.)
assumptions_and_diagnostics.mdDeep assumption checking guidance
effect_sizes_and_power.mdEffect sizes, CIs, power analysis
bayesian_statistics.mdPriors, hierarchical Bayes, diagnostics
reporting_standards.mdComplete reporting standards and templates

scripts/

FileContents
assumption_checks.pyNormality, IQR outliers, and optional Levene variance check on a supplied column
glm_diagnostics.pyFit an additive logistic GLM on a user-owned table; export OR, intervals, and calibration JSON

Related Skills

NeedGo to
Deeper EDA firsteda-sports
Feature legalityfeature-rules / leakage-audit
Nonlinear ML comparisonpredictive-modeling
Ratings instead of covariatesratings-strength-models
Probability reliabilitycalibration-check
Write-upresults-reporting / model-card
Baselines ladderbaseline-models
Validation designvalidation-design

Quick Command Card

bash
python /path/to/statistical-modeling/scripts/assumption_checks.py \
  --input observations.csv --value-col margin --group-col venue \
  --out assumptions.json

python /path/to/statistical-modeling/scripts/glm_diagnostics.py \
  --input model_frame.csv \
  --formula "won ~ is_home + rating_diff + rest_diff" \
  --out glm_report.json

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Statistical Modeling làm được gì?

Hướng dẫn mô hình hóa thống kê cho dữ liệu thể thao do người dùng cung cấp: chọn mô hình cho kết quả nhị phân, liên tục và đếm; kiểm tra giả định; kích thước hiệu ứng; suy luận có xét đến thời gian; chẩn đoán GLM; và báo cáo đầy đủ.

Vì sao nên dùng Statistical Modeling trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Statistical Modeling là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Statistical Modeling trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/WalrusQuant/sports-analytic-skills/tree/main/skills/statistical-modeling. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Statistical Modeling?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Statistical Modeling với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Statistical Modeling với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Statistical Modeling có miễn phí không?

Có. Kỹ năng này được WalrusQuant phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇