Análise - Machine Learning com Suicídio

1. Carregamento da base de dados

Para este estudo utilizamos apenas o dataset referente ao ano de 2020 coletado no openDataSus Porta openDataSus

dados <- data.table::fread("data/Mortalidade_Geral_2020.csv") %>%  #importando a base
  tibble::as_tibble() #transformando em um tibble

2. Análise Exploratória dos Dados

Neste pré-processamento criamos a variável desfecho binarizada (CIRCOBITO_SUI) que informa a circunstância onde se deu a morte não natural.

source("munge/1-Selecionando.R") #selecionando variáveis de interesse
source("munge/2-Filtrando-Criando.R") #Filtrando e criando variáveis de interesse

2.1 Tabela de contingência vs Variável binária suicídio

#renomeando niveis das variáveis
source("munge/3-Renomeando.R")

#criando a tabela de contingência
dados %>% 
  select( #aqui ta selecionando as variáveis na tabela
    IDADE,
    SEXO,
    RACACOR,
    ESTCIV,
    ESC2010,
    CIRCOBITO_SUI) %>% 
  tbl_summary(by = CIRCOBITO_SUI,
              statistic = list(all_continuous() ~ "{mean} ({sd})")) %>% 
  add_p() #adiciona os p-valores dos testes estatísticos
Characteristic Outras causas, N = 129,9931 Suicídio, N = 13,1431 p-value2
IDADE 43 (22) 43 (18) <0.001
SEXO <0.001
Masculino 106,139 (82%) 10,321 (79%)
Feminino 23,844 (18%) 2,822 (21%)
Unknown 10 0
RACACOR <0.001
Branca 44,694 (35%) 6,322 (49%)
Preta 9,153 (7.2%) 719 (5.5%)
Amarela 516 (0.4%) 47 (0.4%)
Parda 72,983 (57%) 5,805 (45%)
Indígena 477 (0.4%) 115 (0.9%)
Unknown 2,170 135
ESTCIV <0.001
Solteiro 72,319 (58%) 6,766 (53%)
Casado 24,369 (19%) 3,232 (25%)
Viúvo 9,428 (7.5%) 419 (3.3%)
Separado/divorciado 6,074 (4.8%) 978 (7.6%)
União estável 6,452 (5.1%) 676 (5.3%)
Ignorado 6,887 (5.5%) 768 (6.0%)
Unknown 4,464 304
ESC2010 <0.001
Sem escolaridade 8,276 (6.8%) 527 (4.2%)
Fundamental I 29,308 (24%) 2,443 (20%)
Fundamental II 37,116 (30%) 3,035 (24%)
Ensino Médio 24,040 (20%) 2,946 (24%)
Superior incompleto 1,757 (1.4%) 428 (3.4%)
Superior completo 3,866 (3.2%) 911 (7.3%)
Ignorado 17,460 (14%) 2,152 (17%)
Unknown 8,170 701

1 Mean (SD); n (%)

2 Wilcoxon rank sum test; Pearson's Chi-squared test

2.2 Densidade em relação ao desfecho

Sexo

dados %>% 
  ggplot(aes(IDADE, fill=CIRCOBITO_SUI)) + geom_density(alpha=0.5) + facet_wrap(~SEXO) 

Raca Cor

dados %>% 
  ggplot(aes(IDADE, fill=CIRCOBITO_SUI)) + geom_density(alpha=0.5) + facet_wrap(~RACACOR)

Estado Civil

dados %>% 
  ggplot(aes(IDADE, fill=CIRCOBITO_SUI)) + geom_density(alpha=0.5) + facet_wrap(~ESTCIV)

Escolaridade

dados %>% 
  ggplot(aes(IDADE, fill=CIRCOBITO_SUI)) + geom_density(alpha=0.5) + facet_wrap(~ESC2010)

3. Machine Learning (Algoritmos de Classificação)

Desenvolvimento do modelo

m1 <- glm(CIRCOBITO_SUI ~., data = dados, family = binomial(link = "logit"))

Tabela com os coeficientes do modelo de regressão logística

tab_model(m1)
## Profiled confidence intervals may take longer time to compute. Use
##   'ci_method="wald"' for faster computation of CIs.
## Warning: Model matrix is rank deficient. Parameters TIPOBITO were not estimable.
  CIRCOBITO SUI
Predictors Odds Ratios CI p
(Intercept) 0.13 0.11 – 0.16 <0.001
CODMUNNATU 1.00 1.00 – 1.00 <0.001
IDADE 0.99 0.99 – 0.99 <0.001
SEXO [Feminino] 1.34 1.27 – 1.41 <0.001
RACACOR [Preta] 0.71 0.64 – 0.78 <0.001
RACACOR [Amarela] 0.77 0.53 – 1.09 0.154
RACACOR [Parda] 0.69 0.65 – 0.72 <0.001
RACACOR [Indígena] 2.07 1.62 – 2.63 <0.001
ESTCIV [Casado] 1.27 1.20 – 1.34 <0.001
ESTCIV [Viúvo] 0.47 0.41 – 0.54 <0.001
ESTCIV
[Separado/divorciado]
1.48 1.35 – 1.61 <0.001
ESTCIV [União estável] 1.09 0.99 – 1.19 0.081
ESTCIV [Ignorado] 1.17 1.05 – 1.30 0.006
ESC2010 [Fundamental I] 1.13 1.02 – 1.27 0.023
ESC2010 [Fundamental II] 1.05 0.94 – 1.18 0.365
ESC2010 [Ensino Médio] 1.37 1.22 – 1.53 <0.001
ESC2010 [Superior
incompleto]
2.46 2.10 – 2.88 <0.001
ESC2010 [Superior
completo]
2.30 2.01 – 2.63 <0.001
ESC2010 [Ignorado] 1.59 1.41 – 1.78 <0.001
OCUP 1.00 1.00 – 1.00 0.068
CODMUNRES 1.00 1.00 – 1.00 0.563
CODMUNOCOR 1.00 1.00 – 1.00 0.315
CIRCOBITO 0.82 0.81 – 0.83 <0.001
Observations 103792
R2 Tjur 0.032

Gráfico com a importância das variáveis de acordo com o Odds Ratio.

plot_model(m1)
## Warning: Model matrix is rank deficient. Parameters TIPOBITO were not estimable.