Skip to content

Commit

Permalink
fix cox2.display
Browse files Browse the repository at this point in the history
  • Loading branch information
jinseob2kim committed Nov 14, 2024
1 parent b27dbd2 commit 2f94bc3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 23 additions & 13 deletions R/cox2.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down

0 comments on commit 2f94bc3

Please sign in to comment.