Skip to content

Commit

Permalink
0723
Browse files Browse the repository at this point in the history
  • Loading branch information
wognsths committed Jul 23, 2024
1 parent b7a6d9b commit d370c61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: jstable
Title: Create Tables from Different Types of Regression
Version: 1.3.1
Date: 2024-07-17
Version: 1.3.2
Date: 2024-07-23
Authors@R: c(person("Jinseob", "Kim", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9403-605X")),
person("Zarathu", role = c("cph", "fnd")),
person("Yoonkyoung","Jeon", role = c("aut")),
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# jstable 1.3.2

* Fix: error in subgroup option due to non-existent item in `forestcox`

# jstable 1.3.1

* Fix: `addOverall` options to `svyCreateTableOneJS`
* Fix: `TableSubgroupCox`


# jstable 1.3.0

* Update: Add `weights` option to `TableSubgroupCox` and `TableSubgroupMultiCox` for marginal cox model. ex: `weights = "weights"`
Expand Down
13 changes: 6 additions & 7 deletions R/forestcox.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TableSubgroupCox <- function(formula, var_subgroup = NULL, var_cov = NULL, data,
if (is.numeric(data[[var_subgroup]])) stop("var_subgroup must categorical.")
# if (length(levels(data[[as.character(formula[[3]])]])) != 2) stop("Independent variable must have 2 levels.")
}

## functions with error
possible_table <- purrr::possibly(table, NA)
possible_prop.table <- purrr::possibly(function(x) {
Expand Down Expand Up @@ -192,7 +192,6 @@ TableSubgroupCox <- function(formula, var_subgroup = NULL, var_cov = NULL, data,
stop("Please input correct subgroup variable.")
} else {
### subgroup 지정 한 경우 ###

# 공변량 있는 경우 formula 변경
if (!is.null(var_cov)) {
formula <- as.formula(paste0(deparse(formula), " + ", paste(var_cov, collapse = "+")))
Expand All @@ -205,7 +204,7 @@ TableSubgroupCox <- function(formula, var_subgroup = NULL, var_cov = NULL, data,

if (any(class(data) == "survey.design")) {
### survey data인 경우 ###

data$variables[[var_subgroup]] <- factor(data$variables[[var_subgroup]])
data$variables[[var_subgroup]] %>%
table() %>%
names() -> label_val
Expand Down Expand Up @@ -261,7 +260,7 @@ TableSubgroupCox <- function(formula, var_subgroup = NULL, var_cov = NULL, data,
} else {
### survey data가 아닌 경우 ###
weights_option <- if (!is.null(weights)) TRUE else FALSE

data[[var_subgroup]] <- factor(data[[var_subgroup]])
# Coxph 함수를 각 subgroup에 대해 적용시키기 위한 함수
run_coxph <- function(subgroup_var, subgroup_value, data, formula, weights_option) {
subset_data <- data[data[[subgroup_var]] == subgroup_value, ]
Expand Down Expand Up @@ -414,7 +413,7 @@ TableSubgroupCox <- function(formula, var_subgroup = NULL, var_cov = NULL, data,
)
}) %>%
Reduce(rbind, .) -> CI

model %>%
purrr::map(possible_pv) %>%
purrr::map_dbl(~ round(., decimal.pvalue)) -> pv
Expand Down Expand Up @@ -453,11 +452,11 @@ TableSubgroupCox <- function(formula, var_subgroup = NULL, var_cov = NULL, data,

# output 만들기
if (ncoef < 2) {
out <- data.frame(Variable = paste(" ", label_val), Count = Count, Percent = round(Count / sum(Count) * 100, decimal.percent), `Point Estimate` = Point.Estimate, Lower = CI[, 1], Upper = CI[, 2], check.names = F) %>%
out <- data.frame(Variable = paste(" ", label_val), Count = Count, Percent = round(Count / sum(Count) * 100, decimal.percent), `Point Estimate` = Point.Estimate, Lower = CI[, 1], Upper = CI[, 2], check.names = F, row.names = NULL) %>%
mutate(`P value` = ifelse(pv >= 0.001, pv, "<0.001"), `P for interaction` = NA)

if (!is.null(prop)) {
out <- data.frame(Variable = paste(" ", label_val), Count = Count, Percent = round(Count / sum(Count) * 100, decimal.percent), `Point Estimate` = Point.Estimate, Lower = CI[, 1], Upper = CI[, 2], check.names = F) %>%
out <- data.frame(Variable = paste(" ", label_val), Count = Count, Percent = round(Count / sum(Count) * 100, decimal.percent), `Point Estimate` = Point.Estimate, Lower = CI[, 1], Upper = CI[, 2], check.names = F, row.names = NULL) %>%
cbind(prop) %>%
mutate(`P value` = ifelse(pv >= 0.001, pv, "<0.001"), `P for interaction` = NA)
}
Expand Down

0 comments on commit d370c61

Please sign in to comment.