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")
我可以得到这个情节:
我的问题是灰色区域是如何定义的?这是什么意思 我该如何使用各种参数来控制波段的宽度?
默认情况下,它是线性模型("lm")的预测的95%置信水平区间. ?geom_smooth
中的文档指出:
此几何的默认统计信息为 stat_smooth .请参阅该文档,以了解更多控制基础统计转换的选项.
从?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)
With the following code:
library(ggplot2)
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(colour=factor(cyl))) +
geom_smooth(method="lm")
I can get this plot:
My question is how does the grey zone defined? What's the meaning of it. And how can I play around with various parameter that control the width of that band?
By default, it is the 95% confidence level interval for predictions from a linear model ("lm"). The documentation from ?geom_smooth
states that:
The default stat for this geom is stat_smooth see that documentation for more options to control the underlying statistical transformation.
Digging one level deeper, doc from ?stat_smooth
tells us about the methods used to calculate the smoother's area.
For quick results, one can play with one of the arguments for stat_smooth which is level
: level of confidence interval to use (0.95 by default)
By passing that parameter to geom_smooth, it is passed in turn to stat_smooth, so that if you wish to have a narrower region, you could use for instance .90 as a confidence level:
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(aes(colour=factor(cyl))) +
geom_smooth(method="lm", level=0.90)
这篇关于ggplot geom_smooth lm中带宽的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!