为什么stat_poly_eq和lm对r2的估计值不同

xpcnnkqh  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(112)

我想弄清楚我的回归模型有多好。我有一些数据,像这样:

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"))

> print(data)
# A tibble: 12 × 2
   standard_conc_ngul    ct
                <dbl> <dbl>
 1             50      18.3
 2             50      18.1
 3             50      17.9
 4              5      21.5
 5              5      21.5
 6              0.5    22.8
 7              0.5    23.7
 8              0.05   25.4
 9              0.05   25.3
10              0.005  29.0
11              0.005  26.7
12              0.005  27.9

使用lm建模时,得到的r2为0.692817

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

但是当我在图上使用stat_poly_eq时,r2是0.973,非常不同!

ggplot(data, aes(x = standard_conc_ngul, y = ct)) +
  geom_point() +
  stat_smooth(method = lm, formula = y ~ x) +
  scale_x_continuous(trans="log2") +
  stat_poly_eq(formula = y ~ x,
               aes(label = paste(after_stat(eq.label), after_stat(rr.label), sep = "~~~")),
               parse = TRUE, coef.digits = 3, f.digits = 3, p.digits = 3, 
               rr.digits = 3)

我不明白为什么会不一样!有什么主意吗?

d4so4syb

d4so4syb1#

如果移除log电子秤,则输出相同:

library(ggplot2)
library(ggpmisc)

ggplot(data, aes(x = standard_conc_ngul, y = ct)) +
  geom_point() +
  stat_smooth(method = lm, formula = y ~ x) +
  #scale_x_continuous(trans="log2") +
  stat_poly_eq(formula = y ~ x,
               aes(label = paste(after_stat(eq.label), after_stat(rr.label), sep = "~~~")),
               parse = TRUE, coef.digits = 3, f.digits = 3, p.digits = 3, 
               rr.digits = 3)

创建于2023年1月25日,使用reprex v2.0.2

相关问题