-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
236 lines (163 loc) · 6.97 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r eval=FALSE, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# rtichoke
<!-- badges: start -->
[![R-CMD-check](https://github.com/uriahf/rtichoke/workflows/R-CMD-check/badge.svg)](https://github.com/uriahf/rtichoke/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/rtichoke)](https://CRAN.R-project.org/package=rtichoke)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Codecov test coverage](https://codecov.io/gh/uriahf/rtichoke/branch/main/graph/badge.svg)](https://codecov.io/gh/uriahf/rtichoke?branch=main)
<!-- badges: end -->
For some reproducible examples please visit [rtichoke blog](https://rtichoke-blog.netlify.app/)!
## Installation
<!-- You can install the released version of rtichoke from [CRAN](https://CRAN.R-project.org) with: -->
<!-- ``` r -->
<!-- install.packages("rtichoke") -->
<!-- ``` -->
You can install rtichoke from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("uriahf/rtichoke")
```
<!-- TODO change to good model, bad model and random guess -->
## Overview:
- `rtichoke` is designed to help analysts with exploration of performance metrics with a binary outcome. In order to do so it uses interactive visualization.
## Getting started
### Predictions and Outcomes as input
<!-- - ` is designed for interactive visualization for performance metrics of prediction models with a binary outcome. -->
<!-- -- -->
<!-- It is agnostic in a sense that it does not care about the models that were used to develop predictions. It takes only the estimated probabilities of an outcome -->
In order to use `rtichoke` you need to have
- `probs`: Estimated Probabilities as predictions.
- `reals`: Binary Outcomes.
There are 3 different cases and for each one of them rtichoke requires a different kind of input:
### Singel Model:
The user is required to provide a list with one vector for the predictions and a list with one vector for the outcomes.
<!-- ```{r echo=FALSE} -->
<!-- library(rtichoke) -->
<!-- set.seed(123) -->
<!-- predictions_and_outcomes <- tibble::tibble( -->
<!-- probs = example_dat$bad_model, -->
<!-- real = as.numeric( -->
<!-- rtichoke::example_dat$outcome) -->
<!-- ) -->
<!-- predictions_and_outcomes %>% -->
<!-- dplyr::sample_n(replace = FALSE, size = 6) %>% -->
<!-- gt::gt() %>% -->
<!-- gt::cols_align(align = "center") %>% -->
<!-- gt::fmt_number(columns = probs, -->
<!-- decimals = 2) -->
<!-- ``` -->
```{r eval=FALSE, include=TRUE}
create_roc_curve(
probs = list(example_dat$bad_model),
reals = list(example_dat$outcome)
)
```
### Models Comparison:
**Why?**
In order to compare performance for several different models for the same population.
**How?**
The user is required to provide a list with one vector of predictions for each model and a list with one vector for the outcome of the population.
<!-- ```{r echo=FALSE} -->
<!-- library(rtichoke) -->
<!-- set.seed(42) -->
<!-- predictions_and_outcomes <- tibble::tibble( -->
<!-- "Good Model" = example_dat$estimated_probabilities, -->
<!-- "Bad Model" = example_dat$bad_model, -->
<!-- "Random Guess" = example_dat$random_guess, -->
<!-- real = as.numeric(rtichoke::example_dat$outcome)) -->
<!-- predictions_and_outcomes %>% -->
<!-- dplyr::sample_n(replace = FALSE, size = 6) %>% -->
<!-- gt::gt() %>% -->
<!-- gt::cols_align(align = "center") %>% -->
<!-- gt::fmt_number(columns = 1:3, -->
<!-- decimals = 2) -->
<!-- ``` -->
```{r eval=FALSE, include = TRUE}
create_roc_curve(
probs = list(
"Good Model" = example_dat$estimated_probabilities,
"Bad Model" = example_dat$bad_model,
"Random Guess" = example_dat$random_guess
),
reals = list(rtichoke::example_dat$outcome)
)
```
### Several Populations
*Why?*
In order to compare performance for different populations, like in Train / Test
split or in order to check the fairness of the algorithms.
*How?*
The user is required to provide a list with one vector of predictions for each population and a list with one vector of outcomes for each population.
<!-- ```{r echo=FALSE} -->
<!-- library(rtichoke) -->
<!-- set.seed(42) -->
<!-- predictions_and_outcomes_train <- tibble::tibble( -->
<!-- "probs" = example_dat %>% -->
<!-- dplyr::filter(type_of_set == "train") %>% -->
<!-- dplyr::pull(estimated_probabilities), -->
<!-- real = example_dat %>% dplyr::filter(type_of_set == "train") %>% -->
<!-- dplyr::pull(outcome) %>% -->
<!-- as.numeric()) -->
<!-- predictions_and_outcomes_test <- tibble::tibble( -->
<!-- "probs" = example_dat %>% -->
<!-- dplyr::filter(type_of_set == "test") %>% -->
<!-- dplyr::pull(estimated_probabilities), -->
<!-- real = example_dat %>% dplyr::filter(type_of_set == "test") %>% -->
<!-- dplyr::pull(outcome) %>% -->
<!-- as.numeric()) -->
<!-- predictions_and_outcomes_train %>% -->
<!-- dplyr::sample_n(replace = FALSE, size = 6) %>% -->
<!-- gt::gt() %>% -->
<!-- gt::tab_header( -->
<!-- title = gt::md("**Train Set**") -->
<!-- ) %>% -->
<!-- gt::fmt_number(columns = probs, -->
<!-- decimals = 2) -->
<!-- predictions_and_outcomes_test %>% -->
<!-- dplyr::sample_n(replace = FALSE, size = 6) %>% -->
<!-- gt::gt() %>% -->
<!-- gt::tab_header( -->
<!-- title = gt::md("**Test Set**") -->
<!-- )%>% -->
<!-- gt::fmt_number(columns = probs, -->
<!-- decimals = 2) -->
<!-- ``` -->
```{r eval=FALSE, include = TRUE}
create_roc_curve(
probs = list(
"Train" = example_dat %>%
dplyr::filter(type_of_set == "train") %>%
dplyr::pull(estimated_probabilities),
"Test" = example_dat %>% dplyr::filter(type_of_set == "test") %>%
dplyr::pull(estimated_probabilities)
),
reals = list(
"Train" = example_dat %>% dplyr::filter(type_of_set == "train") %>%
dplyr::pull(outcome),
"Test" = example_dat %>% dplyr::filter(type_of_set == "test") %>%
dplyr::pull(outcome)
)
)
```
## Performance Data as input
For some outputs in rtichoke you can alternatively prepare a performance data and use it as an input:
instead of `create_*_curve` use `plot_*_curve` and instead of `create_performance_table` use `render_performance_table`:
```{r eval=FALSE, include = TRUE}
one_pop_one_model_as_a_vector %>%
plot_roc_curve()
```
### Summary Report
In order to get all the supported outputs of rtichoke in one html file the user can call `create_summary_report()`.
### Getting help
If you encounter a bug please fill an issue with a minimal reproducible example, it will be easier for me to help you and it might help others in the future. Alternatively you are welcome to contact me personally: [email protected]