【问题标题】:Quantile regression plot分位数回归图
【发布时间】:2018-01-09 02:49:20
【问题描述】:

我想知道如何将这些信息带入绘图以显示 0.025,0.25,0.50,0.75,0.975 处的分位数曲线。

library(quantreg)
data(engel)
attach(engel)
qs <- c(0.025,0.25,0.50,0.75,0.975)
cubic.rq <- rq(foodexp ~ poly(income, 3),qs, engel)
f <- coef(cubic.rq)

【问题讨论】:

标签: r ggplot2


【解决方案1】:

为了比较,我已经包含了线性回归线(用于三阶多项式拟合)和数据点。

library(tidyverse)
library(quantreg)
data(engel)

qs <- c(0.025,0.25,0.50,0.75,0.975)

ggplot(engel, aes(income, foodexp)) +
  geom_point(size=1, colour="grey70") +
  geom_quantile(quantiles=qs, formula=y ~ poly(x, 3), colour="red") +
  geom_smooth(method='lm', formula=y ~ poly(x,3), colour="blue", 
              se=FALSE, linetype="11") +
  theme_classic()

【讨论】:

  • 太好了,非常感谢,只是一个问题。你设置了method="lm",我应该把它改成method="rq"吗?
  • geom_smooth 语句仅用于绘制蓝色“标准”线性回归线,与分位数回归无关。它只是为了比较。分位数回归线由geom_quantile绘制。
猜你喜欢
  • 2018-02-20
  • 1970-01-01
  • 1970-01-01
  • 2020-12-24
  • 2013-08-13
  • 2012-11-28
  • 2011-09-07
  • 2020-08-26
  • 2019-03-20
相关资源
最近更新 更多