【发布时间】:2020-04-08 10:00:39
【问题描述】:
我想请教如何绘制分位数标准错误,例如 R 中 quantreg 包中的基本功能
library(quantreg)
library(ggplot2)
library(dplyr)
QR.2 <- rq(hp ~ disp + mpg + I(mpg^2) + qsec + am, data = mtcars, tau = 1:9/10)
plot(summary(QR.2, se="boot"), ols=T)
上图显示了分位数标准误差和置信区间。有没有办法在 ggplot 中重现相同的情节?
尝试下面的代码是一个很好的开始,但是 geom_ribbon(aes(ymin=conf.low,ymax=conf.high),alpha=0.25, fill="#27408b") 确实返回“置信区间”,但显然这些与上面的情节不同。
有没有办法获得conf。如上图所示的间隔?
rq(data=mtcars,
tau= 1:9/10,
formula = hp ~ disp + mpg + I(mpg^2) + qsec + am) %>%
broom::tidy() %>%
filter(!grepl("factor", term)) %>%
filter(!grepl("Intercept", term)) %>%
ggplot(aes(x=tau,y=estimate))+
geom_point(color="#27408b", size = 3)+
geom_line(color="#27408b", size = 1)+
geom_smooth(method= "lm", colour = "red", se = T)+
facet_wrap(~term, scales="free", ncol=2) +
geom_ribbon(aes(ymin=conf.low,ymax=conf.high),alpha=0.25, fill="#27408b")
【问题讨论】:
标签: r ggplot2 regression