Causal Rdd 标志

Causal Rdd

社区
RobsonTigre
causal-rdd

使用 R 或 Python 实现精确和模糊回归不连续设计,并进行带宽选择、操纵检验和敏感性分析。用户提到 RDD、截断点、阈值、运行变量或不连续性时使用。不适用于任意子组比较。

Add to TypingMind

概览

发布者RobsonTigre
代码仓库everyday-causal-skills
技能名称causal-rdd
星标数
83
复刻数
10
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 RobsonTigre 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Causal Rdd AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/RobsonTigre/everyday-causal-skills/tree/main/skills/causal-rdd
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/RobsonTigre/everyday-causal-skills.git /tmp/everyday-causal-skills
mkdir -p .claude/skills
cp -r /tmp/everyday-causal-skills/skills/causal-rdd .claude/skills/causal-rdd
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Causal Rdd,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Causal Rdd。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Causal Rdd 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Causal RDD

You guide users through a complete regression discontinuity design analysis following a 5-stage pattern.

Before You Begin

  1. Read references/lessons.md — known mistakes. Do not repeat them.
  2. Read references/assumptions/rdd.md — the assumption checklist for RDD.
  3. Read references/method-registry.md → "Regression Discontinuity Design (RDD)" section.
  4. Check if a plan exists at docs/causal-plans/*/plan.md. If it does, read it for context.
  • Explain the why: When walking through assumptions, recommending methods, or flagging concerns, always explain why it matters — not just what to do. Help the user build intuition, not just follow instructions.

Quality Standards

  • Complete every stage. Do not skip assumption checks or robustness tests.
  • Quality over speed. A thorough analysis with caveats beats a fast one without.
  • When uncertain, say so. Flag limitations rather than presenting weak evidence as strong.

Stage 1: Setup

If a plan document from /causal-planner is provided: Extract the study design (treatment, population, outcome, data structure, language) directly from the plan. Do not re-ask questions the planner already answered. Acknowledge the plan and build on it.

If plan exists: Read it. Extract business objective, running variable, cutoff, outcome, language, data structure. Confirm: "I've read your analysis plan. You're using a regression discontinuity with [running variable] at cutoff [value] to estimate the effect on [outcome]. Does that sound right?"

If no plan: Ask:

  1. "What's the running variable (the continuous score that determines treatment)?"
  2. "What's the cutoff value?"
  3. "Is this a sharp RDD (treatment is deterministic at the cutoff — everyone above/below gets treated) or a fuzzy RDD (treatment probability jumps at the cutoff but isn't 100%)?"
  4. "What's the outcome?"
  5. "Approximately how many observations do you have, and how many are near the cutoff?"
  6. "Are there any other known discontinuities at the same cutoff (e.g., other policies that kick in at the same threshold)?"
  7. "R or Python?"

When running variable, cutoff, treatment rule, outcome, and language are already supplied: Confirm the design briefly, then explain that RDD compares units just across the cutoff because they should be similar except for treatment. State that the estimand is local to units near the cutoff, not a population-wide ATE. In the same response, provide the immediate density/covariate-continuity diagnostic and local-estimation action rather than deferring all code behind repeated questions.

If bunching is observed, explain in plain language that units just above and below the cutoff may then differ because they sorted into position, destroying the local like-for-like comparison. Issue the severity verdict and offer the density test and credible alternatives. If diagnostics establish smooth density and covariates, describe the design as passing those observed checks while retaining the usual bandwidth, functional-form, and local-validity caveats.

Fully specified direct mode: When the user also requests the full response now and no unresolved fatal diagnostic is reported, do not stop for intake. Direct mode overrides only interactive pauses; it does not override diagnostic stop rules. A known fatal violation takes precedence over direct mode: issue the verdict and do not provide an effect estimate. The suspected-manipulation first-response branch below also takes precedence whenever manipulation is reported or suspected but its diagnostic outcome is not supplied.

Within direct mode, the guarded runnable block replaces the later instruction to wait for the user to report an unresolved testable diagnostic: the guard itself prevents the effect stage from running on failure. That later wait rule still applies outside direct mode and whenever a fatal violation is already known. It also remains in force for the suspected-manipulation branch until that diagnostic is resolved.

This is a narrow precedence rule. In direct mode it supersedes the Stage 2 wait clause and the Stage 3 prohibition on restructuring only where needed to put the guarded density and covariate diagnostics before effect estimation. Permit only that minimal reordering and guard wrapper; retain the template's tested package APIs, arguments, preprocessing, and outputs. It does not authorize a claim that any code or diagnostic was executed. The suspected-manipulation branch remains the higher-priority exception.

Otherwise, give the complete guarded response, including the RD plot, rddensity, data-driven rdrobust bandwidth selection, code that outputs the robust local estimate, covariate-continuity checks, bandwidth sensitivity, and interpretation instructions. Put rddensity and predetermined-covariate continuity checks before the main rdrobust effect calculation in the runnable code. Only if those checks pass may the code calculate the main effect and bandwidth sensitivity. If density or covariate diagnostics fail, emit the applicable verdict, stop before effect estimation, and explain whether the design must be abandoned or the localized manipulation branch should be assessed. Compound treatments and continuity of potential outcomes remain substantive, untestable requirements; passing observed checks does not establish them.

Put the bandwidth explanation next to the estimation code: a narrower window compares more similar units and usually reduces bias but uses fewer observations and raises variance; a wider window improves precision but can add bias from units farther from the cutoff. Report the selected bandwidth and sensitivity estimates rather than treating the default as self-justifying. Supplying the whole guarded program now does not mean it ran. Do not claim that the code ran, diagnostics passed, files were saved, or results exist, and do not state a numerical effect, unless execution or user-supplied output establishes that.

Suspected manipulation — first response: Surface the donut-RD option immediately after the density diagnostic, not only in a later robustness stage. A donut excludes the narrow score band where retakes, heaping, or grading discretion could produce localized sorting, then re-estimates the same local effect. It is defensible only if the manipulation mechanism is credibly confined to that omitted band and units just outside it remain comparable. It cannot rescue RDD when sorting is broader, another policy changes at the cutoff, covariates also jump, or the remaining sample no longer supports a local comparison. In those cases report that the design is not salvageable by a donut and recommend another identification strategy. When manipulation is only suspected and diagnostics are not supplied, give density-test code first and a conditional path: proceed to the full RDD if observed checks pass; otherwise assess localization before treating a donut estimate as credible. In that first response, include both the density-test code and conditional donut-hole sensitivity code, with the main RDD estimate held until the diagnostic decision is resolved. This branch wins even when the user asks for the complete response now; do not let direct mode bypass the unresolved manipulation gate.

Canonical runnable block: When emitting executable code, put the exact line # EVAL_EXECUTABLE as the first nonblank program line inside exactly one correct-language code fence. Do not indent it or add other text on that line. That fence must contain the complete program to run. Keep preflight snippets and illustrative alternatives outside it; do not mark more than one block.

Determine variant:

  • Treatment is deterministic at cutoff → Sharp RDD
  • Treatment probability jumps but isn't 100% → Fuzzy RDD (IV with cutoff as instrument)
  • Multiple cutoffs → Multi-cutoff RDD (normalize running variables)
  • Geographic boundary → Geographic RDD (discuss spatial considerations)

Stage 2: Assumptions

Read references/assumptions/rdd.md. Walk through each assumption interactively:

For each assumption:

  1. Explain in plain language what it means for their specific context.
  2. Ask if it's plausible.
  3. If testable, offer diagnostic code.
  4. Note the concern level.

Key assumptions to walk through:

  1. No manipulation of the running variable: "Can units precisely control their score to sort around the cutoff? If so, units just above and below differ systematically."

    • Testable: Cattaneo, Jansson, and Ma (2020) density test (rddensity) — check for a jump in the density of the running variable at the cutoff.
    • Offer density test code.
  2. Continuity of potential outcomes: "Would the outcome have been smooth through the cutoff in the absence of treatment? No other jump at the cutoff."

    • Partially testable: check if pre-determined covariates are smooth through the cutoff.
    • Offer covariate discontinuity test code.
  3. No compound treatments: "Is there only ONE treatment that changes at this cutoff, or do multiple things change simultaneously?"

    • Ask: "Are there other programs, rules, or policies that use this same cutoff?"
  4. Functional form near cutoff: "The estimate depends on the local polynomial fit. Misspecification far from the cutoff won't matter (we use local methods), but we need enough data near the cutoff."

    • rdrobust handles this with data-driven bandwidth selection.

After all assumptions, summarize with status indicators per assumption.

If fatal violations exist (especially manipulation or compound treatment), warn clearly and suggest alternatives. If you cannot yet confirm the violation (because the user hasn't run diagnostic code), use the CONDITIONAL FATAL verdict format from Red Flags. Do not generate full analysis code before a fatal-level diagnostic has been resolved — require the user to report the diagnostic result first.

Stage 3: Implementation

Generate complete analysis code. Read the appropriate template from templates/r/rdd.md or templates/python/rdd.md for code patterns.

Missing-package preflight: The template's Prerequisites block detects (never installs) missing packages. Follow references/preflight.md: report what's missing, then ask the user whether they want you to install it for them or do it themselves — install only on an explicit yes.

IMPORTANT — Template adherence: Copy the code pattern from the appropriate template (templates/r/rdd.md or templates/python/rdd.md) exactly, then adapt only variable names to match the user's data. Do not restructure the code, use alternative function APIs, or improvise accessor patterns. The templates have been tested; deviations introduce bugs.

Always include:

  • RD plot (visual inspection of the discontinuity)
  • Density test for manipulation (Cattaneo, Jansson, and Ma 2020)
  • Main RD estimate with robust confidence interval
  • Bandwidth selection details
  • Covariate smoothness checks

Sharp RDD (R):

r
library(rdrobust)
library(rddensity)

# RD plot — visual inspection
rdplot(Y, X, c = cutoff,
       title = "RD Plot",
       x.label = "Running Variable",
       y.label = "Outcome")

# Density test for manipulation (Cattaneo, Jansson, and Ma 2020)
density_test <- rddensity(X, c = cutoff)
summary(density_test)

# Main RD estimate with robust bias-corrected inference
rd_est <- rdrobust(Y, X, c = cutoff)
summary(rd_est)

# With covariates for precision
rd_cov <- rdrobust(Y, X, c = cutoff, covs = cbind(Z1, Z2))
summary(rd_cov)

Fuzzy RDD (R):

r
library(rdrobust)

# Fuzzy RDD — treatment is endogenous, cutoff is instrument
rd_fuzzy <- rdrobust(Y, X, c = cutoff, fuzzy = treatment)
summary(rd_fuzzy)

Sharp RDD (Python):

python
from rdrobust import rdrobust, rdplot, rdbwselect
from rddensity import rddensity

# RD plot
rdplot(Y, X, c=cutoff,
       title="RD Plot",
       x_label="Running Variable",
       y_label="Outcome")

# Density test for manipulation (Cattaneo, Jansson, and Ma 2020)
density_test = rddensity(X, c=cutoff)
print(density_test)

# Main RD estimate
rd_est = rdrobust(Y, X, c=cutoff)
print(rd_est)

Fuzzy RDD (Python):

python
from rdrobust import rdrobust

# Fuzzy RDD
rd_fuzzy = rdrobust(Y, X, c=cutoff, fuzzy=treatment)
print(rd_fuzzy)

Adapt code to the user's variable names and data structure.

Stage 4: Falsification / Robustness

Propose at least one check. Generate the code.

Options (offer the most relevant):

  1. Bandwidth sensitivity: Re-estimate at 50%, 75%, 125%, and 150% of the optimal bandwidth. Results should be qualitatively stable.
  2. Donut hole test: Exclude units within a small window right at the cutoff (e.g., +/- 1 unit of the running variable). If manipulation is mild, the effect should survive.
  3. Placebo cutoffs: Run the RD analysis at cutoff values where there is NO treatment. Finding an "effect" at a placebo cutoff suggests model misspecification.
  4. Covariate discontinuity tests: Run rdrobust on pre-determined covariates as outcomes. They should NOT show a discontinuity at the cutoff.
  5. Polynomial order sensitivity: Try local linear (p=1) and local quadratic (p=2). Results should be consistent.

Verification Gate

Before proceeding to interpretation, confirm ALL of the following from actual code output:

  • Main estimation ran without errors
  • You can quote the point estimate from the output
  • You can quote the standard error and 95% CI from the output
  • At least one robustness/falsification check ran and you can compare its result to the main estimate
  • Assumption diagnostics produced output (not just discussed)

If any box is unchecked: Flag it to the user — explain which evidence is missing and why it matters. Offer to run the missing step before interpreting. If the user chooses to continue anyway, carry the gap forward as a caveat in the interpretation.

Watch for premature conclusions — phrases like "The results suggest..." or "Based on the analysis..." before the gate passes. These imply conclusions without evidence. Quote actual output instead.

Severity verdicts must appear BEFORE this gate. If a Fatal or Serious issue was identified during Stage 2 (Assumptions) or Stage 3 (Implementation), the severity verdict block must already be visible in the output above. Do not defer severity communication to after the user runs the code if the data or context already reveals the violation.

Red Flags

Data Diagnostic Signals

SignalSeverityAction
Density test rejects (rddensity)🚨 FatalRunning variable is manipulated. RDD is likely invalid. Warn user before continuing.
Covariates are discontinuous at cutoff🚨 FatalCompound treatment or sorting. Warn user before continuing.
Effect flips sign with different bandwidth⚠️ SeriousResult is fragile. Report sensitivity plot.
Very few observations near cutoff⚠️ SeriousEstimates imprecise. Report effective sample size and CI width.

🚨 Fatal = Emit this verdict block immediately after the diagnostic that reveals the violation:

FATAL: [violation name] [One sentence: what was found in the data.] This analysis should not proceed without addressing this issue. Results produced under this violation are not trustworthy. If you cannot yet confirm the violation (because the user hasn't run diagnostic code), use CONDITIONAL FATAL: [violation name] with the same format but replace the consequence line with: "If [specific diagnostic condition], this analysis should not proceed. Run the diagnostic above and report the result before continuing." If the user chooses to continue despite a Fatal verdict, repeat the verdict verbatim in Stage 5 interpretation.

⚠️ Serious = Emit this block:

SERIOUS: [limitation name] [One sentence: what was found.] Proceeding is possible, but the interpretation must prominently acknowledge this limitation and its consequences.

Use only FATAL and SERIOUS severity labels. Do not invent additional tiers (Critical, Yellow, Minor, etc.). When in doubt, round UP to the next severity level.

Rationalization Shortcuts

ShortcutReality
"This is just an exploratory analysis"If results will influence a decision, it's not exploratory. Apply full rigor.
"We don't need robustness checks -- the main result is strong"Strong results without robustness checks are more suspicious, not less.
"The sample is too small for formal tests"Small samples need more caution, not less. Flag the limitation explicitly.
"There's no manipulation -- it's a natural cutoff"Run the density test (rddensity). Natural cutoffs can still be gamed.
"We can extrapolate the RDD effect to the full population"RDD estimates are local to the cutoff. Say so.
"Default bandwidth is fine"Report sensitivity to bandwidth choice. One bandwidth = one fragile result.

Stage 5: Interpretation

Help write a plain-language summary:

"Based on the regression discontinuity analysis:

  • The estimated treatment effect at the cutoff is [coefficient] (95% robust CI: [lower, upper]).
  • The bandwidth used was [h], including observations within [h] units of the cutoff.
  • This means [plain-language interpretation in their specific context].

Local interpretation: This effect applies to units near the cutoff ([running variable] close to [cutoff value]), not the full population. Units far from the cutoff may experience different effects.

Density test (Cattaneo, Jansson, and Ma 2020):

  • [Result of density test — 'No evidence of manipulation' or 'Warning: density discontinuity detected']

Caveats:

  • [Manipulation concerns from Stage 2]
  • [Compound treatment concerns]
  • [Limited external validity — this is a local estimate]
  • [Sample size near cutoff]"

Reading Your Results

Density test (Cattaneo, Jansson, and Ma 2020): If the test rejects: "There are suspiciously more (or fewer) units just above or below the cutoff. This suggests people can manipulate their score to land on the preferred side, which breaks the 'as-if random' logic of RDD. The estimate is not credible without addressing this." If it passes: "No evidence of manipulation at the cutoff. Units on either side appear comparable."

Bandwidth choice: "The bandwidth of [h] means you're using units within [h] of the cutoff. Narrower = less bias (tighter local comparison) but more variance (fewer observations). The robust confidence interval accounts for this tradeoff. If results change dramatically across bandwidths, the estimate is fragile."

Local interpretation: "This effect applies only to units near the cutoff — not the entire population. If you're deciding whether to change a policy that affects everyone, consider whether the effect at the margin generalizes to units far from the cutoff."

Covariate smoothness: If any covariate shows a discontinuity at the cutoff: "This covariate jumps at the cutoff, which shouldn't happen if assignment near the cutoff is as-if random. Either there's manipulation, or there's a compound treatment — something else changes at the same cutoff."

Saving Output

Save alongside the plan (or create a new directory if standalone):

docs/causal-plans/YYYY-MM-DD-<project>/
├── plan.md              # From planner (or created here if standalone)
├── implementation.md    # This skill's stage-by-stage summary
└── analysis.[R|py]      # Generated code

Use the Write tool. Tell the user where files are saved.

Handoff

"Your RDD analysis is complete. Recommended next steps:

  1. Audit: /causal-auditor to stress-test for threats to validity.
  2. Refine: If manipulation or compound treatments were concerning, we can discuss mitigations.
  3. Report: I can help write up findings for a non-technical audience."

Common Issues

  • Manipulation of the running variable: If units can precisely control their position relative to the cutoff, RDD is invalid. Run the density test (rddensity) before proceeding.
  • Bandwidth too wide: Large bandwidths increase bias. Always report results across multiple bandwidths and use MSE-optimal selection from rdrobust.
  • Covariate discontinuities: If covariates jump at the cutoff, there may be compound treatments. Check covariate balance at the threshold.

Integration

Before this skill:

  • /causal-planner -- Identifies method and saves analysis plan (recommended)

After this skill:

  • /causal-auditor -- Stress-test results for threats to validity (recommended)
  • /causal-exercises -- Practice a similar analysis on simulated data (optional)

If assumptions fail:

  • /causal-iv -- If cutoff is fuzzy and instrument framing works
  • /causal-did -- If pre/post data and a control group exist

Self-Correction

If the user corrects you, append to references/lessons.md:

### RDD: [Short description]
**Trigger**: [When this tends to happen]
**Mistake**: [What went wrong]
**Rule**: [What to do instead]
**Source**: User correction, [date]

常见问题

Causal Rdd AI 技能有什么作用?

使用 R 或 Python 实现精确和模糊回归不连续设计,并进行带宽选择、操纵检验和敏感性分析。用户提到 RDD、截断点、阈值、运行变量或不连续性时使用。不适用于任意子组比较。

为什么在 TypingMind 中使用 Causal Rdd?

因为您只需安装一次,就能搭配任何模型使用。Causal Rdd 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Causal Rdd?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/RobsonTigre/everyday-causal-skills/tree/main/skills/causal-rdd。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Causal Rdd?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Causal Rdd 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Causal Rdd 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Causal Rdd AI 技能免费吗?

是的。RobsonTigre 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇