Nesta primeira etapa, organizamos o ambiente de trabalho e carregamos os pacotes necessários. Esses pacotes permitem baixar os dados oficiais do Sistema de Informação sobre Mortalidade (SIM), manipular tabelas e executar tarefas em paralelo para acelerar o processamento.
Nesta seção, carregamos as bibliotecas necessárias para o projeto
Para tornar o processo mais eficiente, utilizamos processamento
paralelo.
Definimos uma função que baixa os dados do SIM-DO para cada unidade da
federação entre 2018 e 2020. O processo funciona normalmente apenas com
uso do “fetch_datasus”, mas o processo é extremamente lento para
multiplos anos e estados
# Utilizar múltiplos cores
plan(multisession)
ufs <- c("AC","AL","AP","AM","BA","CE","DF","ES","GO",
"MA","MT","MS","MG","PA","PB","PR","PE","PI",
"RJ","RN","RO","RR","RS","SC","SE","SP","TO")
get_uf <- function(uf,ano) {
tryCatch({
fetch_datasus(
year_start = 2018,
year_end = 2020,
uf = uf, # Sem essa função, basta chamar o fetch_datasus e substituir "uf" por "all"
information_system = "SIM-DO"
)
}, error = function(e) NULL)
}
dados <- future_lapply(ufs, get_uf)
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
## ℹ Your local Internet connection seems to be ok.
## ℹ DataSUS FTP server seems to be up and reachable.
## ℹ Starting download...
df <- do.call(dplyr::bind_rows, dados)
dim(df)
## [1] 4223344 88
O banco de dados contém cerca de 88 variáveis. Para a análise, selecionamos apenas aquelas relevantes, relacionadas a características demográficas, condições do óbito e códigos CID-10.
cols <- c(
"CIRCOBITO", "DTOBITO", "DTNASC", "SEXO", "RACACOR", "ESTCIV",
"ESC", "OCUP", "CODMUNRES", "LOCOCOR", "ASSISTMED",
"CAUSABAS", "CAUSABAS_O"
)
Aplicamos em seguida a função process_sim(), que
padroniza nomes, categorias e codificações específicas do nosso conjunto
de dados (SIM - Sistema de Informação sobre Mortalidade), tornando o
conjunto de dados mais fácil de interpretar.
# filtrar apenas colunas existentes
df_filtrado <- df[, intersect(cols, names(df)), drop = FALSE]
df_p <- process_sim(df_filtrado)
Para identificar os óbitos por suicídio, seguimos a metodologia
recomendada por Lovisi et al. (2009).
O critério utiliza os códigos CID-10 entre X60 e X84,
que correspondem a lesões autoprovocadas intencionalmente. Isso é
necessário pois a coluna “CIRCOBITO” não é 100% confiável e atribui
outras classificações para casos em que seria considerado suicídio.
Criamos então a lista de códigos e filtramos a base:
#Criação da lista para filtragem
filter_list <- paste0("X", 600:849)
df_filtrado <- df_p %>%
dplyr::filter(
CAUSABAS %in% filter_list | CAUSABAS_O %in% filter_list
)
dplyr::glimpse(df_filtrado)
## Rows: 40,185
## Columns: 21
## $ CIRCOBITO <chr> "Suicídio", "Suicídio", "Suicídio", "Suicídio", "Suicídio…
## $ DTOBITO <chr> "2018-11-06", "2018-01-02", "2018-01-15", "2018-03-17", "…
## $ DTNASC <chr> "1994-02-13", "1997-06-17", "1990-01-14", "1982-01-07", "…
## $ SEXO <chr> "Masculino", "Masculino", "Masculino", "Masculino", "Femi…
## $ RACACOR <chr> "Indígena", "Parda", "Parda", "Parda", "Parda", "Indígena…
## $ ESTCIV <chr> "Solteiro", "União consensual", "União consensual", "Uniã…
## $ ESC <chr> "Nenhuma", "8 a 11 anos", "4 a 7 anos", NA, "12 anos ou m…
## $ CODMUNRES <chr> "120034", "120030", "120035", "120035", "120035", "120035…
## $ LOCOCOR <chr> "Via pública", "Domicílio", "Domicílio", "Domicílio", "Do…
## $ ASSISTMED <chr> "Não", NA, NA, NA, "Não", NA, NA, NA, "Não", NA, "Não", N…
## $ CAUSABAS <chr> "X700", "X709", "X700", "X700", "X700", "X720", "X700", "…
## $ CAUSABAS_O <chr> "X700", "X70", "X700", "X700", "X700", "X720", "X700", "X…
## $ OCUP <chr> "Trabalhador volante da agricultura", NA, NA, "Trabalhado…
## $ munResStatus <chr> "ATIVO", "ATIVO", "ATIVO", "ATIVO", "ATIVO", "ATIVO", "AT…
## $ munResTipo <chr> "MUNIC", "MUNIC", "MUNIC", "MUNIC", "MUNIC", "MUNIC", "MU…
## $ munResNome <chr> "Manoel Urbano", "Feijó", "Marechal Thaumaturgo", "Marech…
## $ munResUf <chr> "Acre", "Acre", "Acre", "Acre", "Acre", "Acre", "Acre", "…
## $ munResLat <chr> "-8.83632", "-8.16025", "-8.95359", "-8.95359", "-8.95359…
## $ munResLon <chr> "-69.25994", "-70.35398", "-72.79027", "-72.79027", "-72.…
## $ munResAlt <chr> "162", "160", "215", "215", "215", "215", "215", "187", "…
## $ munResArea <chr> "10633.137", "27975.439", "8191.693", "8191.693", "8191.6…
library(DT)
datatable(
head(df_filtrado, 40),
options = list(
pageLength = 10,
autoWidth = TRUE
),
rownames = FALSE,
filter = "top",
caption = "Amostra interativa das primeiras linhas do dataset filtrado"
)