-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path03.Report.R
executable file
·611 lines (493 loc) · 20.5 KB
/
03.Report.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
#!/usr/local/bin/Rscript
################################################################################
### Format files given as arguments and report results from simulation
##
## Created on: 2015-04-09
## Author: Kazuki Yoshida
################################################################################
### Prepare environment
################################################################################
## Configure sink()
if (sink.number() != 0) {sink()}
..scriptFileName.. <- gsub("^--file=", "", Filter(function(x) {grepl("^--file=", x)}, commandArgs()))
if (length(..scriptFileName..) == 1) {
sink(file = paste0(..scriptFileName.., ".txt"), split = TRUE)
options(width = 120)
}
## Record start time
start_time <- Sys.time()
cat("### Started ", as.character(start_time), "\n")
## Load packages
library(magrittr)
library(dplyr)
library(reshape2)
library(tidyr)
library(ggplot2)
library(grid)
library(gridExtra)
source("./function_definitions/05.BalanceCheck.R")
source("./function_definitions/07.Simulate.R")
source("./function_definitions/08.ReportingFunctions.R")
cat("###
### Load data files
################################################################################\n")
## List all .data/Result* files
resFiles <- system("ls ./data/Result*.RData", intern = TRUE)
## Stop if no file is specified
stopifnot(length(resFiles) > 0 & all(!is.na(resFiles)))
cat("### Files to be read\n")
print(resFiles)
## Load into a list
lstRes <- lapply(resFiles, function(file) {
load(file)
list(dfOut = dfOut, lstParams = lstParams, R = R, scenarioCount = scenarioCount)
})
reports <- lapply(lstRes, function(res) {
Report(scenarioCount = res$scenarioCount,
lstParams = res$lstParams,
dfOut = res$dfOut)
}) %>% do.call(rbind, .) %>% as.data.frame
cat("###
### Name scenarios
################################################################################\n")
## Original sample size
reports$N <- factor(reports$N)
## Strength of covariate-treatment association (stronger = poor covariate overlap)
reports$XT_assoc <- factor(reports$XT_assoc, levels = c(1,5),
labels = c("Good overlap", "Poor overlap"))
## Exposure prevalence
reports$pExpo <- factor(reports$pT.2, levels = c(33,45,80),
labels = c("33:33:33", "10:45:45", "10:10:80"))
## Main effects
reports$effects <- factor((reports$betaT1 != 0), levels = c(FALSE,TRUE),
labels = c("Null main effects", "Non-null main effects"))
## Effect modification
reports$em <- factor((reports$betaTX1 != 0), levels = c(FALSE,TRUE),
labels = c("Modification (-)", "Modification (+)"))
## Disease prevalence
reports$pDis <- factor(reports$beta0, levels = sort(unique(reports$beta0)),
labels = exp(sort(unique(reports$beta0))))
## Combine with N
## reports$pDis <- interaction(reports$pDis, reports$N, sep = ":")
## Specify index variables
indexVars <- c("scenario","N","XT_assoc","pExpo","effects","em","pDis")
cat("### Show scenarios\n")
reports[indexVars]
save(reports, indexVars, file = "./data/Report.RData")
cat("###
### Numerical Examination
################################################################################\n")
cat("### Check if there are missing values (corrupt scenarios)\n")
colSumNA <- colSums(is.na(reports))
colSumNA[colSumNA != 0]
cat("### Check if caliper widening ever happened\n")
reports[reports$caliperPw > 0,c("scenario","XT_assoc",paste0("pT.", c(0,1,2)))]
cat("### Magnitude of bias\n")
## Better if closer to 1 (closer to 0 on log scale)
absLogBiasM <- abs(log(reports[,PickMatchNames(names(reports), "M.biasRR")]))
absLogBiasMw <- abs(log(reports[,PickMatchNames(names(reports), "Mw.biasRR")]))
absLogBiasRatio <- absLogBiasM / absLogBiasMw
cat("### Proportion M > Mw using entire sample true value\n")
mean(absLogBiasRatio[,1:3] > 1)
cat("### Proportion M > Mw using common support true value\n")
mean(absLogBiasRatio[,4:6] > 1)
cat("### Magnitude of variance\n")
## Better if closer to 1 (closer to 0 on log scale)
trueVarM <- reports[,PickMatchNames(names(reports), "M.trueV")]
trueVarMw <- reports[,PickMatchNames(names(reports), "Mw.trueV")]
trueVarIp <- reports[,PickMatchNames(names(reports), "Ip.trueV")]
cat("### Proportion M > Mw\n")
mean((trueVarM / trueVarMw)[,1:3] > 1)
cat("### Proportion Ip > Mw\n")
mean((trueVarIp / trueVarMw)[,1:3] > 1)
cat("### Proportion M > Ip\n")
mean((trueVarM / trueVarIp)[,1:3] > 1)
cat("### Magnitude of MSE\n")
## Better if closer to 1 (closer to 0 on log scale)
mseM <- reports[,PickMatchNames(names(reports), "M.mse\\.")]
mseMw <- reports[,PickMatchNames(names(reports), "Mw.mse\\.")]
mseIp <- reports[,PickMatchNames(names(reports), "Ip.mse\\.")]
cat("### Proportion M > Mw\n")
mean((mseM / mseMw)[,1:3] > 1)
cat("### Proportion Ip > Mw\n")
mean((mseIp / mseMw)[,1:3] > 1)
cat("### Proportion M > Ip\n")
mean((mseM / mseIp)[,1:3] > 1)
cat("### False positive rate\n")
## Better if closer to 1 (closer to 0 on log scale)
dat <- Gather(reports, indexVars, "pRej")
dat <- subset(dat, effects == "Null main effects" & em == "Modification (-)")
dat %>%
group_by(method) %>%
summarize(mean = mean(value),
totalNull = n(),
antiCon05 = sum(value > 0.05),
antiCon06 = sum(value > 0.06),
antiCon07 = sum(value > 0.07))
cat("###
### Graphical Examination
################################################################################\n")
## Name graph using the date and time
pdf(file = "./figures/_ExperimentalFigures.pdf", width = 14, height = 10, family = "sans")
## Graph prototype
gg <- ggplot(mapping = aes(x = key, y = value)) +
geom_point() +
labs(y = "", x = "") +
theme_bw() + theme(legend.key = element_blank(),
axis.text.x = element_text(angle = 90))
cat("### Sample size\n")
## dat <- Gather(reports, indexVars, "\\.n$")
## gg %+% dat +
## aes(group = scenario, color = pExpo, x = method) +
## geom_line(size = 0.1) +
## facet_grid(. ~ XT_assoc) +
## labs(title = "Sample size") +
## geom_hline(yintercept = reports$U.n[1])
## dat <- Gather(reports, indexVars, "\\.nCs$")
## gg %+% dat +
## aes(group = scenario, color = pExpo, x = method) +
## geom_line(size = 0.1) +
## facet_grid(. ~ XT_assoc) +
## labs(title = "Sample size (common support)") +
## geom_hline(yintercept = reports$U.n[1])
dat <- Gather(reports, indexVars, "\\.n$|\\.nCs$")
dat$key <- factor(gsub(".*\\.", "", as.character(dat$key)), levels = c("n","nCs"),
labels = c("All", "Within common support"))
gg %+% dat +
aes(group = scenario, color = pExpo, x = method) +
geom_line(size = 0.1) +
facet_grid(XT_assoc ~ key) +
labs(title = "Sample size (All vs Within common support)") +
scale_y_continuous(limit = c(0,NA)) +
geom_hline(yintercept = unique(reports$U.n))
cat("### SMD\n")
dat <- Gather(reports, indexVars, "smd")
dat$key <- gsub("^.*\\.", "", as.character(dat$key))
dat$key <- factor(dat$key, levels = paste0("X", 1:10))
gg %+% dat +
labs(title = "SMD") +
aes(group = scenario, color = pExpo) +
geom_line() +
facet_grid(XT_assoc ~ method) +
scale_y_continuous() +
coord_cartesian(ylim = c(0, 0.5)) +
geom_hline(yintercept = 0.10, size = 0.01) +
geom_hline(yintercept = 0.00)
cat("### Prevalence of modifier\n")
dat <- Gather(reports, indexVars, "pMod$")
gg %+% dat +
aes(group = scenario, color = pExpo, x = method) +
geom_line(alpha = 0.5) +
scale_y_continuous(limit = c(0, NA)) +
facet_grid(. ~ XT_assoc) +
labs(title = "Prevalence of modifier", x = "")
cat("### Bias related\n")
dat <- Gather(reports, indexVars, "coef")
dat$value <- exp(dat$value)
dat$trueValue <- Gather(reports, indexVars, "trueRR\\.")$value
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
labs(x = "") +
## To indicate the true values
geom_point(mapping = aes(y = trueValue), shape = 4, alpha = 1/5, size = 5) +
geom_line() +
scale_y_log10(breaks = c(1/4, 1/2, 1, 2, 4)) +
coord_cartesian(ylim = c(1/4, 4)) +
facet_grid(effects + XT_assoc ~ em + contrast) +
labs(title = "RR along with with true RR", x = "")
dat <- Gather(reports, indexVars, "trueRR\\.")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
scale_y_log10(breaks = c(1/4, 1/2, 1, 2, 4)) +
coord_cartesian(ylim = c(1/4, 4)) +
facet_grid(effects + XT_assoc ~ em + contrast) +
labs(title = "True RR", x = "")
dat <- Gather(reports, indexVars, "biasRR\\.")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
scale_y_log10(breaks = c(1/4, 1/2, 1, 2, 4)) +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(1/4, 4)) +
geom_hline(yintercept = 1) +
labs(title = "Bias (RR / true RR)")
cat("### Variance\n")
dat <- Gather(reports, indexVars, "trueV")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(0, 2)) +
labs(title = "True variance", x = "")
dat <- Gather(reports, indexVars, "vars")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(0, 2)) +
labs(title = "Mean estimated variance", x = "")
datWide <-
reports[, c(PickMatchNames(names(reports), "vars"))] /
reports[, c(PickMatchNames(names(reports), "trueV"))]
datWide <- cbind(datWide, reports[, indexVars])
dat <- Gather(datWide, indexVars, "vars")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
facet_grid(effects + XT_assoc ~ em + contrast) +
geom_hline(yintercept = 1) +
labs(title = "Mean estimated variance / true variance", x = "")
cat("### MSE\n")
dat <- Gather(reports, indexVars, "mse\\.")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(0, 1.5)) +
labs(title = "MSE", x = "")
cat("### Alpha rate\n")
dat <- Gather(reports, indexVars, "pRej")
dat <- subset(dat, effects == "Null main effects" & em == "Modification (-)")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
facet_grid(XT_assoc ~ contrast) +
scale_y_continuous(breaks = seq(from = 0, to = 1, by = 0.2)) +
## coord_cartesian(ylim = c(0, 0.25)) +
geom_hline(yintercept = 0.05) +
labs(title = "Observed alpha error rate (null scenarios)", x = "")
cat("### Coverage\n")
dat <- Gather(reports, indexVars, "cvr\\.")
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = method) +
geom_line() +
facet_grid(effects + XT_assoc ~ em + contrast) +
## coord_cartesian(ylim = c(0.75, 1.00)) +
geom_hline(yintercept = 0.95) +
labs(title = "Coverage", x = "")
cat("### Minimum counts\n")
dat <- Gather(reports, indexVars, "NCases\\.")
dat$key <- gsub("minNCases\\.", "", as.character(dat$key))
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = key) +
geom_line() +
facet_grid(effects + XT_assoc ~ em + pDis) +
coord_cartesian(ylim = c(0, 25)) +
geom_hline(yintercept = 0) +
labs(title = "Minimum case counts", x = "")
dat <- Gather(reports, indexVars, "minX10\\.")
dat$key <- gsub("minX10\\.", "", as.character(dat$key))
gg %+% dat +
aes(group = scenario, color = pExpo, shape = pDis, x = key) +
geom_line() +
facet_grid(effects + XT_assoc ~ em + pDis) +
coord_cartesian(ylim = c(0, 25)) +
geom_hline(yintercept = 0) +
labs(title = "Minimum X10 counts", x = "")
dev.off()
cat("
###
### Production figures
################################################################################\n")
## http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
## Color-blind friendly palette with black.
cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")[c(4,6,7)]
gg <- ggplot(mapping = aes(x = key, y = value)) +
labs(title = NULL, y = NULL, x = NULL) +
scale_color_manual(values = cbbPalette) +
scale_linetype_manual(values = c("solid", "dashed", "dotted")) +
theme_bw() + theme(legend.key = element_blank(),
legend.key.width = unit(1, "cm"),
legend.position = "bottom",
strip.background = element_blank(),
panel.margin = unit(0.5, "lines"))
### Figures
### Average sample size
pdf(file = "./figures/Figure2.pdf", width = 5, height = 5, family = "sans")
dat <- Gather(reports, indexVars, "\\.n$")
## Average across random variability with essentially same scenarios
dat <- dat %>%
group_by(pExpo,method,key,XT_assoc) %>%
summarize(value = mean(value))
gg %+% dat +
aes(group = pExpo, linetype = pExpo, x = method) +
geom_line() +
geom_point() +
facet_grid(. ~ XT_assoc) +
geom_hline(yintercept = c(reports$U.n[1], 0), alpha = 1/5) +
theme(panel.margin = unit(0, "lines"),
legend.margin = unit(0, "lines")) +
labs(title = NULL, x = NULL, y = "Sample Size")
dev.off()
### SMD
pdf(file = "./figures/Figure3.pdf", width = 5, height = 5, family = "sans")
dat <- Gather(reports, indexVars, "smd")
dat$key <- gsub("^.*\\.", "", as.character(dat$key))
dat$key <- factor(dat$key, levels = paste0("X", 1:10))
## Restrict to 3 covariates
dat <- subset(dat, key %in% paste0("X", c(1,4,7)))
## Average across random variability with essentially same scenarios
dat <- dat %>%
group_by(pExpo,method,key,XT_assoc) %>%
summarize(value = mean(value))
gg %+% dat +
aes(group = pExpo, linetype = pExpo, x = method) +
geom_line(alpha = 2/3) +
geom_point() +
facet_grid(XT_assoc ~ key, scales = "free") +
scale_y_continuous() +
coord_cartesian(ylim = c(0, 0.5)) +
geom_hline(yintercept = 0.10, size = 0.3, alpha = 3/5) +
geom_hline(yintercept = 0.00, alpha = 3/5) +
labs(title = NULL, x = NULL, y = "Absolute Standardized Mean Difference")
dev.off()
### eFigures
### Bias
pdf(file = "./figures/eFigure2.pdf", width = 10, height = 10, family = "sans")
dat <- Gather(reports, indexVars, "biasRR\\.")
gg %+% dat +
aes(group = scenario, linetype = pExpo, shape = pDis, x = method) +
geom_line(alpha = 2/3) +
geom_point(alpha = 2/3) +
scale_y_log10(breaks = c(1/4, 1/2, 3/4, 1, 1.5, 2, 3, 4)) +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(3/4, 3)) +
geom_hline(yintercept = 1, alpha = 1/5) +
labs(title = NULL, x = NULL, y = "Bias (Estimated Risk Ratio / True Risk Ratio)")
dev.off()
### True RR
pdf(file = "./figures/eFigure3.pdf", width = 10, height = 10, family = "sans")
dat <- Gather(reports, indexVars, "trueRR\\.")
gg %+% dat +
aes(group = scenario, linetype = pExpo, x = method) +
geom_line(alpha = 2/3) +
scale_y_log10(breaks = c(1/4, 2/5, 1/2, 3/4, 1, 2, 4)) +
coord_cartesian(ylim = c(exp(-1), 1.1)) +
facet_grid(effects + XT_assoc ~ em + contrast) +
labs(title = NULL, x = NULL, y = "True Risk Ratio")
dev.off()
### True variance
pdf(file = "./figures/eFigure4.pdf", width = 10, height = 10, family = "sans")
dat <- Gather(reports, indexVars, "trueV")
gg %+% dat +
aes(group = scenario, linetype = pExpo, shape = pDis, x = method) +
geom_line() +
geom_point() +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(0, 1)) +
labs(title = NULL, x = NULL, y = "True Variance")
dev.off()
### Mean estimated variance
pdf(file = "./figures/eFigure5.pdf", width = 10, height = 10, family = "sans")
dat <- Gather(reports, indexVars, "vars")
gg %+% dat +
aes(group = scenario, linetype = pExpo, shape = pDis, x = method) +
geom_line() +
geom_point() +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(0, 1)) +
labs(title = NULL, x = NULL, y = "Estimated Variance")
dev.off()
### eFigure6.pdf is bootstrap variance figure created elsewhere
### MSE
pdf(file = "./figures/eFigure7.pdf", width = 10, height = 10, family = "sans")
dat <- Gather(reports, indexVars, "mse\\.")
gg %+% dat +
aes(group = scenario, linetype = pExpo, shape = pDis, x = method) +
geom_line() +
geom_point() +
facet_grid(effects + XT_assoc ~ em + contrast) +
coord_cartesian(ylim = c(0, 1.5)) +
labs(title = NULL, x = NULL, y = "Mean Squared Error")
dev.off()
### Type I error rate
pdf(file = "./figures/eFigure8.pdf", width = 5, height = 5, family = "sans")
dat <- Gather(reports, indexVars, "pRej")
dat <- subset(dat, effects == "Null main effects" & em == "Modification (-)")
gg %+% dat +
aes(group = scenario, linetype = pExpo, shape = pDis, x = method) +
geom_line() +
geom_point() +
facet_grid(XT_assoc ~ contrast) +
scale_y_continuous(breaks = seq(from = 0, to = 1, by = 0.2)) +
## coord_cartesian(ylim = c(0, 0.25)) +
geom_hline(yintercept = 0.05) +
labs(title = NULL, x = NULL, y = "Type I Error Rate")
dev.off()
### Coverage probability
pdf(file = "./figures/eFigure9.pdf", width = 10, height = 10, family = "sans")
dat <- Gather(reports, indexVars, "cvr\\.")
gg %+% dat +
aes(group = scenario, linetype = pExpo, shape = pDis, x = method) +
geom_line() +
geom_point() +
facet_grid(effects + XT_assoc ~ em + contrast) +
## coord_cartesian(ylim = c(0.75, 1.00)) +
geom_hline(yintercept = 0.95) +
labs(title = NULL, x = NULL, y = "Coverage Probability")
dev.off()
### eFigure10.pdf is empirical SMD figure created elsewhere
cat("
###
### Anomaly assessment
################################################################################\n")
### High variance for M
cat("### Assessment of very high variance in matching\n")
cat("### Show configuration for most extreme scenario\n")
scenarioNum <- which.max(reports$M.trueV.2v0)
reports[scenarioNum, c("pExpo","XT_assoc","effects","em","pDis")]
cat("### Extract iteration results\n")
res <- lstRes[[scenarioNum]]
cat("### Show coefficients distribution (very low coefficients)\n")
summary(res$dfOut[,PickMatchNames(names(reports), "coef")])
cat("### Show most extreme iterations\n")
res$dfOut[res$dfOut$M.coef.2v0 < min(res$dfOut$M.coef.2v0) + 1.0, ]
cat("### Iteration count of most extreme iteration\n")
as.numeric(rownames(res$dfOut[which.min(res$dfOut$M.coef.2v0),]))
### NA's in performance assessment (SMD for X10)
cat("### Check columns having NA's (This should be empty)\n")
countNa <- foreach(lst = lstRes, .combine = rbind) %do% {
colSums(is.na(lst$dfOut))
}
countNa[, colSums(countNa > 0) > 0]
### False positive scenarios
cat("### Check which scenarios are producing false positives\n")
reportsNull <- subset(reports, effects == "Null main effects" & em == "Modification (-)")
FalsePosScenarios <- function(indexVars, data, pat) {
vars <- PickMatchNames(names(data), pat)
list(alpha005 = data[rowSums(data[,vars] > 0.05) > 0, c(indexVars, vars)],
alpha006 = data[rowSums(data[,vars] > 0.06) > 0, c(indexVars, vars)],
alpha007 = data[rowSums(data[,vars] > 0.07) > 0, c(indexVars, vars)])
}
cat("### Violating scenarios for M\n")
FalsePosScenarios(indexVars, reportsNull, "M.pRej")
cat("### Violating scenarios for Mw\n")
FalsePosScenarios(indexVars, reportsNull, "Mw.pRej")
### Undercoverage scenarios
cat("### Check which scenarios are producing undercoverage\n")
UnderCiScenarios <- function(indexVars, data, pat) {
vars <- PickMatchNames(names(data), pat)
## All over coverage
list(cvr_all_gr097 = data[rowSums(data[,vars] > 0.96) > 2, c(indexVars, vars)],
cvr_all_gr096 = data[rowSums(data[,vars] > 0.96) > 2, c(indexVars, vars)],
## Any undercoverage
cvr_ls095 = data[rowSums(data[,vars] < 0.95) > 0, c(indexVars, vars)],
cvr_ls094 = data[rowSums(data[,vars] < 0.94) > 0, c(indexVars, vars)],
cvr_ls093 = data[rowSums(data[,vars] < 0.93) > 0, c(indexVars, vars)])
}
cat("### Violating scenarios for M\n")
UnderCiScenarios(indexVars, reports, "M.cvr\\.")
cat("### Violating scenarios for Mw\n")
UnderCiScenarios(indexVars, reports, "Mw.cvr\\.")
################################################################################
cat("\n### Record package versions\n")
print(sessionInfo())
## Record execution time
end_time <- Sys.time()
cat("### Started ", as.character(start_time), "\n")
cat("### Finished ", as.character(end_time), "\n")
print(end_time - start_time)
## Stop sinking to a file if active
if (sink.number() != 0) {sink()}