General updates
[covid19.git] / euromomo / Output_txt_v42.R
1 ### ;-separated txt files ###
2
3 if (IArest) {
4 results4 <- read.table(file=paste0(outdir,"/",country,"_output_v4_IArestricted.txt"),
5 header = TRUE, sep =";", dec=".")
6 } else {
7 results4 <- read.table(file=paste0(outdir,"/",country,"_output_v4.txt"),
8 header = TRUE, sep =";", dec=".")
9 }
10
11 csvout <- function(x, s) {
12 y <- do.call("rbind", lapply(sort(unique(x[,s])), function(i) {
13 cbind(unique(x[,"agegrp"]), min(x[(x[,s]==i),"yw"]), max(x[(x[,s]==i),"yw"]),
14 round(tail(
15 x[(x[,s]==i),
16 c(paste0("cEdIA_",s), paste0("cEdIA_",s,"_95L"), paste0("cEdIA_",s,"_95U"),
17 paste0("cEdET_",s), paste0("cEdET_",s,"_95L"), paste0("cEdET_",s,"_95U"),
18 paste0("cexcess_",s), paste0("cuexcess_",s), "N")],
19 n=1)))
20 }))
21 colnames(y) <- c("AgeGroup", "Start", "End", "cIA", "cIA_95L", "cIA_95U",
22 "cET", "cET_95L", "cET_95U", "cexcess", "cuexcess", "N")
23 return(y)
24 }
25
26 results4$yw <- sprintf("%04iw%02i",results4$year, results4$week)
27
28 for (s in c("summer","winter","year")) {
29 out <- do.call("rbind", lapply(0:4, function(a) {
30 csvout(results4[(!is.na(results4[,s])) & (results4$agegrp==a),], s)
31 }))
32 out$AgeGroup <- factor(out$AgeGroup, levels = c(0,1,2,3,4),
33 labels = c("0-4 years","5-14 years","15-64 years","Aged 65","Total"))
34 write.table(out[,c("AgeGroup", "Start", "End", "cIA", "cIA_95L", "cIA_95U",
35 "cET", "cET_95L", "cET_95U", "cexcess", "cuexcess")],
36 file = paste0(outdir, "/", s, "_deaths_v4_IA", ifelse(IArest, "restricted", ""), ".txt" ),
37 row.names = FALSE, quote = FALSE, sep =";", dec=".", na="")
38 if (population) {
39 out[,c("cIA", "cIA_95L", "cIA_95U", "cET", "cET_95L", "cET_95U", "cexcess", "cuexcess")] <-
40 round(100000 * out[,c("cIA", "cIA_95L", "cIA_95U", "cET", "cET_95L", "cET_95U", "cexcess", "cuexcess")] / out[,"N"], 2)
41 colnames(out) <- c("AgeGroup", "Start", "End", "cmrIA", "cmrIA_95L", "cmrIA_95U", "cmrET", "cmrET_95L", "cmrET_95U", "cexcess", "cuexcess", "N")
42 write.table(out[,c("AgeGroup", "Start", "End", "cmrIA", "cmrIA_95L", "cmrIA_95U",
43 "cmrET", "cmrET_95L", "cmrET_95U", "cexcess", "cuexcess")],
44 file=paste0(outdir,"/",s,"_mr_v4_IA", ifelse(IArest, "restricted", ""), ".txt"),
45 row.names = FALSE, quote = FALSE, sep =";", dec=".")
46 }
47 }
48
49 rm(out, s, csvout, results4)