Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding column of predicted Hazard Ratio to dataframe after Cox Regression in R

I need to add columns of predicted hazard ratio in the dataframe after running Cox PH regression in R. The dataframe is a panel data where numgvkey if firm identifier and age is time identifier. You can download a small section of the date from this link: https://drive.google.com/file/d/0B8usDJAPeV85VFRWd01pb0h1MDA/view?usp=sharing

I have don the following:

library(survival)
library(readstata13)
sme <- read.dta13("sme.dta")
reg<-coxph(Surv(age,EVENT2)~L1FETA+frailty(numgvkey), ties=c("efron"),  data=sme)
summary(reg)
hr <- predict(reg, type="risk")

How can I add a 5th column of "Hazard Ratio"(hr) in my 'sme' dataframe? Also, is there any way to predict the EVENT2 probability rather than 'hr'?

like image 965
Jairaj Gupta Avatar asked May 28 '15 20:05

Jairaj Gupta


People also ask

How do you find the hazard ratio on Coxph?

The hazard ratio HR = exp(coef) = 1.01, with a 95% confidence interval of 0.99 to 1.03. Because the confidence interval for HR includes 1, these results indicate that age makes a smaller contribution to the difference in the HR after adjusting for the ph.

How do you display hazard ratio?

As a formula, the hazard ratio, which can be defined as the relative risk of an event happening at time t, is: λ(t) / λ0. A hazard ratio of 3 means that three times the number of events are seen in the treatment group at any point in time.

What is hazard ratio in Cox regression?

The hazard ratio is the ratio of these two expected hazards: h0(t)exp (b1a)/ h0(t)exp (b1b) = exp(b1(a-b)) which does not depend on time, t. Thus the hazard is proportional over time.


1 Answers

The predict.coxph function allows you to generate several different "type" of output. One of them is "expected" which may be what you mean by "probability". It's not really a probability since the numbers sometimes exceed 1.0 when the relative risk, "baseline hazard" and times under observation are high.

The "risk" option for "type" returns the hazard ratio.

There is a survfit.coxph which allows one to calculate predicted survival. The object it returns has both surv and a cumhaz list components.

You might want to try this:

sme$cumhaz <- survfit(fit, newdata=sme)$cumhaz
like image 103
IRTFM Avatar answered Sep 20 '22 23:09

IRTFM