4
4
# ' @param TPF True Positive Fraction
5
5
# '
6
6
# ' @return a list with positive and negative likelihood ratios
7
+ # ' @export
8
+ # '
9
+ # ' @examples
10
+ # ' getLRatios(.4, .6)
7
11
getLRatios <- function (FPF , TPF ){
8
12
list (
9
13
negative = (1 - TPF ) / (1 - FPF ),
@@ -17,6 +21,11 @@ getLRatios <- function(FPF, TPF){
17
21
# ' @param TPF True Positive Fraction
18
22
# '
19
23
# ' @return a value
24
+ # ' @export
25
+ # ' @importFrom stats qlogis plogis
26
+ # '
27
+ # ' @examples
28
+ # ' getOR(.4, .6)
20
29
getOR <- function (FPF , TPF ){
21
30
logOR <- qlogis(TPF ) - qlogis(FPF )
22
31
exp(logOR )
@@ -28,10 +37,12 @@ getOR <- function(FPF, TPF){
28
37
# ' @param TPF True Positive Fraction
29
38
# '
30
39
# ' @return a tibble with of FPF and TPF values
40
+ # ' @export
41
+ # ' @importFrom stats qlogis plogis
31
42
getIsoOR <- function (FPF , TPF ) {
32
43
OR <- getOR(FPF , TPF )
33
44
x <- seq(0 , 1 , length.out = 101 )
34
- tibble(FPF = x ) %> %
45
+ tibble :: tibble (FPF = x ) %> %
35
46
mutate(TPF = ifelse(FPF %in% c(0 , 1 ),
36
47
FPF ,
37
48
plogis(qlogis(x ) + log(OR ))
@@ -44,26 +55,41 @@ getIsoOR <- function(FPF, TPF) {
44
55
# ' @param TPF True Positive Fraction
45
56
# '
46
57
# ' @return a tibble with intercept and slope for each LR
58
+ # ' @export
47
59
getIsoLR <- function (FPF , TPF ){
48
60
lRatios <- getLRatios(FPF , TPF )
49
- tribble(
61
+ tibble :: tribble(
50
62
~ type , ~ intercept , ~ slope ,
51
63
" positive" , 0 , lRatios $ positive ,
52
64
" negative" , 1 - lRatios $ negative , lRatios $ negative
53
65
)
54
66
}
55
67
56
68
69
+ # ' Get predictive values
70
+ # '
71
+ # ' @param FPF False Positive Fraction
72
+ # ' @param TPF True Positive Fraction
73
+ # ' @param prior a vector of prior probabilities. If NULL, will compute over (0,1)
74
+ # '
75
+ # ' @return a tibble with:
76
+ # ' - prior
77
+ # ' - type: "negative" or "positive"
78
+ # ' - posterior: posterior probabilities
79
+ # ' @export
80
+ # ' @importFrom dplyr inner_join mutate
81
+ # ' @examples
82
+ # ' getPredValues(.4, .6, .5)
57
83
getPredValues <- function (FPF , TPF , prior = NULL ) {
58
84
# get LR as a list and transform in a tidy format
59
85
lRatios <- getLRatios(FPF , TPF ) %> %
60
- as_tibble() %> %
61
- pivot_longer(c(positive , negative ), names_to = " type" )
86
+ tibble :: as_tibble() %> %
87
+ tidyr :: pivot_longer(c(positive , negative ), names_to = " type" )
62
88
63
89
# if prior unspecified, compute over ]0-1[
64
90
if (is.null(prior )) prior <- seq(0 , 1 , length.out = 101 )
65
91
66
- dat <- expand_grid(
92
+ dat <- tidyr :: expand_grid(
67
93
prior = prior ,
68
94
type = c(" positive" , " negative" )
69
95
)
@@ -76,10 +102,30 @@ getPredValues <- function(FPF, TPF, prior = NULL) {
76
102
}
77
103
78
104
105
+ # ' Prettify proportions
106
+ # '
107
+ # ' @param prop A proportion
108
+ # ' @param digits passed to round()
109
+ # '
110
+ # ' @return A pretty string
111
+ # ' @export
112
+ # '
113
+ # ' @examples
114
+ # ' prettyProp(.501)
79
115
prettyProp <- function (prop , digits = 0 ){
80
116
paste0(round(100 * prop , digits ), " %" )
81
117
}
82
118
119
+ # ' Prettify ratios
120
+ # '
121
+ # ' @param ratio A ratio
122
+ # ' @param digits passed to signif()
123
+ # '
124
+ # ' @return A pretty string
125
+ # ' @export
126
+ # '
127
+ # ' @examples
128
+ # ' prettyRatio(1/2.41)
83
129
prettyRatio <- function (ratio , digits = 2 ){
84
130
if (ratio > = 1 ){
85
131
paste0(signif(ratio , digits ), " : 1" )
0 commit comments