如何检测黄土95%CI的宽度达到某个量?

问题描述 投票:0回答:1

我用95%CI拟合了一条黄土曲线,现在我希望能够确定CI到达特定宽度的位置。

例如,使用“汽车”数据集:

plot <- ggplot (cars, aes (x=speed, y=dist)) +
geom_point() +
stat_smooth (method= "loess", se=TRUE) +
xlab("Speed")+
ylab("Distance")+
theme_bw()
plot

plot

我希望能够找出CI的“速度”值等于20个距离单位。查看该图,可能约为7和24。

谢谢!

r ggplot2 confidence-interval loess
1个回答
0
投票

您可以使用ggplot_build(plot)提取有关ggplot2中内置的图层的相关数据和其他杂项信息。

在这种情况下,置信区间的限制在yminymax列中,可以使用:

foo <- ggplot_build(plot)
foo[["data"]][[2]]

然后您可以进行简单的变异来检查ymaxymin之间的差异,以及通过x列CI间隔达到20的“速度”。

mutate_info <- foo[["data"]][[2]] %>% dplyr::mutate(ci_gap = ymax-ymin)
© www.soinside.com 2019 - 2024. All rights reserved.