forked from pgullon/cvd_inequities_spain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prevalencias.R
103 lines (78 loc) · 3.94 KB
/
prevalencias.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
library(plyr)
library(tidyverse)
library(scales)
library(broom)
library(survey)
library(lubridate)
library(lme4)
library(broom.mixed)
library(mixedup)
library(glmmTMB)
library(srvyr)
rm(list=ls())
load("joined_dta.RData")
ccaas <- read_delim("ccaas.csv", delim = ";",
escape_double = FALSE, trim_ws = TRUE)
# Invertimos alcohol
dta <- dta %>%
mutate(alcohol=(alcohol-1)*-1)
prevalencias_peso_ccaa_overall <- dta %>%
as_survey_design(weights = c(factor2)) %>%
group_by(ccaa, education_3, encuesta) %>%
summarize(diabetes = survey_mean(diabetes, na.rm = T, vartype = "ci"),
hta = survey_mean(hta, na.rm = T, vartype = "ci"),
col = survey_mean(col, na.rm = T, vartype = "ci"),
obesity = survey_mean(obesity, na.rm = T, vartype = "ci"),
sobrepeso = survey_mean(sobrepeso, na.rm = T, vartype = "ci"),
smoking = survey_mean(smoking, na.rm = T, vartype = "ci"),
alcohol = survey_mean(alcohol, na.rm = T, vartype = "ci"),
sedentario = survey_mean(sedentario, na.rm = T, vartype = "ci"),
fruta_verdura = survey_mean(fruta_verdura, na.rm = T, vartype = "ci")) %>%
left_join(ccaas) %>%
mutate(sexo="Overall")
prevalencias_peso_ccaa_sexo <- dta %>%
as_survey_design(weights = c(factor2)) %>%
group_by(ccaa, education_3, encuesta, sexo) %>%
summarize(diabetes = survey_mean(diabetes, na.rm = T, vartype = "ci"),
hta = survey_mean(hta, na.rm = T, vartype = "ci"),
col = survey_mean(col, na.rm = T, vartype = "ci"),
obesity = survey_mean(obesity, na.rm = T, vartype = "ci"),
sobrepeso = survey_mean(sobrepeso, na.rm = T, vartype = "ci"),
smoking = survey_mean(smoking, na.rm = T, vartype = "ci"),
alcohol = survey_mean(alcohol, na.rm = T, vartype = "ci"),
sedentario = survey_mean(sedentario, na.rm = T, vartype = "ci"),
fruta_verdura = survey_mean(fruta_verdura, na.rm = T, vartype = "ci")) %>%
left_join(ccaas)
prevalencias_ccaa <- prevalencias_peso_ccaa_sexo %>%
mutate(sexo=as.character(sexo)) %>%
rbind(prevalencias_peso_ccaa_overall)
write.csv(prevalencias_ccaa, "prevalencias_ccaa.csv")
prevalencias_peso_spain_overall <- dta %>%
as_survey_design(weights = c(factor2)) %>%
group_by(education_3, encuesta) %>%
summarize(diabetes = survey_mean(diabetes, na.rm = T, vartype = "ci"),
hta = survey_mean(hta, na.rm = T, vartype = "ci"),
col = survey_mean(col, na.rm = T, vartype = "ci"),
obesity = survey_mean(obesity, na.rm = T, vartype = "ci"),
sobrepeso = survey_mean(sobrepeso, na.rm = T, vartype = "ci"),
smoking = survey_mean(smoking, na.rm = T, vartype = "ci"),
alcohol = survey_mean(alcohol, na.rm = T, vartype = "ci"),
sedentario = survey_mean(sedentario, na.rm = T, vartype = "ci"),
fruta_verdura = survey_mean(fruta_verdura, na.rm = T, vartype = "ci")) %>%
mutate(sexo="Overall")
prevalencias_peso_spain_sexo <- dta %>%
as_survey_design(weights = c(factor2)) %>%
group_by(sexo, education_3, encuesta) %>%
summarize(diabetes = survey_mean(diabetes, na.rm = T, vartype = "ci"),
hta = survey_mean(hta, na.rm = T, vartype = "ci"),
col = survey_mean(col, na.rm = T, vartype = "ci"),
obesity = survey_mean(obesity, na.rm = T, vartype = "ci"),
sobrepeso = survey_mean(sobrepeso, na.rm = T, vartype = "ci"),
smoking = survey_mean(smoking, na.rm = T, vartype = "ci"),
alcohol = survey_mean(alcohol, na.rm = T, vartype = "ci"),
sedentario = survey_mean(sedentario, na.rm = T, vartype = "ci"),
fruta_verdura = survey_mean(fruta_verdura, na.rm = T, vartype = "ci"))
prevalencias_spain <- prevalencias_peso_spain_sexo %>%
mutate(sexo=as.character(sexo)) %>%
rbind(prevalencias_peso_spain_overall)
write.csv(prevalencias_spain, "prevalencias_spain.csv")