# This example code is written for analyses of the ovarian cancer dataset adopted in Royston and White (2011; Journal of Statistical Software 45: Issue 4). # The article page of Journal of Statistical Software: https://www.jstatsoft.org/article/view/v045i04/ # The ovarian cancer dataset ("ovariancancer.dta") can be downloaded from https://www.jstatsoft.org/index.php/jss/article/downloadSuppFile/v045i04/ovariancancer.dta require(mice) require(survival) require(foreign) tgc <- read.dta(file="ovariancancer.dta") head(tgc) N <- dim(tgc)[1] attach(tgc) log_ca125 <- log(ca125) log_alp <- log(alp) grade <- factor(grade, levels=c("well differentiated", "moderately differentiated", "poorly differentiated")) histol <- factor(histol, levels=c("Serous papillary", "Adenocarcinoma", "Endometrioid", "Mesonephroid (clear cell)", "Mixed mesodermal", "Mucinous", "Undifferentiated" )) resdis <- factor(resdis, levels=c(">5 cm", "2-5 cm", "<2 cm")) t <- tgc[,20] - tgc[,21] d <- tgc[,19] tgce <- data.frame(patno, age, figo, grade, histol, ascites, ps, resdis, log_ca125, log_alp, d, t) detach(tgc) #### # Model 1: Complete-Case Analysis ph1 <- coxph(Surv(t, d) ~ age + figo + grade + histol + ascites + ps + resdis + log_ca125 + log_alp, data=tgce) summary(ph1) # Model 2: mice predmt1 <- (1 - diag(1, ncol(tgce))) predmt1[c(1,11,12),] <- predmt1[,c(1,11,12)] <- 0 imp.tgce <- mice(tgce, m=200, predictorMatrix=predmt1, seed=34871) # m は、代入値の組の数(デフォルトでは5であるが、ここでは200としている) # predictorMatrixで、予測モデルに含める変数の組を指定している # methodで、代入値の生成方法を指定できる。特に指定しなければ、デフォルトの方法を採用。 # seedは、乱数のシード print(imp.tgce) complete(imp.tgce, 5) # 5番目のimputed datasetを出力 ph2 <- with(imp.tgce, coxph(Surv(t, d) ~ age + figo + grade + histol + ascites + ps + resdis + log_ca125 + log_alp)) # 補完後のデータセット(M組)の解析;Cox回帰 pool2 <- pool(ph2) round(summary(pool2),3) # M組の解析結果の統合と結果の表⽰