From 2b0ece71d5c9b89a0f1214001f48c071f0c4ddef Mon Sep 17 00:00:00 2001 From: Ondrej Slama Date: Fri, 14 Feb 2025 16:00:38 +0100 Subject: [PATCH] #6: addressing shift in PPV by one row --- R/PV.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/PV.R b/R/PV.R index f508b46..b0d6c65 100644 --- a/R/PV.R +++ b/R/PV.R @@ -32,7 +32,7 @@ nonParametricPV <- function(outcome, score) { thresh.predictions <- lapply(score, function(x) as.numeric(score > x)) ppv <- vapply( - thresh.predictions[1:(length(score) - 1)], + thresh.predictions, function(x) { yardstick::ppv_vec( truth = factor(outcome, levels = c("1", "0")), @@ -44,7 +44,7 @@ nonParametricPV <- function(outcome, score) { ) npv <- vapply( - thresh.predictions[1:(length(score) - 1)], + thresh.predictions, function(x) { yardstick::npv_vec( truth = factor(outcome, levels = c("1", "0")), @@ -58,8 +58,8 @@ nonParametricPV <- function(outcome, score) { threshold.data <- data.frame( score = score, percentile = ecdf(score)(score), - PPV = c(prev, ppv), - NPV = c(npv, 1 - prev) + PPV = ppv, + NPV = npv ) %>% mutate(MNPV = 1 - .data$NPV) %>% tidyr::fill(