Diff of /overview/all-models.R [000000] .. [0375db]

Switch to unified view

a b/overview/all-models.R
1
models.include <-
2
  c(
3
    'age', 'cox', 'cox disc', 'cox imp', 'cox imp disc', 'rfsrc', 'rfsrc imp',
4
    'rf-logrank', 'cox-logrank disc', 'cox-elnet disc'
5
  )
6
7
source('../lib/handy.R')
8
requirePlus('ggplot2', 'cowplot')
9
10
models.performance.all <- readTablePlus('../../output/models-performance-manual.tsv')
11
12
models.performance.all$x.labels <-
13
  paste0(
14
    models.performance.all$model,
15
    ifelse(models.performance.all$imputation, ' imp', ''),
16
    ifelse(models.performance.all$discretised, ' disc', '')
17
  )
18
19
# Currently different scripts quote either the area under the curve or a pre
20
# one-minused the area under the curve...so standardise that
21
big.calibration.scores <- models.performance.all$calibration.score > 0.5
22
models.performance.all[big.calibration.scores, c('calibration.score', 'calibration.score.lower', 'calibration.score.upper')] <-
23
  1 - models.performance.all[big.calibration.scores, c('calibration.score', 'calibration.score.lower', 'calibration.score.upper')]
24
25
models.performance <- data.frame()
26
for(model in models.include) {
27
  models.performance <-
28
    rbind(
29
      models.performance,
30
      models.performance.all[models.performance.all$x.labels == model, ]
31
    )
32
}
33
# Turn this into a factor with defined levels so ggplot respects the order above
34
models.performance$x.labels <-
35
  factor(models.performance$x.labels, levels = models.include)
36
37
plot.c.index <-
38
  ggplot(models.performance, aes(x = x.labels, y = c.index)) +
39
  geom_bar(stat='identity', aes(fill = model)) +
40
  geom_errorbar(
41
    aes(ymin = c.index.lower, ymax = c.index.upper), width = 0.1
42
  ) +
43
  coord_cartesian(
44
    ylim = c(0.75, 0.81)
45
  ) +
46
  theme(legend.position = "none")
47
  
48
plot.calibration <-
49
  ggplot(models.performance, aes(x = x.labels, y = 1 - calibration.score)) +
50
  geom_bar(stat='identity', aes(fill = model)) +
51
  geom_errorbar(
52
    aes(
53
      ymin = 1 - calibration.score.lower, ymax = 1 - calibration.score.upper
54
    ),
55
    width = 0.1
56
  ) +
57
  coord_cartesian(
58
    ylim = c(0.8, 1.0)
59
  ) +
60
  theme(legend.position = "none")
61
62
plot_grid(
63
  plot.c.index, plot.calibration,
64
  labels = c("A", "B"),
65
  align = "v", ncol = 1
66
)
67
68
ggsave(
69
  '../../output/all-models-performance.pdf',
70
  width = 16,
71
  height = 10,
72
  units = 'cm',
73
  useDingbats = FALSE
74
)