-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotebook.qmd
89 lines (66 loc) · 1.91 KB
/
notebook.qmd
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
---
title: "Reproduction of figures from Diamant et al. 2024"
author: "Jackson Vanfleet-Brown"
format: html
echo: false
---
```{r message=FALSE}
library(tidyverse)
library(tidymodels)
library(targets)
tar_load(c("study_data", "combined_predictions"))
```
## Figure 4
Reproduction shown below in @fig-fig4
```{r}
#| label: fig-fig4
ggplot(study_data)+
geom_histogram(aes(x=whistle_num, fill = label),
binwidth = 10,
position=position_dodge())
```
## Figure 5
Reproduction shown below in @fig-fig5
```{r results="hide"}
#| label: fig-fig5
#| fig-cap: "Histograms of whistle features, with and without vessel."
#| fig-subcap:
#| - "Whistle length"
#| - "Whistle overlap"
#| - "Number of Clusters"
#| - "Harmony Rate"
vars_wanted <- c("whistle_length", "harmony_num", "whistle_overlap", "cluster_num")
binwidths <- c(0.05, 1, 1, 1)
make_plot <- function(x, y) {
ggplot(x) +
geom_histogram(aes(x= value, fill = label),
position = position_dodge(),
binwidth = binwidths[grep(y, vars_wanted)]
)
}
study_data %>%
pivot_longer(cols=1:9, names_to = "var") %>%
nest(data=-var) %>%
filter(var %in% vars_wanted) %>%
mutate(plot = map2(data, var, ~ make_plot(.x, .y))) %>%
pull(plot)
```
## Prediction Results
Reproduction of Figure 6 shown in @fig-fig6 below.
```{r}
#| label: fig-fig6
#| fig-cap: "Classification results"
#|
metrics_wanted <- c("accuracy", "sens")
results <- combined_predictions %>%
nest(data = -svm) %>%
mutate(cf = map(data, ~ conf_mat(.x, truth, est))) %>%
mutate(summary = map(cf, ~ summary(.x))) %>%
mutate(metrics = map(summary, ~ filter(.x, .metric %in% metrics_wanted))) %>%
pull(metrics, name = "svm") %>%
list_rbind(names_to = "svm")
ggplot(results) +
geom_bar(mapping = aes(x=svm, y=.estimate, fill = .metric),
position = position_dodge(),
stat = "identity")
```