-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path09.tables.R
82 lines (66 loc) · 2.79 KB
/
09.tables.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
################################################################################
# Updated version of the R code for the analysis in:
#
# "Scortichini M, Schneider Dos Santos R, De' Donato F, De Sario M,
# Michelozzi P, Davoli M, Masselot P, Sera F, Gasparrini A.
# Excess mortality during the COVID-19 outbreak in Italy: a two-stage
# interrupted time-series analysis.
# International Journal of Epidemiology. 2020. DOI: 10.1093/ije/dyaa169."
# http://www.ag-myresearch.com/2020_scortichini_ije.html
#
# Update: 21 October 2020
# * an updated version of this code, compatible with future versions of the
# software, is available at:
# https://github.com/gasparrini/ItalyCOVIDdeath
################################################################################
################################################################################
# TABLES
################################################################################
################################################################################
# TABLE 1: DESCRIPTIVE BY REGION
# CREATE THE MAIN TABLE
datatab1 <- datafull %>%
group_by(regcode, regname) %>%
summarize(prov=length(unique(provcode)),
munic=length(unique(municcode)),
cov=length(unique(municcode[munictype==1]))/munic*100,
tot=sum(tot, na.rm=T)) %>%
ungroup() %>%
dplyr::select(-regcode)
# ADD AREA
datatab1 <- cbind(datatab1[,1], Area=areareg, datatab1[,-1])
# ADD THE TOTAL FOR COUNTRY
datatab1[nrow(datatab1)+1,] <- data.frame(regname="Italy", "",
prov=sum(datatab1$prov), munic=sum(datatab1$munic),
cov=sum(datatab1$munic*datatab1$cov)/sum(datatab1$munic),
tot=sum(datatab1$tot))
# FORMAT AND NAMES
for(i in c(3,4,6)) datatab1[,i] <- formatC(datatab1[,i,drop=T], format="f",
digits=0, big.mark=",")
datatab1[-nrow(datatab1),1] <- labreg
datatab1[,5] <- paste0(formatC(datatab1[,5,drop=T], format="f", digits=1), "%")
names(datatab1) <- c("Region", "Area", "Provinces", "Municipalities", "Coverage",
"Deaths")
# SAVE
write.csv(datatab1, file="tables/tab1.csv", row.names=F)
################################################################################
# TABLE 2: EXCESS BY REGION
tab2list <- lapply(sexlab, function(x) {
# COMPUTE EXCESS AND TOTAL
exc <- excreg[,1,x,1,]
tot <- totreg[,1,x,1]
# ADD TOTAL FOR COUNTRY
exc <- rbind(exc, round(excitaly[1,x,1,]))
tot <- c(tot, totitaly[1,x,1])
rownames(exc)[nrow(exc)] <- "Italy"
# FORMAT
tot <- formatC(tot, format="f", digits=0, big.mark=",")
exc <- formatC(exc, format="f", digits=0, big.mark=",", zero.print="0")
# TABLE
tab <- cbind(tot, paste0(exc[,1]," (",exc[,2]," to ", exc[,3],")"))
dimnames(tab) <- list(rownames(exc), paste(c("Death", "Excess"),x))
tab
})
datatab2 <- do.call(cbind, tab2list)
# SAVE
write.csv(datatab2, file="tables/tab2.csv", row.names=T)