You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:
41
42
42
-
```{r cars}
43
+
## What does our example dataset look like?
44
+
45
+
```{r}
46
+
example_data
47
+
```
48
+
49
+
50
+
## Let's apply a threshold of 0.2
51
+
52
+
This means we will call all predictions with a probability >= 0.2 as `TRUE`.
53
+
54
+
```{r}
55
+
example_data %>%
56
+
apply_threshold(0.2)
57
+
```
58
+
59
+
60
+
## Let's calculate a net benefit with a threshold of 0.2
61
+
62
+
63
+
```{r}
43
64
example_data %>%
44
-
apply_all(0.2) %>%
45
-
calculate_nb(verbose = TRUE)
65
+
apply_threshold(0.2) %>%
66
+
calculate_net_benefit()
67
+
```
68
+
69
+
## What is going on behind the scenes?
70
+
71
+
Behind the scenes, the `calculate_net_benefit()` function is calculating the number of true and false positives, and then using that along with the previously applied threshold to calculate the net benefit.
72
+
73
+
### How did `calculate_net_benefit()` know about the threshold?
74
+
75
+
This information is captured in the `thresholds` attribute.
46
76
77
+
```{r}
47
78
example_data %>%
48
79
apply_threshold(0.2) %>%
49
-
calculate_nb()
80
+
attributes() %>%
81
+
.$thresholds
82
+
```
83
+
### Want more information about the number of true and false positives?
84
+
85
+
Set the `verbose` argument of `calculate_net_benefit()` to `TRUE`. This will print, *not* return, a data frame with the information it used to calculate the net benefit. The value returned is still the net benefit.
50
86
87
+
```{r}
88
+
example_data %>%
89
+
apply_threshold(0.2) %>%
90
+
calculate_net_benefit(verbose = TRUE)
91
+
```
92
+
93
+
## What happens when you apply an absolute constraint?
94
+
95
+
Two of the five predicted `TRUE` values are converted to `FALSE` because only the first 3 `TRUE` values (those with the highest predicted probability) are able to be acted upon.
96
+
97
+
```{r}
98
+
example_data %>%
99
+
apply_threshold(0.2) %>%
100
+
apply_constraint(3)
101
+
```
102
+
103
+
104
+
## Calculate a realized net benefit with a threshold of 0.2 and an capacity of 3
105
+
106
+
This is an example of an *absolute* constraint.
107
+
108
+
```{r}
51
109
example_data %>%
52
110
apply_threshold(0.2) %>%
53
111
apply_constraint(3) %>%
54
-
calculate_nb()
112
+
calculate_net_benefit(verbose = TRUE)
55
113
114
+
```
56
115
116
+
117
+
## Calculate a realized net benefit with an absolute threshold of 0.2 and capacity of 3, and *then* a relative constraint of 0.5:
118
+
119
+
```{r}
57
120
example_data %>%
58
121
apply_threshold(0.2) %>%
59
122
apply_constraint(3) %>%
60
123
apply_threshold(0.5) %>%
61
-
calculate_nb()
124
+
calculate_net_benefit(verbose = TRUE)
125
+
```
62
126
127
+
## The default assumption when we set a threshold without a subsequent constraint is that the capacity is infinite.
63
128
64
-
bind_rows(
65
-
example_data %>%
129
+
You can also explicitly note the infinite capacity, which will be applied only to the immediate prior threshold.
130
+
131
+
```{r}
132
+
example_data %>%
133
+
apply_threshold(0.2) %>%
134
+
apply_constraint(3) %>%
135
+
apply_threshold(0.5) %>%
136
+
apply_constraint(Inf) %>%
137
+
calculate_net_benefit()
138
+
```
139
+
140
+
141
+
Using this mechanism, you can construct multiple layers of absolute and relative constraints as the piped functions retain metadata about prior constraints and thus know that each constraint applies to only the prior threshold.
142
+
143
+
You *cannot* apply a threshold that is *lower* than a prior threshold because it would make no sense to apply a permissive criterion *before* a more restrictive one.
144
+
145
+
## Setting a new threshold that is lower than the prior one will generate an error.
146
+
147
+
```{r error = TRUE}
148
+
example_data %>%
66
149
apply_threshold(0.5) %>%
67
150
apply_constraint(3) %>%
68
-
calculate_nb(),
69
-
example_data %>%
70
-
apply_threshold(0.6) %>%
71
-
apply_constraint(3) %>%
72
-
calculate_nb(),
73
-
example_data %>%
74
-
apply_threshold(0.7) %>%
75
-
apply_constraint(3) %>%
76
-
calculate_nb(),
77
-
example_data %>%
78
-
apply_threshold(0.8) %>%
79
-
apply_constraint(3) %>%
80
-
calculate_nb()
81
-
)
151
+
apply_threshold(0.2) %>%
152
+
calculate_net_benefit()
153
+
```
154
+
155
+
156
+
## Setting a new threshold that is the same as a prior one will generate a warning.
82
157
158
+
In a future version, this may be upgraded to an error.
159
+
160
+
```{r error = TRUE}
83
161
example_data %>%
84
-
apply_threshold(0.6) %>%
162
+
apply_threshold(0.2) %>%
85
163
apply_constraint(3) %>%
86
-
apply_threshold(0.5) %>%
87
-
apply_constraint(Inf) %>%
88
-
calculate_nb()
164
+
apply_threshold(0.2) %>%
165
+
calculate_net_benefit()
166
+
```
89
167
90
-
# Vary absolute constraint
168
+
# Let's plot a decision curve for an absolute constraint, and an absolute + relative constraint
0 commit comments