SuperAPI AI 工具集

marginaleffects

编程与开发

查看项目

更新于 10-15 17:30

技能介绍

用途:marginaleffects 是 R 和 Python 的软件包手册,同时是配套书《Model to Meaning: How to Interpret Statistical Models in R and Python》(作者 Vincent Arel-Bundock,2026,CRC Press)的指南。主要信息源为 https://marginaleffects.com,提供免费书籍、案例与 vignettes。适用于用户询问预测值、比较、斜率或边际效应,选择估计量(ATE、ATT、CATE、风险差、优势比),函数语法与参数,解释模型结果或检验假设,以及反事实分析、G-computation 或因果推断等场景。

核心框架:每个分析可分解为五个问题——Quantity(估计量:预测、比较、斜率或检验)、Predictors/Grid(在何处评估:观测值、反事实情景、平衡网格)、Aggregation(对谁聚合:单元级、by= 分组均值、加权平均)、Uncertainty(推断方法:delta 法、稳健标准误、bootstrap、贝叶斯)、Test(假设:零假设检验、等价性、成对对比)。

主要能力:R 端核心函数包括 predictions()、comparisons()、slopes()、hypotheses() 及 avg_* 变体,datagrid() 构造网格,plot_predictions()、plot_comparisons()、plot_slopes() 绘图,另有 posterior_draws()、inferences()、get_dataset()。Python 端提供 predictions、avg_predictions、comparisons、avg_comparisons、slopes、avg_slopes、hypotheses、datagrid、plot_* 以及 fit_statsmodels、fit_sklearn、fit_linearmodels 等模型拟合辅助。

使用方式:先判断请求属于概念类(读 chapters/)、实现类(读 man/r/ 或 man/python/)还是混合类;再读取对应源文件,如 chapters/framework.qmd、predictions.qmd、comparisons.qmd、slopes.qmd、hypothesis.qmd、interactions.qmd、categorical.qmd、experiments.qmd、gcomputation.qmd、uncertainty.qmd、mrp.qmd、ml.qmd、challenge.qmd,以及 man/r/ 与 man/python/ 下的函数参考。回答时按五问框架组织,并给出对应语言的代码示例。示例:R 中 avg_slopes(mod)、predictions(mod, newdata = datagrid(hp = c(100,150,200), wt = 3))、avg_comparisons(mod, variables = list(hp = c(100,150)))、avg_comparisons(mod, variables = list(hp = 50), comparison = "ratio");Python 中 me.avg_slopes(mod)、me.predictions(mod, newdata=me.datagrid(mod, hp=[100,150,200], wt=3))、me.avg_comparisons(mod, variables={"hp": [100,150]})。

限制:资料未提供具体收费、价格、平台支持范围或性能效果等信息,暂未提供。用户未指定 R 或 Python 时应先询问偏好再给代码。