ggplot geom_smooth lm 中带宽的含义
Meaning of band width in ggplot geom_smooth lm
使用以下代码:
library(ggplot2)
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(colour=factor(cyl))) +
geom_smooth(method="lm")
我可以得到这个情节:
我的问题是灰色地带是怎么定义的?这是什么意思。
以及如何使用控制该波段宽度的各种参数?
这是置信区间。如果不想显示,可以使用se=FALSE
。如果您想要 99% CI 而不是 95% CI,您也可以使用 level = 0.99
。有关所有详细信息,请参阅 ?stat_smooth
。
默认情况下,它是线性模型 ("lm") 预测的 95% 置信水平区间。 ?geom_smooth
的文档指出:
The default stat for this geom is stat_smooth see that documentation for more options to control the underlying statistical transformation.
深入挖掘一层,来自 ?stat_smooth
的文档告诉我们用于计算平滑器面积的方法。
为了快速获得结果,可以使用 stat_smooth 的参数之一,即 level
: 置信区间水平使用(默认为 0.95)
通过将该参数传递给 geom_smooth,它又被传递给 stat_smooth,这样如果你希望有一个更窄的区域,你可以使用例如 .90 作为置信度:
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(colour=factor(cyl))) +
geom_smooth(method="lm", level=0.90)
使用以下代码:
library(ggplot2)
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(colour=factor(cyl))) +
geom_smooth(method="lm")
我可以得到这个情节:
我的问题是灰色地带是怎么定义的?这是什么意思。 以及如何使用控制该波段宽度的各种参数?
这是置信区间。如果不想显示,可以使用se=FALSE
。如果您想要 99% CI 而不是 95% CI,您也可以使用 level = 0.99
。有关所有详细信息,请参阅 ?stat_smooth
。
默认情况下,它是线性模型 ("lm") 预测的 95% 置信水平区间。 ?geom_smooth
的文档指出:
The default stat for this geom is stat_smooth see that documentation for more options to control the underlying statistical transformation.
深入挖掘一层,来自 ?stat_smooth
的文档告诉我们用于计算平滑器面积的方法。
为了快速获得结果,可以使用 stat_smooth 的参数之一,即 level
: 置信区间水平使用(默认为 0.95)
通过将该参数传递给 geom_smooth,它又被传递给 stat_smooth,这样如果你希望有一个更窄的区域,你可以使用例如 .90 作为置信度:
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(colour=factor(cyl))) +
geom_smooth(method="lm", level=0.90)