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

R语言如何从glm模型的summary结果中提取系数、空偏差等指定内容

R glm模型指定结果提取方案

summary(glm)返回的S3对象内置了你需要的所有目标字段,可分别提取对应字段后按需组合即可,各目标内容的提取方式如下:

  • 系数估计值:你之前调用$coefficients得到的是包含估计值、标准误、检验统计量、p值的完整系数矩阵,仅需指定提取Estimate列即可单独获取系数估计值,对应代码为summary(model)$coefficients[,"Estimate"]
  • 空偏差:对应字段为null.deviance,提取代码为summary(model)$null.deviance
  • 残差偏差:对应字段为deviance,提取代码为summary(model)$deviance
  • AIC:可直接从模型原始对象或summary结果中提取,代码为model$aic

完整可运行示例如下:

# 构建二项分布glm模型
model <- glm(am ~ disp + hp, data = mtcars, family = binomial)
sum_model <- summary(model)

# 提取各目标内容
coef_estimate <- sum_model$coefficients[, "Estimate"]
null_deviance <- sum_model$null.deviance
residual_deviance <- sum_model$deviance
aic_value <- model$aic

# 整理为列表统一输出
target_output <- list(
  系数估计值 = coef_estimate,
  空偏差 = null_deviance,
  残差偏差 = residual_deviance,
  AIC = aic_value
)

print(target_output)

运行上述代码后target_output就包含了你需要的全部内容,你也可以根据需求把结果转换为数据框格式存储。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 06:24:01