不使用survcomp,补充完善以下代码,添加两两之间C-INDEX的对比是否有意义。library(foreign) library(survival) # 1. 导入数据集 my_data <- read.csv(file="D:/5放射诊断/R生存分析/nafld.csv") # 2. 转换分级变量 my_data$CACSgrades <- factor(my_data$CACSgrades) levels(my_data$CACSgrades) <- c("1", "2", "3", "4") my_data$CACSgrades <- relevel(my_data$CACSgrades, ref = "1") my_data$CADRADS <- factor(my_data$CADRADS) levels(my_data$CADRADS) <- c("0","1", "2", "3", "4", "5") my_data$CADRADS <- relevel(my_data$CADRADS, ref = "0") # 3.单因素Cox回归模型拟合 # 定义生存时间和事件结果变量 surv <- with(my_data, Surv(time, MACE==1)) #Cox回归模型拟合,多因素,CACSgrades fit_1 <- coxph(Surv(time, MACE==1) ~ age + Diabetes + Hypertension + CACSgrades + CADRADS + SIS + SSS, data = my_data) summary(fit_1) fit_2 <- coxph(Surv(time, MACE==1) ~ age + Diabetes + Hypertension + CACSgrades + CADRADS + SIS + SSS + NAFLD, data = my_data) summary(fit_2) fit_3 <- coxph(Surv(time, MACE==1) ~ age + Diabetes + Hypertension + CACSgrades + CADRADS + SIS + SSS + PCATgrade, data = my_data) summary(fit_3) fit_4 <- coxph(Surv(time, MACE==1) ~ age + Diabetes + Hypertension + CACSgrades + CADRADS + SIS + SSS + PCATgrade + NAFLD, data = my_data) summary(fit_4)
时间: 2024-04-22 19:22:56 浏览: 91
# 4. 计算每个模型的 C-INDEX
library(survival)
sum_surv1 <- summary(fit_1)
c_index_1 <- sum_surv1$concordance
sum_surv2 <- summary(fit_2)
c_index_2 <- sum_surv2$concordance
sum_surv3 <- summary(fit_3)
c_index_3 <- sum_surv3$concordance
sum_surv4 <- summary(fit_4)
c_index_4 <- sum_surv4$concordance
# 5. 计算每个模型之间的 C-INDEX 差异
c_index_diff <- c(fit_1 vs. fit_2 = abs(c_index_1 - c_index_2),
fit_1 vs. fit_3 = abs(c_index_1 - c_index_3),
fit_1 vs. fit_4 = abs(c_index_1 - c_index_4),
fit_2 vs. fit_3 = abs(c_index_2 - c_index_3),
fit_2 vs. fit_4 = abs(c_index_2 - c_index_4),
fit_3 vs. fit_4 = abs(c_index_3 - c_index_4))
# 6. 判断每两个模型之间的C-INDEX差异是否有意义
# 定义检验函数,使用log-rank检验
logrank_test <- function(model1, model2, data) {
fit1 <- survfit(model1, data)
fit2 <- survfit(model2, data)
result <- survdiff(fit1, fit2)
p_value <- 1 - pchisq(result$chisq, length(result$n)-1)
return(p_value)
}
# 对比每两个模型之间的C-INDEX差异是否有意义
p_value_1_2 <- logrank_test(fit_1, fit_2, my_data)
p_value_1_3 <- logrank_test(fit_1, fit_3, my_data)
p_value_1_4 <- logrank_test(fit_1, fit_4, my_data)
p_value_2_3 <- logrank_test(fit_2, fit_3, my_data)
p_value_2_4 <- logrank_test(fit_2, fit_4, my_data)
p_value_3_4 <- logrank_test(fit_3, fit_4, my_data)
# 判断是否有意义
if(p_value_1_2 < 0.05) {
cat("fit_1和fit_2之间的C-INDEX差异有意义\n")
} else {
cat("fit_1和fit_2之间的C-INDEX差异无意义\n")
}
if(p_value_1_3 < 0.05) {
cat("fit_1和fit_3之间的C-INDEX差异有意义\n")
} else {
cat("fit_1和fit_3之间的C-INDEX差异无意义\n")
}
if(p_value_1_4 < 0.05) {
cat("fit_1和fit_4之间的C-INDEX差异有意义\n")
} else {
cat("fit_1和fit_4之间的C-INDEX差异无意义\n")
}
if(p_value_2_3 < 0.05) {
cat("fit_2和fit_3之间的C-INDEX差异有意义\n")
} else {
cat("fit_2和fit_3之间的C-INDEX差异无意义\n")
}
if(p_value_2_4 < 0.05) {
cat("fit_2和fit_4之间的C-INDEX差异有意义\n")
} else {
cat("fit_2和fit_4之间的C-INDEX差异无意义\n")
}
if(p_value_3_4 < 0.05) {
cat("fit_3和fit_4之间的C-INDEX差异有意义\n")
} else {
cat("fit_3和fit_4之间的C-INDEX差异无意义\n")
}
阅读全文