在R中Cox回归后添加预测危害比率列到数据框 [英] Adding column of predicted Hazard Ratio to dataframe after Cox Regression in R
问题描述
https://drive.google.com/file/d/0B8usDJAPeV85VFRWd01pb0h1MDA/view?usp=sharing
我已经不了了以下内容:
库(生存)
库(readstata13)
sme < - read.dta13(sme.dta)
reg< -coxph(Surv(age,EVENT2)〜L1FETA + frailty(numgvkey),ties = c(efron),data = sme)
summary(reg)
hr< ; - 预测(reg,type =risk)
如何添加第5列危险比率(hr)在我的sme数据框?另外,有没有办法预测EVENT2概率而不是'hr'?
.coxph
函数允许您生成几种不同的类型输出。其中一个是预期的,这可能是你的概率的意思。这不是真的一个概率,因为当相对风险基准危害和观察次数较高时,数字有时会超过1.0。
类型的风险选项返回风险比。
有一个survfit.coxph可以计算预测的生存期。它返回的对象既有 surv
和一个 cumhaz
列表组件。
您可能想尝试这样:
sme $ cumhaz< - 幸存(fit,newdata = sme)$ cumhaz
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'?
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
这篇关于在R中Cox回归后添加预测危害比率列到数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!