-
Notifications
You must be signed in to change notification settings - Fork 0
/
posterior_prediction_plots.R
83 lines (70 loc) · 2.34 KB
/
posterior_prediction_plots.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
# define functions used below
require(bayesplot)
require(brms)
require(here)
require(ggplot2)
require(ggpubr)
# general code that finds and loads all candidate model fits
source(here("code/lib/load_models.R"))
# to make sure we always get the same pp_check
set.seed(123456)
bh <- pp_check(focal_models[["vero"]][["beverton_holt"]], discrete=TRUE, type="ecdf_overlay") +
labs(x="Number of seeds", y="Cumulative distribution")
rick <- pp_check(focal_models[["vero"]][["ricker"]], discrete=TRUE, type="ecdf_overlay") +
labs(x="Number of seeds", y="Cumulative distribution")
null <- pp_check(focal_models[["vero"]][["interaction_free"]], discrete=TRUE, type="ecdf_overlay") +
labs(x="Number of seeds", y="Cumulative distribution")
# output filename
filename <- paste0(
"figures/posterior_predictive_checks_goro.pdf"
)
together <- bayesplot::bayesplot_grid(
null,
rick,
bh,
grid_args=list(ncol=3),
legends=FALSE,
subtitles=c("Null","Ricker","Beverton-Holt")
)
together <- annotate_figure(
together,
top = text_grob(
"Goodenia rosea",
face = "italic",
size = 15
),
# bottom = text_grob("Value", size = 15),
# left = text_grob("Parameter", size = 15, rot = 90),
fig.lab.pos = "top.right"
)
ggsave(filename = here::here(filename), plot=together, height=3)
bh <- pp_check(focal_models[["trcy"]][["beverton_holt"]], discrete=TRUE, type="ecdf_overlay") +
labs(x="Number of seeds", y="Cumulative distribution")
rick <- pp_check(focal_models[["trcy"]][["ricker"]], discrete=TRUE, type="ecdf_overlay") +
labs(x="Number of seeds", y="Cumulative distribution")
null <- pp_check(focal_models[["trcy"]][["interaction_free"]], discrete=TRUE, type="ecdf_overlay") +
labs(x="Number of seeds", y="Cumulative distribution")
# output filename
filename <- paste0(
"figures/posterior_predictive_checks_trcy.pdf"
)
together <- bayesplot::bayesplot_grid(
null,
rick,
bh,
grid_args=list(ncol=3),
legends=FALSE,
subtitles=c("Null","Ricker","Beverton-Holt")
)
together <- annotate_figure(
together,
top = text_grob(
"Trachymene cyanopetala",
face = "italic",
size = 15
),
# bottom = text_grob("Value", size = 15),
# left = text_grob("Parameter", size = 15, rot = 90),
fig.lab.pos = "top.right"
)
ggsave(filename = here::here(filename), plot=together, height=3)