I was previously informed in another thread that my plot on the y-axis is showing odds and not odds ratios. The following example code and figure depict this.
library(survival)
data(cancer, package="survival")
d <- colon[, c("age", "status")]
table(d$status)
dd <- datadist(d); options(datadist='dd')
fit <- lrm(status ~ rcs(age, 4), data=d)
predictions <- Predict(fit, age, ref.zero=TRUE, fun=exp)
ggplot(predictions) + ylab("Predicted odds")
In my understanding: The odds are defined as the probability that the event will occur divided by the probability that the event will not occur. With regard to my example, the overall odds would be 0.98.
> table(d$status)
0 1
938 920
> round(920/938, 2)
[1] 0.98
Based on this, I do understand that a single point in the plot above shows the odds for a specific age.
From this understanding, I would assume that the scale on the y-axis would be hazard and not hazard ratio for a time to event outcome. However, the two following screenshots show figures of published papers with hazard ratios on the y-axis. What do I get wrong?
Johannesen CDL, et al. BMJ. 2020.
Rawshani A, et al. N Engl J Med. 2018.
Update after Björn's answer
Thanks for your detailed answer! Let me rephrase it in my own words to see if I understood it correctly.
- When the plot shows odds or probability, the value on the Y-axis must be interpreted separately for each value of x, and the 95% CI should not be zero at any point (case #1).
- When the plot shows odds ratio (or possibly risk ratio), the value on the Y-axis must be interpreted in relation to the reference x value; the y value should be equal to 1 for the reference x value, and the 95% CI should be zero at this point (case #2).
I tried to demonstrate this using examples with the rms
package and the spline
package. I believe that I did it correct using the rms
package, but I am not sure how to do it (case #2) with the spline
package.
### Case #1 using rms
library(survival)
data(cancer, package="survival")
d <- colon[, c("age", "status")]
table(d$status)
dd <- datadist(d); options(datadist='dd')
# dd$limits["Adjust to","age"] <- 60
fit <- lrm(status ~ rcs(age, 4), data=d)
predictions <- Predict(fit, age, ref.zero=FALSE, fun=exp)
ggplot(predictions) + ylab("Predicted Odds")
### Case #2 using rms
library(survival)
data(cancer, package="survival")
d <- colon[, c("age", "status")]
table(d$status)
dd <- datadist(d); options(datadist='dd')
dd$limits["Adjust to","age"] <- 60
fit <- lrm(status ~ rcs(age, 4), data=d)
predictions <- Predict(fit, age, ref.zero=TRUE, fun=exp)
age_range <- data.frame(age = seq(from = 27, to = 81, length = 100))
ggplot(predictions) + ylab("Predicted Odds Ratio")
### Case #1 using spline
library(survival)
data(cancer, package="survival")
d <- colon[, c("age", "status")]
fit <- glm("status ~ ns(age, 3)", family=binomial(link="logit"), data=d)
age_range <- data.frame(age = seq(from = 27, to = 81, length = 100))
predictions <- predict(fit, newdata = age_range, se.fit=TRUE, type = "link", level = 0.95)
x <- data.frame(age = age_range$age,
effect = exp(predictions$fit),
lower = exp(predictions$fit - 1.96 * predictions$se.fit),
upper = exp(predictions$fit + 1.96 * predictions$se.fit),
model = "ns")
ggplot(data = x, aes(x = age, y = effect)) +
geom_line() +
geom_ribbon(aes(ymin = lower, ymax = upper), alpha = 0.2) +
xlab("Age") +
ylab("Predicted Odds")