从R中的coxph中提取pvalues和se(coef)

从R中的coxph中提取pvalues和se(coef),r,survival-analysis,R,Survival Analysis,我试图简化我的代码以避免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

我试图简化我的代码以避免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
对象中有没有一种简单的方法可以做到这一点?或者用一种简单的方法来修改此代码?

您只需添加这两行代码即可获得p值和std错误

pValues <- sapply(1:length(ans), function(x) {summary(ans[[x]])$coefficients[5]})

sd <- sapply(1:length(ans), function(x) {summary(ans[[x]])$coefficients[3]})

pValues Hi,您知道是否可以不提取系数而提取exp(ceof)?