# 如何在R中的索引图中添加p值？How can I add p-value to my concordance index plot in R?

`````` surv <- with(group, Surv(group\$survival, group\$time))

# calculate survival
sum.surv_1 <-  with(group, summary(coxph(surv ~ group\$1)))
sum.surv.1_2 <-  with(group, summary(coxph(surv ~ group\$1 + group\$2,ties = T)))

c_index.1 <- sum.surv_1\$concordance
c_index.1_2 <- sum.surv.1_2\$concordance

Comb_cIndex = data.frame(rbind(c_index.1["concordance.concordant"],
c_index.1_2["concordance.concordant"]))

barplot(as.matrix(Comb_cIndex), beside=TRUE, axis.lty=1,
ylab = "C Index", ylim = c(0, 0.8),
col = c("green", "blue"))
``````

## 1 个回复1

### ===============>>#1 票数：0

``````round(cindex.comp(c_index_no_ties1, c_index_no_ties2)\$p.value,3)
``````

``````cindex.p.ties <- function(c_index_ties1, c_index_ties2, c_index_no_ties1, c_index_no_ties2) {
eps <- 1E-15
n <- c_index_no_ties1\$n
r <- cor(c_index_no_ties1\$data\$x, c_index_no_ties2\$data\$x, use="complete.obs", method="spearman")
if ((1 - abs(r)) > eps) {
t.stat <- (c_index_ties1\$concordance - c_index_ties2\$concordance) / sqrt(c_index_ties1\$std.err^2 + c_index_ties2\$std.err^2 - 2 * r * c_index_ties1\$std.err * c_index_ties2\$std.err)
diff.ci.p <- pt(q=t.stat, df=n - 1, lower.tail=FALSE)
} else { diff.ci.p <- 1 }
return(list("p.value"=diff.ci.p))
}
cindex.p.ties(c_index_ties1=c_index_ties1, c_index_ties2=c_index_ties2, c_index_no_ties1=c_index_no_ties1, c_index_no_ties2=c_index_no_ties2)
``````

1回复

2回复

1回复

1回复

1回复

1回复

1回复

1回复

1回复

1回复