Jarmin
Jarmin

Reputation: 31

Set a reference group and change is value in cox regression with R

I want to perform a cox regression analysis, as shown in the picture, how can I do to set a reference group and change is HR into 1 and others are the specific value to the reference group?

enter image description here

Upvotes: 1

Views: 2902

Answers (1)

Frank Harrell
Frank Harrell

Reputation: 2230

Instead of worrying about which value of a covariate is a "reference" value, directly estimate the quantities of interest. For example you can estimate and get confidence limits for all hazard ratios against x=7. Here is the easy way when using the R rms package, which has a function cph which is a front-end for the R survival package coxph function.

require(rms)
dd <- datadist(mydata); options(datadist='dd')
# Example model with 3 predictors, interaction with the variable
# x1 that you are interested in.  So hazard ratios will depend on x2
# which we set to 10.  Omit x2 from list() if want to use the default
# value (median/mode of x2).  The following obtains hazard ratios for
# x1 = 6 7 8 9 against x1 = 7.
f <- cph(Surv(time, event) ~ x1 * x2 + x3, data=mydata)
contrast(f, list(x1=6 : 9, x2=10), list(x1=7, x2=10))
# Type ?contrast.rms to see how to plot these with confidence limits

To get survival probabilities use the survest function but note that the column heading you had is misleading because there is no one survival probability.

Upvotes: 1

Related Questions