Skip to content

Commit 43f542e

Browse files
authored
#8: remove yardstick (#9)
Close #8
2 parents 306ba82 + 4be0e01 commit 43f542e

File tree

5 files changed

+45
-30
lines changed

5 files changed

+45
-30
lines changed

DESCRIPTION

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: stats4phc
22
Title: Performance Evaluation for the Prognostic Value of Predictive Models Intended to Support
33
Personalized Healthcare Through Predictiveness Curves and Positive / Negative Predictive Values
4-
Version: 0.1.1
4+
Version: 0.1.2
55
Authors@R: c(
66
person("Ondrej", "Slama", email = "[email protected]", role = c("aut", "cre")),
77
person("Darrick", "Shen", email = "[email protected]", role = "aut"),
@@ -36,8 +36,7 @@ Imports:
3636
isotone (>= 1.1.0),
3737
mgcv (>= 1.8.41),
3838
pracma (>= 2.4.2),
39-
tidyr (>= 1.3.0),
40-
yardstick (>= 1.1.0)
39+
tidyr (>= 1.3.0)
4140
Suggests:
4241
knitr,
4342
rmarkdown,

R/PV.R

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,19 @@ nonParametricPV <- function(outcome, score) {
3434
ppv <- vapply(
3535
thresh.predictions,
3636
function(x) {
37-
yardstick::ppv_vec(
38-
truth = factor(outcome, levels = c("1", "0")),
39-
estimate = factor(x, levels = c("1", "0")),
40-
event_level = "first"
41-
)
37+
tp <- sum(outcome == 1 & x == 1)
38+
fp <- sum(outcome == 0 & x == 1)
39+
tp / (tp + fp)
4240
},
4341
numeric(1)
4442
)
4543

4644
npv <- vapply(
4745
thresh.predictions,
4846
function(x) {
49-
yardstick::npv_vec(
50-
truth = factor(outcome, levels = c("1", "0")),
51-
estimate = factor(x, levels = c("1", "0")),
52-
event_level = "first"
53-
)
47+
tn <- sum(outcome == 0 & x == 0)
48+
fn <- sum(outcome == 1 & x == 0)
49+
tn / (tn + fn)
5450
},
5551
numeric(1)
5652
)
@@ -136,35 +132,27 @@ nonParametricTR <- function(outcome, score) {
136132

137133
# Calc sensitivities and specificities at each risk percentile threshold
138134
senses <- vapply(
139-
thresh.predictions[1:(length(score) - 1)],
135+
thresh.predictions,
140136
function(x) {
141-
yardstick::sens_vec(
142-
truth = factor(outcome, levels = c("1", "0")),
143-
estimate = factor(x, levels = c("1", "0")),
144-
event_level = "first"
145-
)
137+
sum(outcome == 1 & x == 1) / sum(outcome == 1)
146138
},
147139
numeric(1)
148140
)
149141

150142
specs <- vapply(
151-
thresh.predictions[1:(length(score) - 1)],
143+
thresh.predictions,
152144
function(x) {
153-
yardstick::spec_vec(
154-
truth = factor(outcome, levels = c("1", "0")),
155-
estimate = factor(x, levels = c("1", "0")),
156-
event_level = "first"
157-
)
145+
sum(outcome == 0 & x == 0) / sum(outcome == 0)
158146
},
159147
numeric(1)
160148
)
161149

162150
# Create a data.frame
163151
dat <- data.frame(
164-
score = c(min(score), score),
165-
percentile = c(0, ecdf(score)(score)),
166-
Sensitivity = c(1, senses, 0),
167-
Specificity = c(0, specs, 1)
152+
score = score,
153+
percentile = ecdf(score)(score),
154+
Sensitivity = senses,
155+
Specificity = specs
168156
) %>%
169157
tidyr::pivot_longer(
170158
cols = c("Sensitivity", "Specificity"),

R/sensSpec.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ sensSpec <- function(outcome,
6767
dat <- split(dat, dat$method) %>%
6868
lapply(\(d) nonParametricTR(outcome = d$outcome, score = d$estimate)) %>%
6969
bind_rows(.id = "method")
70+
71+
if (!plot.raw) {
72+
dat <- add0thPercTR(dat)
73+
}
7074

7175
# Plot
7276
p <- ggplot(dat) +

R/utils.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,30 @@ add0thPercPV <- function(x) {
303303
}
304304

305305

306+
add0thPercTR <- function(x) {
307+
bind_rows(
308+
x,
309+
x %>%
310+
group_by(.data$method) %>%
311+
summarise(
312+
score = NA,
313+
percentile = 0,
314+
pf = "Sensitivity",
315+
value = 1
316+
),
317+
x %>%
318+
group_by(.data$method) %>%
319+
summarise(
320+
score = NA,
321+
percentile = 0,
322+
pf = "Specificity",
323+
value = 0
324+
)
325+
) %>%
326+
arrange(.data$method, .data$pf, .data$percentile)
327+
}
328+
329+
306330
#' For snapshot testing of graphs
307331
#'
308332
#' @param code Code to create a graph

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ remotes::install_github(repo = "genentech/stats4phc")
3030
For reproducibility, refer to a specific version tag, for example
3131

3232
``` r
33-
remotes::install_github(repo = "genentech/stats4phc", ref = "v0.1.1")
33+
remotes::install_github(repo = "genentech/stats4phc", ref = "v0.1.2")
3434
```
3535

3636

0 commit comments

Comments
 (0)