-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-all-true-risk-models-without-titles.R
89 lines (70 loc) · 3.1 KB
/
plot-all-true-risk-models-without-titles.R
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
#####################################
# plot-all-risk-models.R
#
# Script for plotting the various
# risk models implemented in this
# package. See more detail,
# R/plot-risks.R and R/risk-models.R
# in the expard packages
#
# The resulting plots are stored in
# the figures/ folder
#####################################
library(expard)
# the drug history used for the plots
drug_history <- c(rep(0,4), rep(1,6), rep(0, 10))
# a longer history used for effect models that take a long time
long_drug_history <- c(rep(0,4), rep(1,6), rep(0, 70))
# dimensions of the plots
width <- 6
height <- 3
# No effect model ---------------------
plot_risk(drug_history,
risk_model = risk_model_no_association(),
title = "") #"no assocation")
ggsave("figures/risk_model_no_association_no_title.pdf", width = width, height = height)
# Current use model ---------------------
plot_risk(drug_history,
risk_model = risk_model_current_use(),
title = "") #"current use")
ggsave("figures/risk_model_current_use_no_title.pdf", width = width, height = height)
# Past use model ---------------------
plot_risk(long_drug_history,
risk_model = risk_model_past(5),
title = "") #"past use (delay = 5)")
ggsave("figures/risk_model_past_use_delay5_no_title.pdf", width = width, height = height)
plot_risk(long_drug_history,
risk_model = risk_model_past(10),
title = "") #"past use (delay = 10)")
ggsave("figures/risk_model_past_use_delay10_no_title.pdf", width = width, height = height)
# Withdrawal model --------------------
rate <- c(.5,1)
sapply(rate, function(rate) {
p <- plot_risk(drug_history, risk_model = risk_model_withdrawal(rate),
title = "") #sprintf("withdrawal (rate = %g)", rate))
ggsave(sprintf("figures/risk_withdrawal_%g_no_title.pdf", rate), p, width = width, height = height)
})
# Delayed model ----------------
delay <- c(2, 5)
std <- 2
sapply(delay, function(delay) {
p <- plot_risk(drug_history, risk_model = risk_model_delayed(delay, std),
title = "") #sprintf("delayed (delay = %g, std = %g)", delay, std))
ggsave(sprintf("figures/risk_model_delayed_%g_%g_no_title.pdf", delay, std), p, width = width, height = height)
})
# Decaying model ----------------
rate <- c(.5,1)
sapply(rate, function(rate) {
p <- plot_risk(drug_history, risk_model = risk_model_decaying(rate),
title = "") #sprintf("decaying (rate = %g)", rate))
ggsave(sprintf("figures/risk_decaying_%g_no_title.pdf", rate), p, width = width, height = height)
})
# Delayed + decaying model -----
p <- plot_risk(drug_history, risk_model = risk_model_delayed_decaying(10, 2, 0.5),
title = "") #sprintf("delayed + decaying (delay = 10, std = 2, rate = 0.5)"))
ggsave(sprintf("figures/risk_delayed+decaying_no_title.pdf"), p, width = width, height = height)
# Long term model ---------------
rate <- 0.25
delay <- 50
p <- plot_risk(long_drug_history, risk_model = risk_model_long_term(rate = rate, delay = delay))
ggsave(sprintf("figures/risk_long_term_%g_%g_no_title.pdf", rate, delay), p, width = width, height = height)