[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EKW7VCSB3DQCWW05SB4D1Z":3,"skill-same:01M6EKW7VCSB3DQCWW05SB4D1Z":84},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":32,"linkOnly":33,"markdownContent":34,"markdownBody":35,"frontMatter":36,"refName":61,"commitSha":62,"skillDirectory":63,"forksCount":64,"repositoryHtmlUrl":65,"repositoryHomepageUrl":6,"ownerHtmlUrl":66,"ownerBlogUrl":67,"ownerDescription":68,"updatedAt":69,"install":70,"resources":83},"01M6EKW7VCSB3DQCWW05SB4D1Z","causal-inverse-probability-weighting",null,"Estimate ATE via stabilized IPW with weight trimming, cluster-robust SEs from a weighted regression on treatment, and an explicit weighted-balance check that invokes G4 with weights=stabilized_weights.","cgpan\u002Fedm-ars-public","cgpan","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F118746117?v=4","01M6EKT5TG36Q3GH340QN8RH08","Chenguang Pan","01M6EKT5YTQVRARGJF0VPA1SY7",5,"MIT","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Fskills\u002Fmethodology\u002Fcausal-inverse-probability-weighting\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31],"probability","causal inverse probability weighting","dag","diagnostics","methodology","regression","check","conventions","analyst","sensitivity","identification","via","cluster","2026-11-10 10:12:30",false,"---\nname: causal-inverse-probability-weighting\nlayer: methodology\ndescription: Estimate ATE via stabilized IPW with weight trimming, cluster-robust SEs from a weighted regression on treatment, and an explicit weighted-balance check that invokes G4 with weights=stabilized_weights.\ntrigger_keywords:\n  - causal\n  - ipw\n  - inverse-probability\n  - weighting\n  - stabilized\n  - propensity\n  - ess\napplicable_task_types:\n  - causal_soo\napplicable_datasets: []\napplicable_stages:\n  - Analyst\npriority: 1\nreferences_skills:\n  - causal-dag-identification\n  - causal-estimand-definition\n  - causal-positivity-diagnostics\n  - causal-balance-diagnostics\n  - causal-sensitivity-unmeasured-confounding\n  - hsls09-causal-conventions\nresources: []\nversion: \"1.0\"\nrule_severity: mandatory\n---\n\n# Causal Inverse-Probability Weighting (M3)\n\nEstimate the ATE by reweighting each row by the inverse of its\npropensity to receive its observed treatment. Stabilized weights\nshrink variance vs. unstabilized; trimming bounds the worst weights\nper G3's positivity rule; cluster-robust SEs come from a weighted\nregression on treatment with school-level clustering.\n\nThe **weighted balance check** in this skill is non-negotiable —\nM3 composes G4 implicitly via `references_skills`, but the body\nbelow names the check explicitly so the LLM cannot drop it.\n\n**Adjustment-set resolution:** apply D1's `resolve_encoded_columns` rule when constructing\nthe design matrix for the propensity model. Do not look up original categorical names in\n`df.columns` directly — categorical adjustment variables (X1RACE, X1PAREDU, X1SEX, etc.)\nhave been one-hot encoded by DataEngineer into `\u003Cvarname>_\u003Clevel>` columns. See\n`skills\u002Fdataset\u002Fhsls09-causal-conventions\u002FSKILL.md` § Encoded-column lookup.\n\n## Stabilized weights\n\nFor each row `i`:\n\n```\nSW_i = P(T=1)        \u002F e(X_i)        if T_i = 1\nSW_i = P(T=0)        \u002F (1 - e(X_i))  if T_i = 0\n```\n\nwhere `e(X)` is the estimated propensity and `P(T=1)` \u002F `P(T=0)`\nare the marginal treatment proportions. Stabilization shrinks the\nweight variance relative to unstabilized\n(`1\u002Fe(X)` and `1\u002F(1-e(X))`).\n\n## Weight trimming\n\nPer G3 (`causal-positivity-diagnostics`)'s positivity rule, **trim\nrows where propensity `\u003C 0.05` OR `> 0.95`**. Document the trimmed\n`n` in `data_report.warnings`. If the trim takes more than 10% of\nthe sample, escalate per G3's `extreme_tail_fraction ≥ 0.10` rule.\n\n## Estimator\n\nWeighted regression of `Y ~ T` (no covariates beyond T — the weights\ndo the adjustment) with `weights=SW` and `cov_type='cluster'` on the\nschool pseudo-IDs from D1.\n\n## Estimand\n\n**ATE in the analytic sample** by default (stabilized weights target\nATE). Explicit estimand declaration per G2\n(`causal-estimand-definition`).\n\n## ESS degeneracy diagnostic\n\nReport the effective sample size:\n\n```\nESS = (sum(SW))^2 \u002F sum(SW^2)\n```\n\n**Flag if `ESS \u003C 0.5 * n`** — weight degeneracy means a handful of\nrows dominate the estimator, and the stated `n` overstates the\ninformation content. Append to `results.warnings`; if combined with\npositivity violation, the estimate should not be reported.\n\n## Weighted balance check (mandatory)\n\nAfter computing stabilized weights, run G4\n(`causal-balance-diagnostics`) with `weights=stabilized_weights` and\nreport **weighted** SMDs for every covariate in the adjustment set.\nApply the same three-tier threshold rule as G4\n(`|SMD| \u003C 0.10` balanced, `0.10–0.25` flag, `≥ 0.25` REVISE). Save\n`love_plot_ipw.png` showing pre-weighting vs. post-weighting SMDs.\n\nThis is the IPW-specific analogue of M2's matched-balance check.\nM3 composes G4 implicitly via `references_skills`, but the\nexplicitness of this bullet is the enforcement.\n\n## Output schema\n\n```json\n\"ipw_results\": {\n  \"weight_max\": 0.0,\n  \"weight_min\": 0.0,\n  \"weight_ess\": 0,\n  \"trimmed_n\": 0,\n  \"trimming_threshold\": 0.05,\n  \"ate_estimate\": 0.0,\n  \"ate_ci_lower\": 0.0,\n  \"ate_ci_upper\": 0.0,\n  \"se_method\": \"cluster_robust\",\n  \"stabilized_weights\": true,\n  \"weighted_balance\": {\n    \"max_post_weighted_smd\": 0.0,\n    \"flagged_covariates\": [],\n    \"love_plot_path\": \"love_plot_ipw.png\"\n  }\n}\n```\n\n## Failures prevented\n\nINF-01 (P), INF-04 (S), INF-05 (S), ESC-01 (S — explicit ATE rule);\nresidual covariate imbalance under weighting (via G4 weighted\nbalance check).\n\n## Python implementation guidance\n\n**Primary library:** `statsmodels.regression.linear_model.WLS` or\n`statsmodels.GLM` with `freq_weights=stabilized_weights` and\n`cov_type='cluster'`. Mature, supports clustering.\n\n**Alternative:** `causalml.inference.meta.LRSRegressor` provides IPW\ndirectly but lacks cluster-robust SEs.\n\n**Function signatures:**\n\n```python\ndef compute_stabilized_weights(\n    propensity: np.ndarray,\n    treatment: np.ndarray,\n) -> np.ndarray: ...\n\ndef trim_extreme_weights(\n    df: pd.DataFrame,\n    propensity: np.ndarray,\n    weights: np.ndarray,\n    threshold: float = 0.05,\n) -> tuple[pd.DataFrame, np.ndarray]: ...\n\ndef ipw_ate(\n    df: pd.DataFrame,\n    treatment_col: str,\n    outcome_col: str,\n    weights: np.ndarray,\n    cluster_col: str,\n) -> dict: ...  # returns ipw_results schema above\n```\n\n**Library pitfalls:**\n\n- `statsmodels` GLM does not always honor `cov_type='cluster'`\n  correctly with non-identity links; for binary outcomes, use a\n  linear probability model (`OLS` \u002F `WLS` with binary Y) plus\n  clustered SE — then the ATE is the risk difference. Safer than\n  fighting GLM's link-function plumbing.\n- `freq_weights` vs `var_weights` in `statsmodels`: prefer\n  `freq_weights` for IPW (treats the weights as case counts; matches\n  the intent that the weighted sample stands in for the target\n  population).\n\n## Validation criteria\n\nThe SKILL contract requires that:\n\n1. The stabilized-weights formula is present.\n2. The trimming rule referencing G3 is present.\n3. The ESS degeneracy check (`ESS \u003C 0.5 * n`) is present.\n4. The cluster-robust SE rule references D1's pseudo-school-IDs.\n5. The output schema is present.\n6. The explicit weighted-balance-check bullet invoking G4 with\n   `weights=stabilized_weights` and the three-tier SMD threshold\n   rule is present.\n\nAn Analyst code artifact using this skill must produce:\n\n- `results.estimates.ipw` per schema (including the\n  `weighted_balance` block),\n- `love_plot_ipw.png`,\n- `validation_passed: false` when `weight_ess \u003C 0.5 * n` OR\n  `max_post_weighted_smd >= 0.25`.\n\n## Source provenance\n\nCanonical source: the v3.0 causal-methods specification (internal) §3.9\n(M3 per-skill specification, including the §3a.1 R4 explicit\nweighted-balance-check bullet).\n","# Causal Inverse-Probability Weighting (M3)\n\nEstimate the ATE by reweighting each row by the inverse of its\npropensity to receive its observed treatment. Stabilized weights\nshrink variance vs. unstabilized; trimming bounds the worst weights\nper G3's positivity rule; cluster-robust SEs come from a weighted\nregression on treatment with school-level clustering.\n\nThe **weighted balance check** in this skill is non-negotiable —\nM3 composes G4 implicitly via `references_skills`, but the body\nbelow names the check explicitly so the LLM cannot drop it.\n\n**Adjustment-set resolution:** apply D1's `resolve_encoded_columns` rule when constructing\nthe design matrix for the propensity model. Do not look up original categorical names in\n`df.columns` directly — categorical adjustment variables (X1RACE, X1PAREDU, X1SEX, etc.)\nhave been one-hot encoded by DataEngineer into `\u003Cvarname>_\u003Clevel>` columns. See\n`skills\u002Fdataset\u002Fhsls09-causal-conventions\u002FSKILL.md` § Encoded-column lookup.\n\n## Stabilized weights\n\nFor each row `i`:\n\n```\nSW_i = P(T=1)        \u002F e(X_i)        if T_i = 1\nSW_i = P(T=0)        \u002F (1 - e(X_i))  if T_i = 0\n```\n\nwhere `e(X)` is the estimated propensity and `P(T=1)` \u002F `P(T=0)`\nare the marginal treatment proportions. Stabilization shrinks the\nweight variance relative to unstabilized\n(`1\u002Fe(X)` and `1\u002F(1-e(X))`).\n\n## Weight trimming\n\nPer G3 (`causal-positivity-diagnostics`)'s positivity rule, **trim\nrows where propensity `\u003C 0.05` OR `> 0.95`**. Document the trimmed\n`n` in `data_report.warnings`. If the trim takes more than 10% of\nthe sample, escalate per G3's `extreme_tail_fraction ≥ 0.10` rule.\n\n## Estimator\n\nWeighted regression of `Y ~ T` (no covariates beyond T — the weights\ndo the adjustment) with `weights=SW` and `cov_type='cluster'` on the\nschool pseudo-IDs from D1.\n\n## Estimand\n\n**ATE in the analytic sample** by default (stabilized weights target\nATE). Explicit estimand declaration per G2\n(`causal-estimand-definition`).\n\n## ESS degeneracy diagnostic\n\nReport the effective sample size:\n\n```\nESS = (sum(SW))^2 \u002F sum(SW^2)\n```\n\n**Flag if `ESS \u003C 0.5 * n`** — weight degeneracy means a handful of\nrows dominate the estimator, and the stated `n` overstates the\ninformation content. Append to `results.warnings`; if combined with\npositivity violation, the estimate should not be reported.\n\n## Weighted balance check (mandatory)\n\nAfter computing stabilized weights, run G4\n(`causal-balance-diagnostics`) with `weights=stabilized_weights` and\nreport **weighted** SMDs for every covariate in the adjustment set.\nApply the same three-tier threshold rule as G4\n(`|SMD| \u003C 0.10` balanced, `0.10–0.25` flag, `≥ 0.25` REVISE). Save\n`love_plot_ipw.png` showing pre-weighting vs. post-weighting SMDs.\n\nThis is the IPW-specific analogue of M2's matched-balance check.\nM3 composes G4 implicitly via `references_skills`, but the\nexplicitness of this bullet is the enforcement.\n\n## Output schema\n\n```json\n\"ipw_results\": {\n  \"weight_max\": 0.0,\n  \"weight_min\": 0.0,\n  \"weight_ess\": 0,\n  \"trimmed_n\": 0,\n  \"trimming_threshold\": 0.05,\n  \"ate_estimate\": 0.0,\n  \"ate_ci_lower\": 0.0,\n  \"ate_ci_upper\": 0.0,\n  \"se_method\": \"cluster_robust\",\n  \"stabilized_weights\": true,\n  \"weighted_balance\": {\n    \"max_post_weighted_smd\": 0.0,\n    \"flagged_covariates\": [],\n    \"love_plot_path\": \"love_plot_ipw.png\"\n  }\n}\n```\n\n## Failures prevented\n\nINF-01 (P), INF-04 (S), INF-05 (S), ESC-01 (S — explicit ATE rule);\nresidual covariate imbalance under weighting (via G4 weighted\nbalance check).\n\n## Python implementation guidance\n\n**Primary library:** `statsmodels.regression.linear_model.WLS` or\n`statsmodels.GLM` with `freq_weights=stabilized_weights` and\n`cov_type='cluster'`. Mature, supports clustering.\n\n**Alternative:** `causalml.inference.meta.LRSRegressor` provides IPW\ndirectly but lacks cluster-robust SEs.\n\n**Function signatures:**\n\n```python\ndef compute_stabilized_weights(\n    propensity: np.ndarray,\n    treatment: np.ndarray,\n) -> np.ndarray: ...\n\ndef trim_extreme_weights(\n    df: pd.DataFrame,\n    propensity: np.ndarray,\n    weights: np.ndarray,\n    threshold: float = 0.05,\n) -> tuple[pd.DataFrame, np.ndarray]: ...\n\ndef ipw_ate(\n    df: pd.DataFrame,\n    treatment_col: str,\n    outcome_col: str,\n    weights: np.ndarray,\n    cluster_col: str,\n) -> dict: ...  # returns ipw_results schema above\n```\n\n**Library pitfalls:**\n\n- `statsmodels` GLM does not always honor `cov_type='cluster'`\n  correctly with non-identity links; for binary outcomes, use a\n  linear probability model (`OLS` \u002F `WLS` with binary Y) plus\n  clustered SE — then the ATE is the risk difference. Safer than\n  fighting GLM's link-function plumbing.\n- `freq_weights` vs `var_weights` in `statsmodels`: prefer\n  `freq_weights` for IPW (treats the weights as case counts; matches\n  the intent that the weighted sample stands in for the target\n  population).\n\n## Validation criteria\n\nThe SKILL contract requires that:\n\n1. The stabilized-weights formula is present.\n2. The trimming rule referencing G3 is present.\n3. The ESS degeneracy check (`ESS \u003C 0.5 * n`) is present.\n4. The cluster-robust SE rule references D1's pseudo-school-IDs.\n5. The output schema is present.\n6. The explicit weighted-balance-check bullet invoking G4 with\n   `weights=stabilized_weights` and the three-tier SMD threshold\n   rule is present.\n\nAn Analyst code artifact using this skill must produce:\n\n- `results.estimates.ipw` per schema (including the\n  `weighted_balance` block),\n- `love_plot_ipw.png`,\n- `validation_passed: false` when `weight_ess \u003C 0.5 * n` OR\n  `max_post_weighted_smd >= 0.25`.\n\n## Source provenance\n\nCanonical source: the v3.0 causal-methods specification (internal) §3.9\n(M3 per-skill specification, including the §3a.1 R4 explicit\nweighted-balance-check bullet).\n",{"name":5,"layer":23,"version":37,"priority":38,"resources":39,"description":7,"rule_severity":40,"trigger_keywords":41,"applicable_stages":49,"references_skills":51,"applicable_datasets":58,"applicable_task_types":59},"1.0",1,[],"mandatory",[42,43,44,45,46,47,48],"causal","ipw","inverse-probability","weighting","stabilized","propensity","ess",[50],"Analyst",[52,53,54,55,56,57],"causal-dag-identification","causal-estimand-definition","causal-positivity-diagnostics","causal-balance-diagnostics","causal-sensitivity-unmeasured-confounding","hsls09-causal-conventions",[],[60],"causal_soo","main","1aeaead66d2bf876109f3b101005d2eed54041d9","skills\u002Fmethodology\u002Fcausal-inverse-probability-weighting",0,"https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public","https:\u002F\u002Fgithub.com\u002Fcgpan","https:\u002F\u002Fcpan.ai","Ph.D. candidate in Measurement, Evaluation, and Statistics.","2026-09-28 20:39:06",{"source":8,"skillName":5,"commands":71,"prompt":81,"zipAvailable":82},[72,75,78],{"tool":73,"command":74},"npx","npx skills add cgpan\u002Fedm-ars-public --skill causal-inverse-probability-weighting",{"tool":76,"command":77},"bunx","bunx skills add cgpan\u002Fedm-ars-public --skill causal-inverse-probability-weighting",{"tool":79,"command":80},"pnpm","pnpm dlx skills add cgpan\u002Fedm-ars-public --skill causal-inverse-probability-weighting","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Fskills\u002Fmethodology\u002Fcausal-inverse-probability-weighting\u002FSKILL.md",true,[],[85,98,111,120,132,142],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":32},"01M6EM1ZTQZVAP90DZTVBHCCFB","acm-fixture","Fixture writing skill for ACM acmart sigconf paper output.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fwriting\u002Facm-fixture\u002FSKILL.md",[],[92,93,94,95,96,97],"acm fixture","fixture","writing","LaTeX","writer","paper",{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":32},"01M6EM1XNFETAZFGPHQPAXKBYN","prediction-fixture","Fixture skill for the prediction task type; references shap-fixture.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Ftask-type\u002Fprediction-fixture\u002FSKILL.md",[],[93,105,106,107,108,109,110,27],"prediction fixture","task","type","references","fixture skill","shap",{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":32},"01M6EM1V4MQXYGQ7K2ZDJRAPSM","causal-fixture","Fixture skill for the causal_inference task type.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Ftask-type\u002Fcausal-fixture\u002FSKILL.md",[],[93,118,107,106,119,109],"causal fixture","inference",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":32},"01M6EM1SCWFZZ2ACSAP65GNWK9","shap-fixture","Fixture methodology for SHAP feature importance analysis.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fmethodology\u002Fshap-fixture\u002FSKILL.md",[],[127,93,110,128,23,129,130,131],"shap fixture","feature importance","analysis","explainer","feature",{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":32},"01M6EM1PZC1MK1G0D1YFVYAQ9W","cluster-recon-fixture","Fixture methodology for reconstructing cluster IDs from fingerprint variables.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fmethodology\u002Fcluster-recon-fixture\u002FSKILL.md",[],[139,140,31,93,141,23],"recon","cluster recon fixture","ids",{"skillNo":143,"name":144,"nameZh":6,"description":145,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":146,"categories":147,"keywords":148,"publishedAt":32},"01M6EM1MZVKMSWEXZ7TJ45DS04","hsls09-fixture","Fixture skill for HSLS:09 with a bundled YAML resource and one cross-reference.","https:\u002F\u002Fgithub.com\u002Fcgpan\u002Fedm-ars-public\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fdataset\u002Fhsls09-fixture\u002FSKILL.md",[],[93,149,150,151,152,109,153,139,31,154],"hsls09 fixture","yaml","public","reference","dataset","registry"]