我试图简化我的代码以避免使用for循环,但当我运行我的cox比例风险代码来提取系数的p值和标准误差时,我遇到了困难。我的代码如下:
library(survival)
#Generate Data
x = matrix(rbinom(10000,1,.5),ncol=100)
y = rexp(ncol(x),.02)
censor = rbinom(ncol(x),1,.5)
event = ifelse(censor==1,0,1)
#Fit the coxph model to the data
ans = apply(x,1,function(x,y,event)coxph(Surv(y,event)~x),y=y,event=event)
#Extract the coefficients from ans
coef = unname(sapply(ans,function(x)x$coef))
正如您所见,我能够从ans
对象中提取系数,但是我无法提取p值和标准误差。是否有一种简单的方法可以从我的ans
对象中实现这一点?或者有一种简单的方法修改这段代码以实现它吗?