You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Stargazer多模型场景下自定义置信区间设置报错求助

Stargazer多模型自定义置信区间解决方案

Stargazer默认用正态分布计算二项式模型的置信区间,指数化后结果不准确,需要手动传入基于模型默认轮廓似然区间的自定义置信区间。多模型场景下的正确操作如下:

错误原因

直接使用confint(model1, model2)会返回包含两个矩阵的列表,对列表直接执行exp()无法正确转换,且ci.custom要求传入每个模型对应一个置信区间矩阵的列表,而非包含多模型结果的单一列表。

正确代码示例

model1 <- glm(vs ~ mpg + hp, data = mtcars, family = 'binomial')
model2 <- glm(vs ~ mpg + disp, data = mtcars, family = 'binomial')

library(stargazer)

# 分别计算每个模型的轮廓似然置信区间并指数化(转换为OR值尺度)
ci_model1 <- exp(confint(model1))
ci_model2 <- exp(confint(model2))

# 传入自定义置信区间列表,每个元素对应一个模型
stargazer(model1, model2,
          apply.coef = exp,  # 系数指数化
          digits = 3,
          ci = TRUE,
          t.auto = FALSE,  # 禁用自动计算的置信区间/统计量
          type = "text",
          ci.custom = list(ci_model1, ci_model2))

注意事项

  • confint()默认计算轮廓似然置信区间(比正态近似更准确),如果需要指定置信水平,可添加参数level = 0.95(与Stargazer默认一致)。
  • 确保每个模型的置信区间矩阵维度与模型系数数量匹配,confint()会自动对应系数顺序,无需手动调整。

内容的提问来源于stack exchange,提问作者Schillerlocke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 05:40:22