问题
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'?
回答1:
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
来源:https://stackoverflow.com/questions/30516275/adding-column-of-predicted-hazard-ratio-to-dataframe-after-cox-regression-in-r