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

为何stat_poly_eq与lm的R²估计值存在显著差异?

回归模型R²结果差异的排查思路

核心原因

你得到的两个R²值差异极大,本质是两组分析使用的x变量尺度完全不同:lm()用的是原始浓度值,而ggplot2的stat_poly_eq用的是log2转换后的浓度值。

数据与初始建模

你的数据如下:

data <- structure(list(standard_conc_ngul = c(50, 50, 50, 5, 5, 0.5, 
0.5, 0.05, 0.05, 0.005, 0.005, 0.005), ct = c(18.3305377960205, 
18.133768081665, 17.8813705444336, 21.5002365112305, 21.4915542602539, 
22.7616996765137, 23.6836719512939, 25.3699340820312, 25.3488445281982, 
28.984302520752, 26.7397594451904, 27.8844776153564)), row.names = c(NA, 
-12L), class = c("tbl_df", "tbl", "data.frame"))

直接对原始浓度做线性回归,得到的R²为0.692817:

model <- lm(ct ~ standard_conc_ngul, data = data)
summary(model)$r.squared
# [1] 0.692817

ggplot中的隐藏变量转换

你在绘图代码中加入了scale_x_continuous(trans="log2"),这会自动对standard_conc_ngul做log2转换。此时stat_poly_eq和stat_smooth(method=lm)都是基于转换后的x变量拟合线性模型,相当于你实际运行的是ct ~ log2(standard_conc_ngul),而非原始变量的回归。

验证方法

手动拟合转换后的模型,就能得到和stat_poly_eq一致的R²:

model_log <- lm(ct ~ log2(standard_conc_ngul), data = data)
summary(model_log)$r.squared
# 结果会接近0.973

总结

  • lm()使用原始浓度值,变量间线性关系弱,R²低
  • ggplot中的回归基于log2转换后的浓度值,此时浓度与ct值的线性关系极强,因此R²接近0.97

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 12:02:42