我想知道是否可以在 R 中繪制一條回歸線,包括 - 2* 標準誤差。例如,使用iris:
library(ggplot2)
ggplot(iris, aes(x = Petal.Length, y = Sepal.Width)) geom_smooth(method=lm, color="black") theme_bw()
輸出是:

如何(如果可能)將灰色區域擴展為標準誤差的兩倍?
uj5u.com熱心網友回復:
實作您想要的結果的一種選擇是通過stat_smooth并使用以下方法手動添加置信區間after_stat:
library(ggplot2)
ggplot(iris, aes(x = Petal.Length, y = Sepal.Width))
geom_smooth(method = lm, color = "black", se = FALSE)
stat_smooth(aes(ymin = after_stat(y - 2 * se), ymax = after_stat(y 2 * se)), geom = "ribbon", method = lm, fill = "grey60", alpha = .4)
theme_bw()
#> `geom_smooth()` using formula 'y ~ x'
#> `geom_smooth()` using formula 'y ~ x'

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/358886.html
