C- statiustic和95%Ci

时间:2017-05-01 13:24:54

标签: r

我正在尝试为我的C统计量计算95%CI,但是,代码无效。试过这个:

calculating confidence interval for C-statistic
library(rms)

CstatisticCI <- function(x=Dead_or_alive$Data.Juste) #x is the object of rcorr.cens.
{se <- x["S.D."]/sqrt(x["n"]) 
Low95 <- x["C Index"] - 1.96*se 
Upper95 <- x["C Index"] + 1.96*se 
cbind(x["C Index"], Low95, Upper95) 
CstatisticCI(CoxModel02.lrm.pen.rcorr)}

CoxModel02.lrm.rcorr <- rcorr.cens(x=predict(CoxModel02.lrm), S=CoxModel02$Data.Juste)
CoxModel02.lrm.rcorr

还有一个:

library(rms)
Cindexdiff <- function(data=Data.Juste, indices=CoxModel02,CoxModel03){
  data <- Data.Juste[indices,]# select obs. in bootstrap sample
  # C-statistic DFS+ CACS:
  C1   <- lrm(CoxModel02, data=Data.Juste, x=T,
                                            y=T,
                                           se.fit= T)$stats["C"]
  # C-statistic DFS+CACS+ CAD_RADS:
  C2   <- lrm(CoxModel03, data=Data.Juste, x=T,
              y=T,
              se.fit=T)$stats["C"] 
  as.numeric(C2-C1) # returns the difference
}

library(boot)
set.seed(1)
b <- boot(data=Data.Juste, Cindexdiff, 999)
boot.ci(b, type = c("norm", "basic", "bca"))

有人可以给我一个提示,为什么代码没有给我任何输出?

亲切的问候, 中庸之道

1 个答案:

答案 0 :(得分:0)

经过细微更改后,您的代码运行良好。

library(rms)

CstatisticCI <- function(x) {
  se <- x["S.D."]/sqrt(x["n"])
  Low95 <- x["C Index"] - 1.96*se 
  Upper95 <- x["C Index"] + 1.96*se 
  cbind(x["C Index"], Low95, Upper95) 
}

set.seed(1)
x <- round(rnorm(200))
y <- rnorm(200)
rcorr.cens(x, y, outx=TRUE)   # can correlate non-censored variables
library(survival)
age <- rnorm(400, 50, 10)
bp  <- rnorm(400,120, 15)
bp[1]  <- NA
d.time <- rexp(400)
cens   <- runif(400,.5,2)
death  <- d.time <= cens
d.time <- pmin(d.time, cens)

out.rcorr <- rcorr.cens(age, Surv(d.time, death))   
CstatisticCI(out.rcorr)

                      Low95   Upper95
C Index 0.4992573 0.4956571 0.5028576