Skip to content

Commit

Permalink
AssScalar: precision_ci_ul now available as metric
Browse files Browse the repository at this point in the history
  • Loading branch information
lgessl committed Aug 9, 2024
1 parent 98290cc commit 890bb02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions R/ass_scalar_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ get_metric <- function(
metric_v <- numeric(length(ass_scalar$metrics))
thresholds <- 1
hr_and_more <- numeric(4)
prec_ci <- numeric(2)
if (!binary_bool) {
thresholds <- unique(predicted)
prevs <- vapply(thresholds, function(t) mean(predicted >= t), numeric(1))
Expand Down Expand Up @@ -195,11 +196,15 @@ get_metric <- function(
},
"precision_ci_ll" = {
check_one_threshold()
j_res <- stats::binom.test(
prec_ci <- stats::binom.test(
x = sum(actual[predicted >= thresholds]),
n = sum(predicted >= thresholds),
conf.level = ass_scalar$confidence_level
)$conf.int[1]
)$conf.int
j_res <- prec_ci[1]
},
"precision_ci_ul" = {
j_res <- prec_ci[2]
},
"hr" = {
check_one_threshold()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- badges: end -->

## An R package for binary classification of survival
## An R package pipelining binary classification of survival

### What's the scenario this R package is made for?

Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-ass_scalar.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ test_that("AssScalar$assess_center() works", {
n_na_in_pheno <- 5
n_fold <- 2
multiple_metrics <- c("precision", "accuracy", "n_true", "perc_true", "n_samples",
"logrank", "threshold", "prevalence", "precision_ci_ll", "hr", "hr_ci_ll", "hr_ci_ul", "hr_p")
"logrank", "threshold", "prevalence", "precision_ci_ll", "precision_ci_ul", "hr", "hr_ci_ll",
"hr_ci_ul", "hr_p")
single_metric <- "auc"

dir <- withr::local_tempdir()
Expand Down Expand Up @@ -189,6 +190,9 @@ test_that("AssScalar$assess_center() works", {
expect_equal(nrow(eval_tbl), length(model_list)-1)
expect_equal(colnames(eval_tbl), c("model", "cohort", ass_scalar$metrics))
expect_true(is.numeric(as.matrix(eval_tbl[, 3:ncol(eval_tbl)])))
expect_true(all(eval_tbl[["precision_ci_ll"]] < eval_tbl[["precision_ci_ul"]]))
expect_true(all(0 < eval_tbl[["precision_ci_ll"]]))
expect_true(all(eval_tbl[["precision_ci_ul"]] <= 1))

data$cohort <- "test"
ass_scalar$metrics <- "precision"
Expand Down

0 comments on commit 890bb02

Please sign in to comment.