1

我不确定这个问题是否与 CrossValidated 或 StackOverflow 更相关。如有必要,我很乐意迁移它。

我试图从Roger Koenker分位数回归小插图中重现这些图,但使用Frank Harrell序数回归模型

这是 Koenker 在第 8 页上的图(我最感兴趣的是分位数与预测器的图): Koenker 的阴谋 第 8 页

代码

我可以制作类似的图,但不完全相同。例如:

## Load libraries
library(dplyr)
library(rms)
library(ggplot2)

## Simulate data
set.seed(123)
n <- 100
df <- data.frame(x1 = rnorm(n),
                 x2 = sample(c(-1,0,1), n, TRUE)) %>% 
  mutate(y = x1 + rnorm(n))

d <- datadist(df)
options(datadist="d")


## Fit ORM model
f1 <- orm(y ~ x1 + x2, data = df)


## Estimate quantiles
qu  <- Quantile(f1)
q25 <- function(x) qu(0.25, x)
q50 <- function(x) qu(0.50, x)
q75 <- function(x) qu(0.75, x)

## Point predictions
qplot <- Predict(f1, fun =q25) %>% mutate(q = 25) %>% 
  bind_rows(Predict(f1, fun = q50) %>% mutate(q = 50)) %>% 
  bind_rows(Predict(f1, fun = p75) %>% mutate(q = 75))

qplot %>% 
  mutate(q = as.factor(q)) %>% 
  ggplot(aes(x = x1, y = yhat, group = q, color = q)) +
  geom_line()

我相信 SAS 在proc quantreg.

4

1 回答 1

1

这两个图可能相似但不相同,因为(累积概率模型)使用与(分位数回归模型)orm不同的建模过程。rqorm中,预测的中值来自估计的条件累积分布函数。有趣的是,Liu et al (2017) 中的图 14 提供了从 2 个模型生成的条件中值的比较。

参考资料
Liu Q, Shepherd BE, Li C, Harrell FE。使用序数回归对连续响应变量进行建模。医学统计 2017 年 11 月 30 日;36(27):4316-4335。doi:10.1002/sim.7433。

于 2020-06-19T08:13:11.483 回答