-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttachment_B2.Rmd
140 lines (114 loc) · 3.5 KB
/
Attachment_B2.Rmd
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
---
title: "Attachment B"
output:
pdf_document: default
html_document: default
---
## Attachment B
Statistical analysis about tumours counting data comparasion of 12 months before COVID and 12 months after, in Modena province.
```{r setup, include=FALSE}
rm(list = ls()) # delete previous data in memory
knitr::opts_chunk$set(echo = TRUE)
library(tidyquery)
library(ggplot2)
library(MASS)
library(dplyr)
# Function for creating dummy variables
make.dummy=function(n, freq=12, start=1){
dv=matrix(0,nrow=(n+start-1), ncol=freq)
for (i in 1:freq)
dv[,i][seq(i,n+start-1,freq)] = 1
return(dv[start:(n+start-1),])
}
```
### Import of the datasets
```{r}
df_pre <- read.csv("df_pre_17.csv")
df_post <- read.csv("df_post_17.csv")
```
#### horizontal monthly dataframe
```{r}
df_pre = query(
" SELECT *
FROM df_pre
ORDER BY Year, Month;"
)
df_pre_m = query(
" SELECT Month,Year, COUNT(*)
FROM df_pre
GROUP BY Year,Month;"
)
df_post = query(
" SELECT *
FROM df_post
ORDER BY Year, Month;"
)
df_post_m = query(
" SELECT Month,Year, COUNT(*)
FROM df_post
GROUP BY Year,Month;"
)
df_h = as.data.frame(cbind(df_pre_m[,3],df_post_m[,3]))
colnames(df_h) = c("before","after") # columns names
```
#### from horizontal to vertical monthly dataframe
```{r}
#### Vertical Dataframe
df_v = as.data.frame(matrix(data=c(df_h[,1],df_h[,2],rep(0,17),rep(1,17)),
nrow = 34,ncol = 2, byrow =F))
colnames(df_v) =c("count","covid")
df_v$covid = as.factor(df_v$covid)
```
```{r}
(1-(sum(df_v$count[df_v$covid==1])/sum(df_v$count[df_v$covid==0])))*100
```
#### horizontal monthly dataframe
```{r}
df_pre <- read.csv("df_pre_17.csv")
df_post <- read.csv("df_post_17.csv")
# df_pre2= df_pre %>% group_by(SESSO)
df_pre_sex<-df_pre %>%
count(SESSO)
df_post_sex<-df_post %>%
count(SESSO)
df_pre_age<-df_pre %>%
count(AgeCod)
df_post_age<-df_post %>%
count(AgeCod)
df_pre_hist<-df_pre %>%
count(ISTOLOGIA)
df_post_hist<-df_post %>%
count(ISTOLOGIA)
```
Dati tabella paper - cali percentuali
```{r}
# totale
(dim(df_pre)[1] - dim(df_post)[1])/dim(df_pre)[1]
# sesso
(df_pre_sex[1,2] - df_post_sex[1,2])/df_pre_sex[1,2] # femmine
(df_pre_sex[2,2] - df_post_sex[2,2])/df_pre_sex[2,2] # maschi
# agecod
(df_pre_age[1,2] - df_post_age[1,2])/df_pre_age[1,2] # 1
(df_pre_age[2,2] - df_post_age[2,2])/df_pre_age[2,2] # 2
(df_pre_age[3,2] - df_post_age[3,2])/df_pre_age[3,2] # 3
(df_pre_age[4,2] - df_post_age[4,2])/df_pre_age[4,2] # 4
(df_pre_age[5,2] - df_post_age[5,2])/df_pre_age[5,2] # 5
# istologia
(df_pre_hist[1,2] - df_post_hist[1,2])/df_pre_hist[1,2] # 1
(df_pre_hist[2,2] - df_post_hist[2,2])/df_pre_hist[2,2] # 2
(df_pre_hist[3,2] - df_post_hist[3,2])/df_pre_hist[3,2] # 3
(df_pre_hist[4,2] - df_post_hist[4,2])/df_pre_hist[4,2] # 4
```
```{r}
1-(df_pre_sex[1,2]/(df_pre_sex[1,2]+df_post_sex[1,2]))
1-(df_pre_sex[2,2]/(df_pre_sex[2,2]+df_post_sex[2,2]))
1-(df_pre_age[1,2]/(df_pre_age[1,2]+df_post_age[1,2]))
1-(df_pre_age[2,2]/(df_pre_age[2,2]+df_post_age[2,2]))
1-(df_pre_age[3,2]/(df_pre_age[3,2]+df_post_age[3,2]))
1-(df_pre_age[4,2]/(df_pre_age[4,2]+df_post_age[4,2]))
1-(df_pre_age[5,2]/(df_pre_age[5,2]+df_post_age[5,2]))
1-(df_pre_hist[1,2]/(df_pre_hist[1,2] + df_post_hist[1,2] ))
1-(df_pre_hist[2,2]/(df_pre_hist[2,2] + df_post_hist[2,2] ))
1-(df_pre_hist[3,2]/(df_pre_hist[3,2] + df_post_hist[3,2] ))
1-(df_pre_hist[4,2]/(df_pre_hist[4,2] + df_post_hist[4,2] ))
```