-
Notifications
You must be signed in to change notification settings - Fork 0
/
relacion_muertes.qmd
149 lines (118 loc) · 2.76 KB
/
relacion_muertes.qmd
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
---
title: "Relación con muertes"
format: html
editor_options:
chunk_output_type: console
---
# Importar datos
```{r}
library(tidyverse)
```
```{r}
# Ruta al directorio donde se encuentran los archivos
path_dir <- "01_data/raw/Data Request MS242_02142023/"
# Leer los archivos .csv que contienen "DTHRED" en su nombre
death_df <- purrr::map_df(
.x = list.files(
path = path_dir,
pattern = "DTHRED.*\\.csv$",
full.names = TRUE # Esto asegura que se devuelva la ruta completa al archivo
),
.f = readr::read_csv
)
gbmt_fit_final <- readRDS("01_data/processed/gbmt_fit_final.rds")
```
```{r}
write_csv(death_df, file = "01_data/processed/death_df.csv")
```
```{r}
deaths_by_year <- death_df %>%
group_by(ISO2, SALID1, YEAR) %>%
summarise(
deaths = sum(DTHRED3DEATHS, na.rm = TRUE)
) %>%
ungroup()
deaths <- deaths_by_year %>%
group_by(ISO2, SALID1) %>%
summarise(
deaths = sum(deaths, na.rm = TRUE)
) %>%
ungroup()
```
```{r}
gbmt_log_3 <- gbmt_fit_final %>%
filter(scale_name == "logarithmic", ng == 3) %>%
slice(1)
gbmt_log_3 <- gbmt_log_3$gbmt_fit_total[[1]]
gbmt_log_4 <- gbmt_fit_final %>%
filter(scale_name == "logarithmic", ng == 4) %>%
slice(1)
gbmt_log_4 <- gbmt_log_4$gbmt_fit_total[[1]]
gbmt_log <- gbmt_log_3 %>%
bind_rows(gbmt_log_4,
.id = "Clusters") %>%
mutate(Clusters = case_match(Clusters,
"1" ~ 3,
"2" ~ 4))
```
```{r}
gbmt_log_final <- gbmt_log %>%
left_join(deaths)
```
```{r}
gbmt_log2 <- gbmt_log %>%
group_by(Clusters, pubsalid1, SALID1, group) %>%
summarise(
across(
c(population_imp_norm:bectuareal1ux_imp),
~ mean(.x, na.rm = TRUE)
)
) %>%
ungroup()
gbmt_log_final <- gbmt_log2 %>%
left_join(deaths)
gbmt_log_final2 <- gbmt_log_final %>%
mutate(
deaths_pob = deaths*100000/population_imp
)
```
```{r}
gbmt_log_final2 %>%
group_by(
Clusters
) %>%
summarise(
broom::tidy(
kruskal.test(deaths_pob ~ group)
)
)
```
```{r}
library(ggstatsplot)
grouped_ggbetweenstats(
data = gbmt_log_final2,
x = group,
y = deaths_pob,
grouping.var = Clusters,
# ggsignif.args = list(textsize = 4, tip_length = 0.01),
# p.adjust.method = "bonferroni",
# palette = "default_jama",
package = "ggsci"
# plotgrid.args = list(nrow = 1),
# annotation.args = list(title = "Differences in movie length by mpaa ratings for different genres")
)
```
```{r}
ggbetweenstats(
data = gbmt_log_final2 %>% filter(Clusters == 3),
x = group,
y = deaths_pob
)
```
```{r}
ggbetweenstats(
data = gbmt_log_final2 %>% filter(Clusters == 4),
x = group,
y = deaths_pob
)
```