{"id":"70f7c7c9-c85e-4788-a09b-4443da68d860","shortId":"JfeQVW","kind":"skill","title":"marginaleffects","tagline":"Manual for the marginaleffects R and Python package, and guide to the book \"Model to Meaning\". Use when users ask about predictions, comparisons, slopes, marginal effects, average treatment effects (ATE/ATT/CATE), hypothesis testing, contrasts, counterfactuals, risk ratios, odds ","description":"# marginaleffects\n\nPrimary source of information: https://marginaleffects.com\nFree book, case studies, and vignettes are available there.\n\nPackage manual for R and Python, plus a guide to the companion book.\n\n**Book**: *Model to Meaning: How to Interpret Statistical Models in R and Python*\n- Author: Vincent Arel-Bundock (2026)\n- Publisher: CRC Press\n- Free online: https://marginaleffects.com (primary source with many case studies and vignettes)\n- Print: https://routledge.com/9781032908724\n\n## Core framework: Five questions for every analysis\n\nEvery interpretation task can be decomposed into five disciplined questions:\n\n1. **Quantity**: What estimand? (predictions, comparisons, slopes, or tests)\n2. **Predictors (Grid)**: Where to evaluate? (observed values, counterfactual scenarios, balanced grids)\n3. **Aggregation**: Over whom? (unit-level, group means with `by=`, weighted averages)\n4. **Uncertainty**: Which inference method? (delta method, robust SE, bootstrap, Bayesian)\n5. **Test**: What hypothesis? (null tests, equivalence, pairwise contrasts)\n\n## Quick start\n\n**Chapter summaries**: Read `chapters/<chapter>.qmd`\n**Function reference**: Read `man/r/<function>.md` or `man/python/<function>.md`\n\n## When to use this skill\n\n- User asks about predictions, comparisons, slopes, or marginal effects\n- User needs help choosing estimands (ATE, ATT, CATE, risk difference, odds ratio)\n- User asks about marginaleffects function syntax or arguments\n- User wants to interpret model results or test hypotheses\n- User mentions counterfactual analysis, G-computation, or causal inference\n- User references Model to Meaning chapters\n\n## Instructions\n\n1. **Classify the request**:\n   - Conceptual: Which estimand? How to interpret? → Use `chapters/`\n   - Implementation: Function syntax, arguments, code → Use `man/r/` or `man/python/`\n   - Mixed: Start with conceptual framing, then provide code\n\n2. **Read the relevant source files**:\n    - Book chapters: `chapters/framework.qmd`, `chapters/predictions.qmd`, `chapters/comparisons.qmd`, `chapters/slopes.qmd`, `chapters/hypothesis.qmd`, etc.\n   - R reference: `man/r/predictions.md`, `man/r/comparisons.md`, `man/r/slopes.md`, `man/r/hypotheses.md`, `man/r/datagrid.md`\n   - Python reference: `man/python/predictions.md`, `man/python/comparisons.md`, `man/python/slopes.md`, `man/python/hypotheses.md`\n\n3. **Apply the five-question framework** to organize your response:\n   - Help user define the estimand (Quantity)\n   - Clarify where to evaluate it (Grid)\n   - Determine aggregation level (Aggregation)\n   - Recommend uncertainty quantification (Uncertainty)\n   - Specify hypothesis if testing (Test)\n\n4. **Provide concrete code examples** using the correct function for their language (R or Python)\n\n## Available resources\n\n### Book chapters (`chapters/`)\n| File | Topic | Chapter focus |\n|------|-------|---------------|\n| `framework.qmd` | Five-question framework (start here) | Defines the five questions and core quantities (predictions, comparisons, slopes) for turning models into intuitive estimands. |\n| `predictions.qmd` | Predicted values and expected outcomes | Defines predictions, grids, aggregation, and tests with `predictions()`/`avg_predictions()`. |\n| `comparisons.qmd` | Counterfactual comparisons, ATE, ATT, risk ratios | Defines counterfactual comparisons, effect functions, grids, and aggregation with `comparisons()`/`avg_comparisons()`. |\n| `slopes.qmd` | Marginal effects, partial derivatives | Defines slopes as partial derivatives, conditional on predictors; uses `slopes()`/`avg_slopes()`. |\n| `hypothesis.qmd` | Hypothesis testing and equivalence | Null vs equivalence tests for any quantity using `hypothesis` and `equivalence` arguments. |\n| `interactions.qmd` | Interaction effects and effect modification | Interprets heterogeneity and nonlinearity with interactions and polynomials using predictions, comparisons, and slopes. |\n| `categorical.qmd` | Categorical predictors and contrasts | Applies the framework to categorical/ordinal outcomes with predictions and comparisons by outcome level. |\n| `experiments.qmd` | Experimental designs | ATE in experiments and factorial designs via `avg_comparisons()` and robust SEs. |\n| `gcomputation.qmd` | G-computation and causal inference | G-computation steps for ATE/ATT/ATU/CATE with counterfactual prediction grids. |\n| `uncertainty.qmd` | Inference methods (delta, bootstrap, Bayesian) | Delta method, bootstrap, simulation, conformal prediction, and robust/clustered standard errors via `inferences()`/`vcov`. |\n| `mrp.qmd` | Multilevel regression and poststratification | Multilevel models and poststratification with predictions and comparisons in mixed effects. |\n| `ml.qmd` | Machine learning models | Model auditing with predictions, comparisons, and slopes for ML frameworks. |\n| `challenge.qmd` | The interpretation challenge | Defines analysis goals, estimands, and why coefficients need transformation. |\n\n### R function reference (`man/r/`)\nCore functions (includes `avg_*` variants): `predictions.md`, `comparisons.md`, `slopes.md`, `hypotheses.md`\nGrids: `datagrid.md`\nPlots: `plot_predictions.md`, `plot_comparisons.md`, `plot_slopes.md`\nUtilities: `posterior_draws.md`, `inferences.md`, `get_dataset.md`\n\n### Python function reference (`man/python/`)\nCore: `predictions.md`, `avg_predictions.md`, `comparisons.md`, `avg_comparisons.md`, `slopes.md`, `avg_slopes.md`, `hypotheses.md`\nGrids: `datagrid.md`\nPlots: `plot_predictions.md`, `plot_comparisons.md`, `plot_slopes.md`\nModel fitting: `fit_statsmodels.md`, `fit_sklearn.md`, `fit_linearmodels.md`\n\n## Examples\n\n### Logit model example\n\n**R:**\n```r\nlibrary(marginaleffects)\n\n# Fit logistic regression\nmod <- glm(am ~ hp + wt, data = mtcars, family = binomial)\n\n# Average marginal effects (slopes on probability scale)\navg_slopes(mod)\n\n# Predicted probabilities at specific values\npredictions(mod, newdata = datagrid(hp = c(100, 150, 200), wt = 3))\n\n# Average treatment effect: compare hp = 150 vs hp = 100\navg_comparisons(mod, variables = list(hp = c(100, 150)))\n\n# Risk ratio for a 50-unit increase in hp\navg_comparisons(mod, variables = list(hp = 50), comparison = \"ratio\")\n```\n\n**Python:**\n```python\nimport marginaleffects as me\nimport statsmodels.formula.api as smf\n\n# Fit logistic regression\nmod = smf.logit(\"am ~ hp + wt\", data=me.get_dataset(\"mtcars\")).fit()\n\n# Average marginal effects\nme.avg_slopes(mod)\n\n# Predicted probabilities at specific values\nme.predictions(mod, newdata=me.datagrid(mod, hp=[100, 150, 200], wt=3))\n\n# Average treatment effect: compare hp = 150 vs hp = 100\nme.avg_comparisons(mod, variables={\"hp\": [100, 150]})\n```\n\n**User asks about choosing an estimand:**\n→ Read `chapters/framework.qmd` and `chapters/comparisons.qmd`, explain the five-question framework, recommend the appropriate quantity (e.g., `avg_comparisons()` for ATE).\n\n**User asks how to compute marginal effects:**\n→ Read `man/r/slopes.md` or `man/python/slopes.md`, provide syntax with relevant arguments.\n\n**User wants to test treatment effect heterogeneity:**\n→ Read `chapters/comparisons.qmd` for CATE concepts, then `man/r/hypotheses.md` for testing syntax with `by=` groups.\n\n**User asks about counterfactual grids:**\n→ Read `chapters/framework.qmd` (Predictors section) and `man/r/datagrid.md` for `datagrid()` usage.\n\n## Best practices\n\n- **Ask about language preference**: If the user hasn't specified R or Python, ask which they prefer before providing code examples\n- Always frame responses using the five-question framework when appropriate\n- Cite specific sections from summaries or manuals\n- Mention `get_dataset()` when users need example data\n- For mixed requests, start with conceptual framing then show implementation","tags":["vincentarelbundock","marginaleffects","awesome","agent","skills","for","empirical","research","brycewang-stanford","academic-research","agent-skills","ai-agent"],"capabilities":["skill","source-brycewang-stanford","skill-39-vincentarelbundock-marginaleffects","topic-academic-research","topic-agent-skills","topic-ai-agent","topic-awesome-list","topic-communication","topic-copaper","topic-economics","topic-education","topic-empirical-research","topic-international-relations","topic-political-science","topic-psychology"],"categories":["Awesome-Agent-Skills-for-Empirical-Research"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research/39-vincentarelbundock-marginaleffects","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research","source_repo":"https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research","install_from":"skills.sh"}},"qualityScore":"0.700","qualityRationale":"deterministic score 0.70 from registry signals: · indexed on github topic:agent-skills · 598 github stars · SKILL.md body (7,742 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-02T12:52:56.522Z","embedding":null,"createdAt":"2026-04-18T22:12:46.134Z","updatedAt":"2026-05-02T12:52:56.522Z","lastSeenAt":"2026-05-02T12:52:56.522Z","tsv":"'/9781032908724':103 '1':121,250 '100':676,689,697,757,770,776 '150':677,686,698,758,767,777 '2':130,279 '200':678,759 '2026':85 '3':142,306,680,761 '4':155,342 '5':166 '50':703,714 'aggreg':143,330,332,398,419 'alway':876 'analysi':110,236,581 'appli':307,482 'appropri':796,886 'arel':83 'arel-bundock':82 'argument':223,265,457,818 'ask':21,196,217,779,804,840,855,868 'ate':209,408,498,802 'ate/att/atu/cate':522 'ate/att/cate':31 'att':210,409 'audit':567 'author':80 'avail':52,357 'averag':28,154,655,681,740,762 'avg':403,422,439,505,596,662,690,708,799 'avg_comparisons.md':620 'avg_predictions.md':618 'avg_slopes.md':622 'balanc':140 'bayesian':165,532 'best':853 'binomi':654 'book':14,46,66,67,285,359 'bootstrap':164,531,535 'bundock':84 'c':675,696 'case':47,96 'cate':211,829 'categor':478 'categorical.qmd':477 'categorical/ordinal':486 'causal':241,515 'challeng':579 'challenge.qmd':576 'chapter':177,180,248,261,286,360,361,364 'chapters/comparisons.qmd':289,787,827 'chapters/framework.qmd':287,785,845 'chapters/hypothesis.qmd':291 'chapters/predictions.qmd':288 'chapters/slopes.qmd':290 'choos':207,781 'cite':887 'clarifi':323 'classifi':251 'code':266,278,345,874 'coeffici':586 'companion':65 'compar':684,765 'comparison':24,126,199,381,407,414,421,423,474,491,506,558,570,691,709,715,772,800 'comparisons.md':599,619 'comparisons.qmd':405 'comput':239,513,519,807 'concept':830 'conceptu':254,274,907 'concret':344 'condit':434 'conform':537 'contrast':34,174,481 'core':104,378,593,616 'correct':349 'counterfactu':35,138,235,406,413,524,842 'crc':87 'data':651,735,901 'datagrid':673,851 'datagrid.md':603,625 'dataset':737,896 'decompos':116 'defin':319,373,395,412,429,580 'delta':160,530,533 'deriv':428,433 'design':497,503 'determin':329 'differ':213 'disciplin':119 'e.g':798 'effect':27,30,203,415,426,460,462,561,657,683,742,764,809,824 'equival':172,445,448,456 'error':542 'estimand':124,208,256,321,388,583,783 'etc':292 'evalu':135,326 'everi':109,111 'exampl':346,635,638,875,900 'expect':393 'experi':500 'experiment':496 'experiments.qmd':495 'explain':788 'factori':502 'famili':653 'file':284,362 'fit':631,643,727,739 'fit_linearmodels.md':634 'fit_sklearn.md':633 'fit_statsmodels.md':632 'five':106,118,310,368,375,791,882 'five-quest':309,367,790,881 'focus':365 'frame':275,877,908 'framework':105,312,370,484,575,793,884 'framework.qmd':366 'free':45,89 'function':182,220,263,350,416,590,594,613 'g':238,512,518 'g-comput':237,511,517 'gcomputation.qmd':510 'get':895 'get_dataset.md':611 'glm':647 'goal':582 'grid':132,141,328,397,417,526,602,624,843 'group':149,838 'guid':11,62 'hasn':862 'help':206,317 'heterogen':465,825 'hp':649,674,685,688,695,707,713,733,756,766,769,775 'hypothes':232 'hypotheses.md':601,623 'hypothesi':32,169,338,442,454 'hypothesis.qmd':441 'implement':262,911 'import':719,723 'includ':595 'increas':705 'infer':158,242,516,528,544 'inferences.md':610 'inform':43 'instruct':249 'interact':459,469 'interactions.qmd':458 'interpret':73,112,227,259,464,578 'intuit':387 'languag':353,857 'learn':564 'level':148,331,494 'librari':641 'list':694,712 'logist':644,728 'logit':636 'machin':563 'man/python':188,270,615 'man/python/comparisons.md':303 'man/python/hypotheses.md':305 'man/python/predictions.md':302 'man/python/slopes.md':304,813 'man/r':185,268,592 'man/r/comparisons.md':296 'man/r/datagrid.md':299,849 'man/r/hypotheses.md':298,832 'man/r/predictions.md':295 'man/r/slopes.md':297,811 'mani':95 'manual':2,55,893 'margin':26,202,425,656,741,808 'marginaleffect':1,5,39,219,642,720 'marginaleffects.com':44,91 'md':186,189 'me.avg':743,771 'me.datagrid':754 'me.get':736 'me.predictions':751 'mean':17,70,150,247 'mention':234,894 'method':159,161,529,534 'mix':271,560,903 'ml':574 'ml.qmd':562 'mod':646,664,671,692,710,730,745,752,755,773 'model':15,68,75,228,245,385,552,565,566,630,637 'modif':463 'mrp.qmd':546 'mtcar':652,738 'multilevel':547,551 'need':205,587,899 'newdata':672,753 'nonlinear':467 'null':170,446 'observ':136 'odd':38,214 'onlin':90 'organ':314 'outcom':394,487,493 'packag':9,54 'pairwis':173 'partial':427,432 'plot':604,626 'plot_comparisons.md':606,628 'plot_predictions.md':605,627 'plot_slopes.md':607,629 'plus':60 'polynomi':471 'posterior_draws.md':609 'poststratif':550,554 'practic':854 'predict':23,125,198,380,390,396,402,404,473,489,525,538,556,569,665,670,746 'predictions.md':598,617 'predictions.qmd':389 'predictor':131,436,479,846 'prefer':858,871 'press':88 'primari':40,92 'print':100 'probabl':660,666,747 'provid':277,343,814,873 'publish':86 'python':8,59,79,300,356,612,717,718,867 'qmd':181 'quantif':335 'quantiti':122,322,379,452,797 'question':107,120,311,369,376,792,883 'quick':175 'r':6,57,77,293,354,589,639,640,865 'ratio':37,215,411,700,716 'read':179,184,280,784,810,826,844 'recommend':333,794 'refer':183,244,294,301,591,614 'regress':548,645,729 'relev':282,817 'request':253,904 'resourc':358 'respons':316,878 'result':229 'risk':36,212,410,699 'robust':162,508 'robust/clustered':540 'routledge.com':102 'routledge.com/9781032908724':101 'scale':661 'scenario':139 'se':163 'section':847,889 'ses':509 'show':910 'simul':536 'skill':194 'skill-39-vincentarelbundock-marginaleffects' 'slope':25,127,200,382,430,438,440,476,572,658,663,744 'slopes.md':600,621 'slopes.qmd':424 'smf':726 'smf.logit':731 'sourc':41,93,283 'source-brycewang-stanford' 'specif':668,749,888 'specifi':337,864 'standard':541 'start':176,272,371,905 'statist':74 'statsmodels.formula.api':724 'step':520 'studi':48,97 'summari':178,891 'syntax':221,264,815,835 'task':113 'test':33,129,167,171,231,340,341,400,443,449,822,834 'topic':363 'topic-academic-research' 'topic-agent-skills' 'topic-ai-agent' 'topic-awesome-list' 'topic-communication' 'topic-copaper' 'topic-economics' 'topic-education' 'topic-empirical-research' 'topic-international-relations' 'topic-political-science' 'topic-psychology' 'transform':588 'treatment':29,682,763,823 'turn':384 'uncertainti':156,334,336 'uncertainty.qmd':527 'unit':147,704 'unit-level':146 'usag':852 'use':18,192,260,267,347,437,453,472,879 'user':20,195,204,216,224,233,243,318,778,803,819,839,861,898 'util':608 'valu':137,391,669,750 'variabl':693,711,774 'variant':597 'vcov':545 'via':504,543 'vignett':50,99 'vincent':81 'vs':447,687,768 'want':225,820 'weight':153 'wt':650,679,734,760","prices":[{"id":"238cbfd4-528e-48a6-b808-fcc13008b1fb","listingId":"70f7c7c9-c85e-4788-a09b-4443da68d860","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"brycewang-stanford","category":"Awesome-Agent-Skills-for-Empirical-Research","install_from":"skills.sh"},"createdAt":"2026-04-18T22:12:46.134Z"}],"sources":[{"listingId":"70f7c7c9-c85e-4788-a09b-4443da68d860","source":"github","sourceId":"brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research/39-vincentarelbundock-marginaleffects","sourceUrl":"https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research/tree/main/skills/39-vincentarelbundock-marginaleffects","isPrimary":false,"firstSeenAt":"2026-04-18T22:12:46.134Z","lastSeenAt":"2026-05-02T12:52:56.522Z"}],"details":{"listingId":"70f7c7c9-c85e-4788-a09b-4443da68d860","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"brycewang-stanford","slug":"39-vincentarelbundock-marginaleffects","github":{"repo":"brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research","stars":598,"topics":["academic-research","agent-skills","ai-agent","awesome-list","communication","copaper","economics","education","empirical-research","international-relations","political-science","psychology","public-administration","reproducible-research","skills-library","social-science","sociology"],"license":"other","html_url":"https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research","pushed_at":"2026-04-30T20:01:12Z","description":"🔬 A curated collection of 23,000+ agent skills for empirical research across 8 social science disciplines. | 精选 23,000+ AI Agent 技能库，覆盖8大社会科学学科的实证研究。CoPaper.AI 20分钟完成一篇可复现的规范实证论文，并支持用户上传 Skills。-- Maintained by CoPaper.AI from Stanford REAP.","skill_md_sha":"7ab9f0e99d3958130543a3b1c3bba8034f21f2c4","skill_md_path":"skills/39-vincentarelbundock-marginaleffects/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research/tree/main/skills/39-vincentarelbundock-marginaleffects"},"layout":"multi","source":"github","category":"Awesome-Agent-Skills-for-Empirical-Research","frontmatter":{"name":"marginaleffects","license":"CC-BY-4.0","description":"Manual for the marginaleffects R and Python package, and guide to the book \"Model to Meaning\". Use when users ask about predictions, comparisons, slopes, marginal effects, average treatment effects (ATE/ATT/CATE), hypothesis testing, contrasts, counterfactuals, risk ratios, odds ratios, causal inference with G-computation, or need help with marginaleffects functions like predictions(), comparisons(), slopes(), hypotheses(), datagrid(), avg_predictions(), avg_comparisons(), avg_slopes(), or plot functions."},"skills_sh_url":"https://skills.sh/brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research/39-vincentarelbundock-marginaleffects"},"updatedAt":"2026-05-02T12:52:56.522Z"}}