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

如何在polr模型的比值比结果中添加显著性星号及标准误

手动处理polr模型结果:添加OR显著性星号与标准误

实现步骤与代码

假设你已经用MASS::polr()拟合了比例优势模型(注意必须设置Hess = TRUE才能计算p值),以下是完全手动提取并处理结果的代码:

library(MASS)
# 用内置数据集做示例,替换成你的模型即可
data("housing")
model <- polr(Sat ~ Infl + Type + Cont, data = housing, Hess = TRUE)

# 提取模型摘要的系数表
coef_info <- summary(model)$coefficients

# 拆分核心统计量
coefs <- coef_info[, 1]          # 线性系数
std_err <- coef_info[, 2]        # 标准误
p_vals <- coef_info[, 4]         # p值
odds_ratios <- exp(coefs)        # 计算比值比(OR)

# 定义显著性星号规则:*p<0.05,**p<0.01,***p<0.001
add_signif_stars <- function(p) {
  stars <- ifelse(p < 0.001, "***",
                  ifelse(p < 0.01, "**",
                         ifelse(p < 0.05, "*", "")))
  return(stars)
}

# 给OR添加星号
or_with_stars <- paste0(round(odds_ratios, 3), add_signif_stars(p_vals))

# 整合成最终结果表
final_table <- data.frame(
  变量 = names(coefs),
  线性系数 = round(coefs, 3),
  标准误 = round(std_err, 3),
  比值比 = round(odds_ratios, 3),
  比值比_带显著性 = or_with_stars,
  p值 = round(p_vals, 4)
)

# 打印结果
print(final_table, row.names = FALSE)

关键说明

  • 拟合模型时必须加Hess = TRUE,否则summary()不会输出p值
  • 用exp(coefs)将线性系数转换为比值比,这是比例优势模型的标准转换方式
  • 星号规则可根据需求自行调整,修改add_signif_stars()函数即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 03:15:40