HR=mycph(Surv(DFS, RECUR_YN==1)~.-OPTIME-OPFROMDT-OPDATE-OPDUR-PIDS-RECUR_D-PATHOLOGY-DEATH_D-LASTDD-RECUR_F_DATE-DEATH_F_DATE-RECUR_YN-DEATH_YN, data=dat)
> HR=mycph(Surv(DFS, RECUR_YN==1)~.-OPTIME-OPFROMDT-OPDATE-OPDUR-PIDS-RECUR_D-PATHOLOGY-DEATH_D-LASTDD-RECUR_F_DATE-DEATH_F_DATE-RECUR_YN-DEATH_YN, data=dat)
mycph : perform coxph of individual expecting variables
Call: Surv(DFS, RECUR_YN == 1) ~ . - OPTIME - OPFROMDT - OPDATE - OPDUR - , data= dat PIDS - RECUR_D - PATHOLOGY - DEATH_D - LASTDD - RECUR_F_DATE - , data= dat DEATH_F_DATE - RECUR_YN - DEATH_YN, data= dat
Error in .subset2(x, i, exact = exact) : no such index at level 1
mycph 를 사용할 때 빼주어야 하는 변수들이 어떤 것인지 여쭤보고 싶습니다. 제가 뺀 항목들이 문제가 있는 것인지요?
Comment 3
-
cardiomoon
2021.07.01 21:56
-
dejavu730
2021.07.06 16:28
예 여기에 올렸습니다.
-
cardiomoon
2021.07.07 09:14
네 제가 살펴보니 문제가 세가지 있었습니다.
1) 먼저 제가 mycph 함수를 만들때 formula가 윚의 경우와 같이 길어질 것을 생각못해 오류가 납니다. 그 부분을 고친 함수를 mycph2로 다시 만들었습니다.
2) mysph2함수를 호출할 때 데이터에 TS변수를 새로 만들어야 합니다.
3) formula에 DEATH_F_DATE가 있는데 데이터에는 DAETH_F_DATE 열이 있습니다.
위의 세가지 문제를 해결하니 정상적으로 작동됩니다
library(moonBook)
library(survival)
mycph2=function (formula, data, digits = 2)
{
temp=paste0(deparse(formula),collapse="")
call = paste(temp, ", ", "data= ", substitute(data),
sep = "")
cat("\n mycph : perform coxph of individual expecting variables\n")
cat("\n Call:", call, "\n\n")
f = formula
myt = terms(f, data = data)
y = as.character(f[[2]])
if (class(data[[y]]) != "Surv") {
cat(y, "is not an object of class Surv")
return(invisible())
}
myvar = attr(myt, "term.labels")
count = length(myvar)
var <- HR <- lcl <- ucl <- p.value <- c()
for (i in 1:count) {
s = paste(y, myvar[i], sep = "~")
suppressWarnings(out <- summary(survival::coxph(as.formula(s),
data)))
if (any(is.infinite(out$conf.int))) {
cat(dimnames(out$conf.int)[[1]], " was excluded : infinite\n")
next
}
if (any(is.nan(out$coef))) {
cat(dimnames(out$conf.int)[[1]], " was excluded : NaN\n")
next
}
if (any(is.na(out$coef))) {
cat(dimnames(out$conf.int)[[1]], " was excluded : NA\n")
next
}
var = c(var, dimnames(out$conf.int)[[1]])
HR = c(HR, out$coef[, 2])
lcl = c(lcl, out$conf.int[, 3])
ucl = c(ucl, out$conf.int[, 4])
p.value = c(p.value, out$coef[, 5])
}
if (length(HR) < 1)
return(invisible())
result = round(data.frame(HR, lcl, ucl), digits)
rownames(result) = var
result = cbind(result, round(p.value, max(3, digits)))
colnames(result)[4] = "p"
result
}
dat=read.csv("~/Downloads/CRF_FIN.csv")dat$TS=Surv(dat$DFS, dat$RECUR_YN==1)HR=mycph2(TS~.-OPTIME-OPFROMDT-OPDATE-OPDUR-PIDS-RECUR_D-PATHOLOGY-DEATH_D-LASTDD-RECUR_F_DATE-DAETH_F_DATE-RECUR_YN-DEATH_YN, data=dat)HRHR lcl ucl pT 1.07 1.02 1.13 0.008vascular.invasion 1.25 0.95 1.63 0.110lymphatic.invasion 1.30 1.05 1.61 0.016perineural.invasion 1.29 0.78 2.13 0.321HBP 1.12 0.46 2.70 0.808DM 0.64 0.09 4.55 0.655Stroke 0.91 0.51 1.61 0.739IHD 0.96 0.58 1.59 0.887COPD 2.57 1.56 4.26 0.000SMOKINGYN 1.25 0.98 1.58 0.070PRC 1.33 0.90 1.97 0.159LOCATION 1.00 0.93 1.07 0.957NODE 1.84 1.65 2.05 0.000stage 2.00 1.76 2.28 0.000RESEC 1.46 0.75 2.82 0.266AGE 1.00 0.99 1.01 0.773SEX 0.85 0.68 1.05 0.133HEIGHT 1.01 0.99 1.02 0.405WEIGHT 1.00 0.98 1.01 0.361BMI 0.97 0.94 1.00 0.092PHYSSTAT 1.26 0.96 1.65 0.097OPNM 1.04 0.92 1.17 0.519OPYR 0.94 0.82 1.08 0.366ANSDUR 1.00 1.00 1.00 0.000EXTUBATION 1.52 0.97 2.36 0.065ANESTH 0.91 0.76 1.09 0.314ANESTH2 1.05 0.83 1.32 0.701ANESTH3 0.96 0.76 1.20 0.701Tumor_size 0.96 0.90 1.03 0.286PRE_WBC 1.00 1.00 1.00 0.002PRE_NEU 1.01 1.00 1.02 0.071PRE_LYM 0.99 0.97 1.00 0.008PRE_NEU.PRE_LYM 1.03 0.99 1.07 0.191PRE_PLA.PRE_LYM 1.02 1.01 1.03 0.001PRE_HB 0.88 0.82 0.94 0.000PRE_PLA 1.00 1.00 1.00 0.000PST_WBC 1.00 1.00 1.00 0.181PST_NEU 1.01 0.99 1.02 0.345PST_LYM 0.99 0.97 1.01 0.192PST_HB 0.90 0.84 0.97 0.004PST_PLA 1.00 1.00 1.00 0.000OS 0.99 0.99 0.99 0.000BMI_C 0.84 0.67 1.06 0.138PRE_LYM_C 1.00 1.00 1.00 0.755PRE_NEU_C 1.00 1.00 1.00 0.004PRE_PLA_C 1.00 1.00 1.00 0.000PRE_NL_RATIO 1.03 0.99 1.07 0.189PRE_PW_RATIO 1.00 0.99 1.01 0.712PRE_PL_RATIO 1.00 1.00 1.00 0.007PRE_N_LP_RATIO 1.00 1.00 1.00 0.009PST_LYM_C 1.00 1.00 1.00 0.915PST_NEU_C 1.00 1.00 1.00 0.167PST_PLA_C 1.00 1.00 1.00 0.000PST_NL_RATIO 1.01 1.00 1.03 0.066PST_PW_RATIO 1.00 1.00 1.01 0.179PST_PL_RATIO 1.00 1.00 1.00 0.000PST_N_LP_RATIO 1.00 1.00 1.00 0.013PRE_PST_WBC 1.11 0.89 1.38 0.373PRE_PST_NEU 1.62 0.75 3.49 0.218PRE_PST_LYM 1.00 0.95 1.04 0.862PRE_PST_HB 0.85 0.43 1.66 0.627PRE_PST_PLA 1.20 0.68 2.12 0.525PRE_NL_RATIO_M 1.35 1.09 1.67 0.007PRE_PW_RATIO_M 1.07 0.87 1.33 0.526PRE_PL_RATIO_M 1.24 1.00 1.53 0.052PRE_N_LP_RATIO_M 1.52 1.23 1.89 0.000PST_NL_RATIO_M 1.15 0.93 1.42 0.198PST_PW_RATIO_M 1.23 0.99 1.52 0.061PST_PL_RATIO_M 1.41 1.14 1.75 0.002PST_N_LP_RATIO_M 1.33 1.07 1.64 0.010PRE_WBC_M 1.29 1.04 1.59 0.021PRE_NEU_M 1.31 1.06 1.62 0.013PRE_LYM_M 0.76 0.62 0.95 0.014PRE_HB_M 0.66 0.53 0.82 0.000PRE_PLA_M 1.71 1.37 2.13 0.000PST_WBC_M 1.17 0.94 1.44 0.161PST_NEU_M 0.97 0.79 1.20 0.801PST_LYM_M 0.90 0.72 1.11 0.317PST_HB_M 0.73 0.59 0.90 0.004PST_PLA_M 1.47 1.18 1.82 0.001PRE_PST_WBC_M 1.30 1.05 1.61 0.017PRE_PST_NEU_M 1.15 0.93 1.42 0.201PRE_PST_LYM_M 0.94 0.76 1.16 0.536PRE_PST_HB_M 0.96 0.78 1.19 0.721PRE_PST_PLA_M 0.99 0.80 1.22 0.893T_g 1.04 0.99 1.09 0.095NODE0 3.39 2.73 4.20 0.000
사용하신 데이터를 올려봐주시겠어요?