本文へ移動
cccskills
無料GitHub で公開

r-stats

R statistical modeling with base stats, sandwich, lmtest, car, broom. OLS/WLS/ GLS via lm(), GLMs via glm() (logit, probit, Poisson, negative binomial), robust/clustered SEs via sandwich+lmtest, diagnostics via car, tidy output via broom. Use when execution language is R. Python equivalent: statsmodels. For FE regressions use fixest; for panel RE/between use plm; for complex surveys use survey-r.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daafスター 238(GitHub 238 + cccskills 0)

実行スコア 未検証

インストール方法を見る

含まれるファイル(9)

  • SKILL.md17.5 KB
  • references/diagnostics.md11.8 KB
  • references/glm.md13.1 KB
  • references/gotchas.md13.9 KB
  • references/quickstart.md13.5 KB
  • references/reporting.md10.9 KB
  • references/robust-se.md10.1 KB
  • references/tests.md8.7 KB
  • references/time-series.md9.3 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

R Stats Skill

R's statistical modeling ecosystem centered on base stats with key extension packages: sandwich for robust/clustered variance estimators, lmtest for coefficient testing with custom covariance matrices, car for regression diagnostics and hypothesis tests, broom for tidy model output, and MASS for negative binomial regression. Covers OLS/WLS/GLS via lm(), GLMs via glm() (logit, probit, Poisson, negative binomial, Gamma), robust and clustered standard errors via sandwich+lmtest, diagnostics (VIF, heteroskedasticity tests, normality tests), tidy output via broom, and classical hypothesis tests (t, chi-squared, Wilcoxon, Fisher). Use when execution language is R and the model does not require absorbed fixed effects or panel structure. Python equivalent: statsmodels. For fixed effects regressions use fixest; for panel RE/between/Fama-MacBeth use plm; for complex survey designs use survey-r.

What is R Stats?

R is the original statistical computing environment. The stats package ships with every R installation and provides the core modeling functions that the entire R ecosystem builds upon:

  • Formula interface: y ~ x1 + x2 — the original formula syntax that Python libraries (patsy, formulaic) later adopted
  • Linear models: lm() for OLS, WLS, GLS; summary(), confint(), predict(), anova() for post-estimation
  • Generalized linear models: glm() with family/link specifications (binomial/logit, Poisson/log, Gamma/inverse, etc.)
  • Classical tests: t.test(), chisq.test(), wilcox.test(), fisher.test(), prop.test(), ks.test(), cor.test()
  • Time series: ts(), arima(), acf(), pacf(), stl()

The extension packages covered by this skill complete the modeling toolkit:

PackageVersionRole
sandwich3.1-1Robust (HC0-HC4) and clustered variance-covariance estimators
lmtest0.9-40coeftest() with custom vcov; bptest(), dwtest(), bgtest()
car3.1-5vif(), linearHypothesis(), ncvTest(), Anova (type II/III)
broom1.0.12tidy(), glance(), augment() for tidy model output
MASS7.3-65glm.nb() for negative binomial; stepAIC()
modelsummary2.6.0Publication-quality regression tables (multiple models)
marginaleffects0.32.0Average marginal effects, contrasts, predictions

Version Notes

  • R 4.5.3: Base R stats included. The |> native pipe (R 4.1+) is the preferred pipe style in DAAF scripts (not magrittr %>%).
  • sandwich 3.1-1: vcovHC types HC0-HC4, vcovCL for clustering, vcovHAC for time series, vcovBS for bootstrap.
  • lmtest 0.9-40: coeftest(), waldtest(), bptest(), dwtest(), bgtest(), resettest(), grangertest().
  • car 3.1-5: vif(), linearHypothesis(), Anova() type II/III, ncvTest(), influencePlot().
  • broom 1.0.12: Tidiers for 100+ model classes including lm, glm, nls, t.test, and many extension package models.
  • MASS 7.3-65: Ships with R. glm.nb() for negative binomial, polr() for ordered logit/probit, rlm() for robust regression.
  • modelsummary 2.6.0: Supports lm, glm, fixest, plm, and many other model classes. Output formats: markdown, LaTeX, HTML, Word, PNG.
  • marginaleffects 0.32.0: avg_slopes(), avg_comparisons(), avg_predictions(), hypotheses() for delta-method inference.

How to Use This Skill

Reference File Structure

FilePurposeWhen to Read
quickstart.mdlm() basics, summary(), confint(), predict(), formula syntaxStarting with R stats or need formula reference
glm.mdglm() families, MASS::glm.nb(), link functions, deviance, overdispersionNon-linear models, binary/count outcomes
robust-se.mdsandwich vcovHC/vcovCL/vcovHAC, lmtest coeftest()Robust or clustered standard errors
diagnostics.mdcar::vif(), linearHypothesis(), residual analysis, heteroskedasticity testsChecking model assumptions
reporting.mdbroom tidy/glance/augment, modelsummary, marginaleffectsTidy output, publication tables, marginal effects
tests.mdt.test(), chisq.test(), wilcox.test(), fisher.test(), correlation testsClassical hypothesis tests
time-series.mdts objects, arima(), acf/pacf, Durbin-Watson, ADF testTime series analysis
gotchas.mdFormula pitfalls, factor contrasts, na.action, predict() type argDebugging common issues

Reading Order

  1. New to R stats? Start with quickstart.md then robust-se.md
  2. Need GLM or logit/probit? Read quickstart.md then glm.md
  3. Need robust or clustered SEs? Read robust-se.md
  4. Checking model assumptions? Read diagnostics.md
  5. Building publication tables? Read reporting.md
  6. Coming from Python? Read quickstart.md (R is the original formula syntax)

The reference-file routing in this skill applies to advisory and brainstorming turns as much as implementation. Recommending a model, reviewing an analysis plan, or answering a question that touches a routed topic calls for reading the routed reference file just as much as writing code does — the reference files carry curated caveats and environment-specific constraints (e.g., which packages are pre-installed, sandwich function signatures) that this overview and general knowledge lack.

Related Skills

  • statsmodels: Python equivalent for OLS/GLM/time series. If execution language is Python, use statsmodels instead of r-stats. API patterns differ (statsmodels requires .fit() call; R returns fitted object from lm() directly)
  • fixest: Use instead of base R stats when model needs absorbed fixed effects, IV with FE, or DiD. fixest is faster for FE models; base R stats is broader for GLMs and classical tests
  • plm: Use for panel data models (FE within, RE, between, first difference, Fama-MacBeth). plm extends the lm/formula interface for panel structure
  • survey-r: Use for survey-weighted regression with complex designs. Base R lm() with weights is NOT equivalent to survey-weighted regression — it does not account for stratification, clustering, or finite population corrections
  • gt: Publication-quality tables with gt and modelsummary. Load for formatted regression output beyond what broom provides -- modelsummary (covered in this skill's reporting.md) uses gt as its default backend
  • data-scientist: Provides methodology guidance (when to use which model, assumption checking protocol). Load alongside r-stats for the "why"; r-stats provides the "how"
  • r-python-translation: Cross-language reference mapping R stats functions to Python equivalents. Load when annotating R code for Python-background users

Quick Decision Trees

"I need to fit a regression model"

What kind of regression?
+-- Linear (continuous outcome)
|   +-- Basic OLS --> ./references/quickstart.md
|   +-- Weighted least squares --> ./references/quickstart.md (WLS section)
|   |   (WLS != survey-weighted regression -- for complex surveys, use survey-r)
|   +-- Robust to outliers (M-estimator) --> MASS::rlm() in ./references/quickstart.md
|   +-- Quantile regression --> quantreg::rq() (external package)
|   +-- Need fixed effects?
|       +-- Use fixest instead (faster FE absorption)
+-- Binary outcome (0/1)
|   +-- Logit --> ./references/glm.md
|   +-- Probit --> ./references/glm.md
+-- Count outcome (0, 1, 2, ...)
|   +-- Poisson --> ./references/glm.md
|   +-- Negative binomial --> ./references/glm.md (MASS::glm.nb)
|   +-- Zero-inflated --> pscl package (external)
+-- Ordinal (ordered categories)
|   +-- MASS::polr() --> ./references/glm.md
+-- GLM (custom family/link)
|   +-- glm() framework --> ./references/glm.md
+-- Need robust/clustered SEs?
    +-- sandwich + lmtest --> ./references/robust-se.md

"I need to check model assumptions"

What assumption to check?
+-- Heteroskedasticity --> ./references/diagnostics.md
|   +-- Breusch-Pagan (lmtest::bptest)
|   +-- NCV test (car::ncvTest)
+-- Normality of residuals --> ./references/diagnostics.md
|   +-- Shapiro-Wilk (shapiro.test)
|   +-- Jarque-Bera (tseries::jarque.bera.test)
+-- Multicollinearity --> ./references/diagnostics.md
|   +-- VIF (car::vif)
+-- Specification / functional form --> ./references/diagnostics.md
|   +-- RESET test (lmtest::resettest)
+-- Serial correlation --> ./references/diagnostics.md
|   +-- Durbin-Watson (lmtest::dwtest)
|   +-- Breusch-Godfrey (lmtest::bgtest)
+-- Joint hypothesis test --> ./references/diagnostics.md
|   +-- car::linearHypothesis
+-- Influential observations --> ./references/diagnostics.md
    +-- Cook's distance, leverage, DFBETAS

"I need classical hypothesis tests"

What test?
+-- Compare two means --> ./references/tests.md
|   +-- t.test() (parametric)
|   +-- wilcox.test() (non-parametric)
+-- Compare proportions --> ./references/tests.md
|   +-- prop.test()
+-- Test independence --> ./references/tests.md
|   +-- chisq.test() (large sample)
|   +-- fisher.test() (exact, small sample)
+-- Test correlation --> ./references/tests.md
|   +-- cor.test() (Pearson, Spearman, Kendall)
+-- Goodness of fit --> ./references/tests.md
|   +-- chisq.test() with expected frequencies
|   +-- ks.test() (Kolmogorov-Smirnov)

"Something isn't working"

Common issues?
+-- Formula I() for arithmetic --> ./references/gotchas.md
+-- Factor contrasts (treatment vs sum) --> ./references/gotchas.md
+-- predict() type argument --> ./references/gotchas.md
+-- na.action behavior --> ./references/gotchas.md
+-- summary() vs anova() --> ./references/gotchas.md
+-- Convergence warnings (GLM) --> ./references/gotchas.md
+-- r-stats vs fixest boundary --> ./references/gotchas.md

File-First Execution in Research Workflows

Important: In data research pipelines (see CLAUDE.md), R analyses are executed through script files, not interactively. This ensures auditability and reproducibility.

The pattern:

  1. Write model code to scripts/stage8_analysis/{step}_{model-name}.R
  2. Execute via Bash with automatic output capture wrapper script
  3. Validation results get automatically embedded in scripts as comments
  4. If failed, create versioned copy for fixes

Closely read agent_reference/SCRIPT_EXECUTION_REFERENCE.md for the mandatory file-first execution protocol covering complete code file writing, output capture, and file versioning rules.

See:

  • agent_reference/SCRIPT_EXECUTION_REFERENCE.md -- Script execution protocol and format with validation

The examples below show R syntax. In research workflows, wrap them in scripts following the file-first pattern.


Quick Reference

Essential Library Loading

# --- Config ---
library(sandwich)         # Robust variance estimators
library(lmtest)           # Coefficient testing with custom vcov
library(car)              # Diagnostics: VIF, linearHypothesis
library(broom)            # Tidy model output
library(MASS)             # glm.nb(), polr(), rlm()
library(modelsummary)     # Publication tables
library(marginaleffects)  # Marginal effects

Core Operations

OperationCode
OLSlm(y ~ x1 + x2, data = df)
WLSlm(y ~ x1 + x2, data = df, weights = w)
Logitglm(y ~ x1 + x2, data = df, family = binomial)
Probitglm(y ~ x1 + x2, data = df, family = binomial(link = "probit"))
Poissonglm(count ~ x1 + x2, data = df, family = poisson)
Neg. binomialMASS::glm.nb(count ~ x1 + x2, data = df)
Gammaglm(y ~ x1 + x2, data = df, family = Gamma(link = "log"))
Robust SE (HC1)coeftest(fit, vcov = vcovHC(fit, type = "HC1"))
Clustered SEcoeftest(fit, vcov = vcovCL(fit, cluster = df$group))
Summarysummary(fit)
Tidy outputbroom::tidy(fit, conf.int = TRUE)
Model statsbroom::glance(fit)
Predictpredict(fit, newdata = new_df)
Confidence intervalsconfint(fit)
VIFcar::vif(fit)
Joint hypothesiscar::linearHypothesis(fit, c("x1 = 0", "x2 = 0"))
Marginal effectsmarginaleffects::avg_slopes(fit)
Pub tablemodelsummary::modelsummary(list(fit1, fit2))

Formula Syntax

# Additive terms
y ~ x1 + x2 + x3

# Interaction (with main effects)
y ~ x1 * x2           # equivalent to x1 + x2 + x1:x2

# Interaction only (no main effects)
y ~ x1 : x2

# Factor variable (explicit)
y ~ factor(region)

# Suppress intercept
y ~ x1 + x2 - 1       # or: y ~ 0 + x1 + x2

# Polynomial: I() protects arithmetic operators
y ~ x1 + I(x1^2)

# Log transformation
y ~ log(income) + age

# All pairwise interactions
y ~ (x1 + x2 + x3)^2

Topic Index

TopicReference File
lm() basics./references/quickstart.md
Formula syntax./references/quickstart.md
summary() output./references/quickstart.md
confint()./references/quickstart.md
predict()./references/quickstart.md
WLS / weighted regression./references/quickstart.md
Model matrix / design matrix./references/quickstart.md
anova() vs summary()./references/quickstart.md
Comparison to statsmodels./references/quickstart.md
glm() framework./references/glm.md
Logit / probit./references/glm.md
Poisson regression./references/glm.md
Negative binomial (MASS)./references/glm.md
Ordered logit/probit (MASS)./references/glm.md
GLM families and links./references/glm.md
Deviance and overdispersion./references/glm.md
Odds ratios and IRR./references/glm.md
Marginal effects./references/reporting.md
Robust SEs (HC0-HC4)./references/robust-se.md
Clustered SEs./references/robust-se.md
HAC / Newey-West SEs./references/robust-se.md
Bootstrap SEs./references/robust-se.md
coeftest()./references/robust-se.md
waldtest()./references/robust-se.md
VIF / multicollinearity./references/diagnostics.md
Breusch-Pagan test./references/diagnostics.md
NCV test./references/diagnostics.md
Shapiro-Wilk test./references/diagnostics.md
RESET test./references/diagnostics.md
Durbin-Watson test./references/diagnostics.md
Breusch-Godfrey test./references/diagnostics.md
linearHypothesis()./references/diagnostics.md
Cook's distance./references/diagnostics.md
Influence plots./references/diagnostics.md
Residual analysis./references/diagnostics.md
broom::tidy()./references/reporting.md
broom::glance()./references/reporting.md
broom::augment()./references/reporting.md
modelsummary tables./references/reporting.md
marginaleffects./references/reporting.md
t.test()./references/tests.md
chisq.test()./references/tests.md
wilcox.test()./references/tests.md
fisher.test()./references/tests.md
prop.test()./references/tests.md
ks.test()./references/tests.md
cor.test()./references/tests.md
ts objects./references/time-series.md
arima()./references/time-series.md
acf / pacf./references/time-series.md
Durbin-Watson (time series)./references/time-series.md
ADF test./references/time-series.md
Formula pitfalls (I())./references/gotchas.md
Factor contrasts./references/gotchas.md
na.action behavior./references/gotchas.md
predict() type argument./references/gotchas.md
Convergence warnings./references/gotchas.md
r-stats vs fixest boundary./references/gotchas.md

Citation

When base R stats functions are used as a primary analytical tool, include in the report's Software & Tools references:

R Core Team (2026). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/

For extension packages, cite when they contribute substantially to the analysis:

Zeileis, A. (2004). "Econometric Computing with HC and HAC Covariance Matrix Estimators." Journal of Statistical Software, 11(10), 1-17. (sandwich package)

Zeileis, A. & Hothorn, T. (2002). "Diagnostic Checking in Regression Relationships." R News, 2(3), 7-10. (lmtest package)

Fox, J. & Weisberg, S. (2019). An R Companion to Applied Regression, Third Edition. Sage, Thousand Oaks CA. (car package)

Robinson, D., Hayes, A., & Couch, S. (2023). broom: Convert Statistical Objects into Tidy Tibbles. R package. (broom package)

Arel-Bundock, V. (2022). "modelsummary: Data and Model Summaries in R." Journal of Statistical Software, 103(1), 1-23. (modelsummary package)

Arel-Bundock, V., Greifer, N., & Heiss, A. (2024). "How to Interpret Statistical Models Using marginaleffects for R and Python." Journal of Statistical Software, 111(9), 1-32. (marginaleffects package)

Cite when: The package's functions are central to the analytical approach (e.g., sandwich for robust inference, car for diagnostics). Do not cite when: Only used incidentally for output formatting.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

Guide for creating DAAF agent definition files. Covers 12-section template, hook registration, skills-in-frontmatter, integration checklist. Use when adding or revising agents. For SKILL.md files, use skill-authoring instead.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Researcher-facing analytic triangulation ("creative verification") for stress-testing provisional findings and designing pre-specified challenges before an analysis runs. Turns a researcher's concern or focal claim into competing explanations, bounded discriminating tests, audited diagnostic artifacts, and evidence-calibrated interpretations in a hypothesis/evidence ledger — behavioral, output-level verification replacing line-by-line code review. Covers 12 challenge families organized by Shadish-Cook-Campbell validity type, named sensitivity statistics, pre-committed interpretation rules, anti-fishing guardrails, and interactive diagnostic-artifact QA. Use in Ad Hoc Collaboration to verify, challenge, or stress-test a result, or to design discriminating tests before an analysis runs. Not code-change verification (verify skill / code review) and not final adjudication or re-execution (data-verifier, Reproducibility Verification) — prospective, hypothesis-driven challenge design of analytic claims.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

In-situ smoke testing that verifies a LIVE DAAF deployment functions end-to-end in whatever provider route it is configured for. Auto-detects the active install route (anthropic-subscription, openrouter, chatgpt-subscription shim, openai-api shim) and runs tiered probes: Tier 0 free preflight (route/env coherence, hooks, statuslines, shim health); Tier 1 one live round-trip (~cents); Tier 2 a six-probe functional battery (dispatch, coding, web, skill loading, isolation-strip, nested-dispatch deny); Tier D a zero-cost deterministic battery (bats, Pester, lint, safety-hook tests). Use after install, after a rebuild or update, after any provider/config change (new API key, model remap, shim change), for pre-release validation, or when asked "is my install working" or to "smoke test the deployment/config." Requires the DAAF_DEV=1 dev image; a contributor tool, not end-user-facing. NOT DAAFBench (model behavioral-adherence evaluation under benchmarks/) and NOT scripts/smoke_tests/ (R/Python library-package smoke tests).

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Operational framework for the DAAF orchestrator. Defines engagement modes, confirmation protocol, subagent dispatch, context budget, and reference-loading. Loaded exclusively by the orchestrator — not for subagents or user questions.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Data science methodology and method-selection routing for quantitative research. Covers EDA, data validation, descriptive analysis, causal inference (IV, DiD, RD, synthetic control), clustering/PCA/UMAP, supervised ML, geospatial analysis, network analysis, and visualization design. Contains the canonical method-to-library routing tree, routed by execution language — Python: statsmodels (OLS/GLM/time series), pyfixest (FE/DiD), linearmodels (RE/GMM/SUR), svy (complex surveys), scikit-learn (clustering/prediction ML), geopandas (spatial), igraph (network analysis); R: r-stats (OLS/GLM/time series), fixest (FE/DiD), plm (panel/RE/IV), survey-r (complex surveys), tidymodels (ML), sf-terra (spatial), igraph-r (network analysis). Load the routed tool-specific skill before giving tool-specific advice or writing code — library skills encode environment constraints and curated caveats absent from general knowledge.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

Interpretation guidance for Urban Institute Education Data Portal datasets. The Portal is a curation layer over federal data: lowercase variable names, integer-encoded categoricals, standardized missing codes (-1 missing, -2 not applicable, -3 suppressed). Covers year definitions, grade encoding (grade=-1 is Pre-K, not missing), suppression rates, ODC-By licensing, and cross-source join identifiers. Load before analyzing any Portal data. Routes to source-specific deep-dive skills for individual datasets.

日本語の概要は準備中です。原文の説明を表示しています。

DAAF-Contribution-Community/daaf2382026年10月17日 更新

DAAF-Contribution-Community のスキルをすべて見る

このスキルの問題を報告する