-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_plotPPPdistr.R
executable file
·106 lines (82 loc) · 4.17 KB
/
4_plotPPPdistr.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#-----------------------------------------#
## Computational methods for fast Bayesian hierarchical model assessment via calibrated posterior p-values.
## Sally Paganin
## last update: June 2023
## R version 4.3.0 (2023-04-21) -- "Already Tomorrow"
## nimble version 0.13.2
##-----------------------------------------#
library(ggplot2)
library(latex2exp)
##-----------------------------------------#
## Dipper example
## Distribution of PPP and naive results
tt <- readRDS("sec6_examples/dipperTT/results_nCRep_1000_nIter_10000.rds")
## naive cppp
cpppTT <- mean(tt$repPPP[1,] < tt$obsPPP[1])
dfTT <- data.frame(x = tt$repPPP[1,])
plotTT <- ggplot(dfTT, aes(x=x)) +
geom_histogram(aes(x, after_stat(density)), position="identity", alpha=0.5, color="gray20", fill="white")+
geom_density(alpha=0.4, color = "#E69F00", fill = "#E69F00", bounds = c(0,1))+
labs(title="Dipper example - T/T model \nNull distributon of ppp",x="ppp", y = "Density")+
geom_vline(aes(xintercept = tt$obsPPP[1]), col = "red") +
theme_classic() +
coord_cartesian(xlim = c(0, 1))
ggsave(plotTT, file = paste0("figures/dipperTT_pppDistribution.png"),
width = 6, height = 4, dpi = 300)
cc <- readRDS("sec6_examples/dipperCC/results_nCRep_1000_nIter_10000.rds")
## naive cppp
mean(cc$repPPP[1,] < cc$obsPPP[1])
df <- data.frame(x = cc$repPPP[1,])
plotCC <- ggplot(df, aes(x=x)) +
geom_histogram(aes(x, after_stat(density)), position="identity", alpha=0.5, color="gray20", fill="white")+
geom_density(alpha=0.4, color = "#E69F00", fill = "#E69F00", bounds = c(0,1))+
labs(title="Dipper example - C/C model \nNull distributon of ppp",x="ppp", y = "Density")+
geom_vline(aes(xintercept = cc$obsPPP[1]), col = "red") +
theme_classic() +
coord_cartesian(xlim = c(0, 1))
ggsave(plotCC, file = paste0("figures/dipperCC_pppDistribution.png"),
width = 6, height = 4, dpi = 300)
## Newcomb example
## Distribution of PPP and naive results
res <- readRDS("sec6_examples/newcomb/results_nCRep_1000_nIter_1000.rds")
## naive cppp
cpppTT <- mean(res$repPPP[2,] < res$obsPPP[2])
dfTT <- data.frame(x = res$repPPP[2,])
plotTT <- ggplot(dfTT, aes(x=x)) +
geom_histogram(aes(x, after_stat(density)), position="identity", alpha=0.5, color="gray20", fill="white")+
geom_density(alpha=0.4, color = "#E69F00", fill = "#E69F00", bounds = c(0,1))+
labs(title="Newcomb example - good mixing \nNull distributon of ppp",x="ppp", y = "Density")+
geom_vline(aes(xintercept = res$obsPPP[2]), col = "red") +
theme_classic() +
coord_cartesian(xlim = c(0, 1))
ggsave(plotTT, file = paste0("figures/newcomb_pppDistribution.png"),
width = 6, height = 4, dpi = 300)
## Distribution of PPP and naive results
res <- readRDS("sec6_examples/newcombBadMixing/results_nCRep_1000_nIter_1000.rds")
## naive cppp
cpppTT <- mean(res$repPPP[2,] <= res$obsPPP[2])
dfTT <- data.frame(x = res$repPPP[2,])
plotTT <- ggplot(dfTT, aes(x=x)) +
geom_histogram(aes(x, after_stat(density)), position="identity", alpha=0.5, color="gray20", fill="white")+
geom_density(alpha=0.4, color = "#E69F00", fill = "#E69F00", bounds = c(0,1))+
labs(title="Newcomb example - bad mixing \nNull distributon of ppp",x="ppp", y = "Density")+
geom_vline(aes(xintercept = res$obsPPP[2]), col = "red") +
theme_classic() +
coord_cartesian(xlim = c(0, 1))
ggsave(plotTT, file = paste0("figures/newcomb_badMixingpppDistribution.png"),
width = 6, height = 4, dpi = 300)
## CapRecap simulated example
## Distribution of PPP and naive results
res <- readRDS("sec6_examples/capRecapSimulated/results_nCRep_1000_nIter_1000.rds")
## naive cppp
cpppTT <- mean(res$repPPP[1,] <= res$obsPPP[1])
dfTT <- data.frame(x = res$repPPP[1,])
plotTT <- ggplot(dfTT, aes(x=x)) +
geom_histogram(aes(x, after_stat(density)), position="identity", alpha=0.5, color="gray20", fill="white")+
geom_density(alpha=0.4, color = "#E69F00", fill = "#E69F00", bounds = c(0,1))+
labs(title="Simulated example - T/T model \nNull distributon of ppp",x="ppp", y = "Density")+
geom_vline(aes(xintercept = res$obsPPP[1]), col = "red") +
theme_classic() +
coord_cartesian(xlim = c(0, 1))
ggsave(plotTT, file = paste0("figures/capRecap_pppDistribution.png"),
width = 6, height = 4, dpi = 300)