Can anyone help optimise this workflow? I'd like to skip the steps where I manually create "sensitivity" and "sens_hat" and somehow get these data from "cfx" and "summary(cfx)". Any ideas?
library(tidymodels)
options(yardstick.event_first = FALSE)
set.seed(2018)
x <- tibble(pred = ordered(rbinom(20, 1, 0.5)),
truth = ordered(rbinom(20, 1, 0.5)))
cfx <- conf_mat(x, truth, pred)
cfx
#> Truth
#> Prediction 0 1
#> 0 5 4
#> 1 6 5
summary(cfx)
#> # A tibble: 12 x 2
#> name value
#> <chr> <dbl>
#> 1 accuracy 0.5
#> 2 kappa NA
#> 3 sens 0.556
#> 4 spec 0.455
#> 5 prevalence 0.45
#> 6 ppv 0.455
#> 7 npv 0.556
#> 8 mcc 0.0101
#> 9 j_index 0.0101
#> 10 precision 0.455
#> 11 recall 0.556
#> 12 F1 0.5
sensitivity <- tibble(sens = c("fn", "fn", "fn", "fn",
"tp","tp", "tp", "tp", "tp"))
sens_hat <- sensitivity %>%
specify(response = sens, success = "tp") %>%
calculate(stat = "prop")
sens_hat
#> # A tibble: 1 x 1
#> stat
#> <dbl>
#> 1 0.556
boot <- sensitivity %>%
specify(response = sens, success = "tp") %>%
generate(reps = 1000, type = "bootstrap") %>%
calculate(stat = "prop")
get_ci(boot)
#> # A tibble: 1 x 2
#> `2.5%` `97.5%`
#> <dbl> <dbl>
#> 1 0.222 0.889
Created on 2018-09-09 by the reprex
package (v0.2.0).