Thomas Speidel
Thomas Speidel

Reputation: 1443

Quantile Plot in RMS::orm

I'm not sure if this question is more pertinent to CrossValidated or StackOverflow. I'm happy to migrate it if necessary.

I'm trying to reproduce the plots from Roger Koenker's quantile regression vignette but utilizing Frank Harrell's ordinal regression model.

Here are Koenker's plots on page 8 (I'm mostly interested in the plot of quantiles vs. predictor): Koenker's plot Page 8

R Code

I can produce similar plots but not quite the same. For instance:

## 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()

I believe SAS produces a similar plot in proc quantreg.

Upvotes: 2

Views: 294

Answers (1)

Yonghao
Yonghao

Reputation: 176

The 2 plots are likely to be similar but not the same because orm (cumulative probability model) uses a different modelling process from rq (quantile regression model) . In orm, predicted median values derive from the estimated conditional cumulative distribution function. Of interest, Figure 14 in Liu et al (2017) provides a comparison of conditional median values generated from the 2 models.

Reference
Liu Q, Shepherd BE, Li C, Harrell FE. Modeling continuous response variables using ordinal regression. Statistics in Medicine 2017 Nov 30;36(27):4316-4335. doi: 10.1002/sim.7433.

Upvotes: 1

Related Questions