diff --git a/DESCRIPTION b/DESCRIPTION index 67aeb9a..8375b57 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ Depends: R (>= 3.4.0) License: Apache License 2.0 Encoding: UTF-8 RoxygenNote: 7.3.2 -Imports: geepack, lme4, stats, data.table, labelled, tableone, coxme, survival (>= 3.0.0), survey, methods, dplyr, purrr, magrittr, tibble +Imports: geepack, lme4, stats, data.table, labelled, tableone, coxme, survival (>= 3.0.0), survey, methods, dplyr, purrr, magrittr, tibble, tidyr URL: https://github.com/jinseob2kim/jstable BugReports: https://github.com/jinseob2kim/jstable/issues Suggests: diff --git a/NEWS.md b/NEWS.md index 52ae2ee..7b95c36 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ * Update: Add event, count_by option in TableSubgroupCox, TableSubgroupMultiCox * Update: Add pairwise option in CreateTableOne2, CreateTableOneJS, svyCreateTableOne2, svyCreateTableOneJS * Update: Add `labeldata` option in `TableSubgroupGLM`, `TableSubgroupMultiGLM`, `TableSubgroupCox`, `TableSubgroupMultiCox` +* Fix: `cox2.display` HR # jstable 1.3.5 * Fix: error in `TableSubgroupMultiGLM` when covariates diff --git a/R/cox2.R b/R/cox2.R index b140751..4de98f2 100644 --- a/R/cox2.R +++ b/R/cox2.R @@ -68,17 +68,21 @@ cox2.display <- function(cox.obj.withmodel, dec = 2, msm = NULL) { names(uni.res)[ncol(uni.res)] <- "p" uni.res2 <- NULL if (mtype == "normal") { - uni.res2 <- uni.res[, c("z", "p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 3, 4, 5)] + if (length(grep("robust.se", names(uni.res))) > 0) { + uni.res2 <- uni.res[, c(1, 4, 5, 6)] + } } else if (mtype == "cluster") { - uni.res2 <- uni.res[, c("z", "p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 4, 5, 6)] } else { - uni.res2 <- uni.res[, c("p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[-nrow(uni.res), c(1, 3, 4, 6)] } fix.all <- coxExp(uni.res2, dec = dec) colnames(fix.all) <- c("HR(95%CI)", "P value") if (mtype == "frailty") { - rownames(fix.all) <- c(names(model$coefficients), "frailty") + #rownames(fix.all) <- c(names(model$coefficients), "frailty") + rownames(fix.all) <- names(model$coefficients) } else { rownames(fix.all) <- names(model$coefficients) } @@ -109,11 +113,14 @@ cox2.display <- function(cox.obj.withmodel, dec = 2, msm = NULL) { names(uni.res)[ncol(uni.res)] <- "p" uni.res2 <- NULL if (mtype == "normal") { - uni.res2 <- uni.res[, c("z", "p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 3, 4, 5)] + if (length(grep("robust.se", names(uni.res))) > 0) { + uni.res2 <- uni.res[, c(1, 4, 5, 6)] + } } else if (mtype == "cluster") { - uni.res2 <- uni.res[, c("z", "p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 4, 5, 6)] } else { - uni.res2 <- uni.res[, c("p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 3, 4, 6)] } return(uni.res2) }) @@ -140,17 +147,20 @@ cox2.display <- function(cox.obj.withmodel, dec = 2, msm = NULL) { # uni.res <- uni.res[c(2:nrow(uni.res), 1), ] # uni.res <- data.frame(summary(coxph(as.formula(paste("mdata[, 1]", "~", x, formula.ranef, sep="")), data = mdata))$coefficients) names(uni.res)[ncol(uni.res)] <- "p" - if ("robust.se" %in% names(uni.res)) { - uni.res$robust.se <- NULL - } + # if ("robust.se" %in% names(uni.res)) { + # uni.res$robust.se <- NULL + # } uni.res2 <- NULL if (mtype == "normal") { - uni.res2 <- uni.res[, c("z", "p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 3, 4, 5)] + if (length(grep("robust.se", names(uni.res))) > 0) { + uni.res2 <- uni.res[, c(1, 4, 5, 6)] + } } else if (mtype == "cluster") { - uni.res2 <- uni.res[, c("z", "p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 4, 5, 6)] } else { - uni.res2 <- uni.res[, c("p", names(uni.res)[grep("coef", names(uni.res))])] + uni.res2 <- uni.res[, c(1, 3, 4, 6)] } return(uni.res2) })