Introdução

Vamos estudar duas variáveis qualitativas da base de dados Titanic.Rdata

Carregando base de dados

load("C:\\Users\\15781634711\\Desktop\\Base_de_dados-master\\Titanic.RData")

Corrigindo encoding

Titanic$Classe = iconv(Titanic$Classe, "latin1","UTF-8")

Questão de pesquisa

A primeira classe sobreviveu mais que a segunda e a terceira? Teve algo do tipo “Mulheres e crianças primeiro”?

Variável resposta/ variável de interesse Sobrevivencia, qualitativa nominal Variável explicativa (preditor linear) Idade, sexo e classe


Análise da classe

tabela_classe = table(Titanic$Classe, Titanic$Sobreviveu)
tabela_classe
##             
##              Não sobreviveu Sobreviveu
##   Primeira              122        202
##   Segunda               167        118
##   Terceira              528        178
##   Tripulação            673        212
round(prop.table(tabela_classe,1)*100,1)
##             
##              Não sobreviveu Sobreviveu
##   Primeira             37.7       62.3
##   Segunda              58.6       41.4
##   Terceira             74.8       25.2
##   Tripulação           76.0       24.0
barplot(tabela_classe,beside = TRUE, col = c("royalblue","lightblue","skyblue","maroon"), main = "Sobrevivência por classe", legend.text = rownames(tabela_classe))

round(prop.table(tabela_classe,2)*100,1)
##             
##              Não sobreviveu Sobreviveu
##   Primeira              8.2       28.5
##   Segunda              11.2       16.6
##   Terceira             35.4       25.1
##   Tripulação           45.2       29.9
tabela_classe2 = table(Titanic$Sobreviveu,Titanic$Classe)
tabela_classe2 
##                 
##                  Primeira Segunda Terceira Tripulação
##   Não sobreviveu      122     167      528        673
##   Sobreviveu          202     118      178        212
barplot(tabela_classe2,beside = TRUE, col = c("maroon","royalblue"), main = "Sobrevivência por classe", legend.text = rownames(tabela_classe2), args.legend = list(x = "topleft"))

62% da primeira classe sobreviveu e 24% da tripulação sobreviveu, mas uma vez o proletáriado sofre, enquanto a elite, se aproveita.


Análise da idade

tabela_idade = table(Titanic$Idade, Titanic$Sobreviveu)
tabela_idade
##          
##           Não sobreviveu Sobreviveu
##   criança             52         57
##   adulto            1438        653
round(prop.table(tabela_idade,1)*100, 1)
##          
##           Não sobreviveu Sobreviveu
##   criança           47.7       52.3
##   adulto            68.8       31.2
round(prop.table(tabela_idade,2)*100, 1)
##          
##           Não sobreviveu Sobreviveu
##   criança            3.5        8.0
##   adulto            96.5       92.0

Uma a cada duas crianças sobreviveram e um a cada três adultos sobreviveu.


Análise do sexo

tabela_sexo = table(Titanic$Sexo,Titanic$Sobreviveu)
tabela_sexo
##            
##             Não sobreviveu Sobreviveu
##   Feminino             126        344
##   Masculino           1364        366
round(prop.table(tabela_sexo)*100,1)
##            
##             Não sobreviveu Sobreviveu
##   Feminino             5.7       15.6
##   Masculino           62.0       16.6
round(prop.table(tabela_sexo,1)*100,1)
##            
##             Não sobreviveu Sobreviveu
##   Feminino            26.8       73.2
##   Masculino           78.8       21.2
round(prop.table(tabela_sexo,2)*100,1)
##            
##             Não sobreviveu Sobreviveu
##   Feminino             8.5       48.5
##   Masculino           91.5       51.5

Aproximadamente 3/4 das mulheres sobreviveram enquanto aproximadamente 1/5 dos homens sobreviveram.


Uso das cotas de representantes dos partidos políticos

Carregando a library

library(electionsBR)
## Warning: package 'electionsBR' was built under R version 4.2.3
## 
## To cite electionsBR in publications, use: citation('electionsBR')
## To learn more, visit: http://electionsbr.com
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Pegando dados

banco = electionsBR::candidate_local(year = 2020, uf = "RJ")
## Processing the data...
## Done.
banco2 = electionsBR::candidate_fed(year = 2018, uf = "RJ")
## Processing the data...
## Done.
table(banco2$DS_CARGO)
## 
##       1º SUPLENTE       2º SUPLENTE DEPUTADO ESTADUAL  DEPUTADO FEDERAL 
##                17                18              2465              1154 
##        GOVERNADOR           SENADOR   VICE-GOVERNADOR 
##                14                17                14

Criando bancos de dados dos deputados

dep_fed_2018 = banco2 %>% filter(DS_CARGO=="DEPUTADO FEDERAL")

dep_est_2018 = banco2 %>% filter(DS_CARGO=="DEPUTADO ESTADUAL")

Análise dos deputados

tabela_dep_fed = table(dep_fed_2018$SG_PARTIDO, dep_fed_2018$DS_GENERO)
tabela_dep_fed
##                
##                 FEMININO MASCULINO
##   AVANTE              16        33
##   DC                  17        32
##   DEM                  7        16
##   MDB                  8        14
##   NOVO                 6        13
##   PATRIOTA            13        22
##   PC do B              3         6
##   PCB                  1         0
##   PCO                  1         1
##   PDT                 20        34
##   PHS                 21        47
##   PMB                 14        26
##   PMN                  5        15
##   PODE                15        26
##   PP                   4        10
##   PPL                 15        36
##   PPS                  4        10
##   PR                   7        22
##   PRB                 18        43
##   PROS                 3        11
##   PRP                 22        48
##   PRTB                18        38
##   PSB                  3        15
##   PSC                 18        38
##   PSD                 19        43
##   PSDB                 7        14
##   PSL                 21        48
##   PSOL                15        33
##   PSTU                 0         1
##   PT                   8        17
##   PTB                  3        11
##   PTC                  7        23
##   PV                   4        16
##   REDE                 5        10
##   SOLIDARIEDADE       10        24
round(prop.table(tabela_dep_fed,1)*100,1)
##                
##                 FEMININO MASCULINO
##   AVANTE            32.7      67.3
##   DC                34.7      65.3
##   DEM               30.4      69.6
##   MDB               36.4      63.6
##   NOVO              31.6      68.4
##   PATRIOTA          37.1      62.9
##   PC do B           33.3      66.7
##   PCB              100.0       0.0
##   PCO               50.0      50.0
##   PDT               37.0      63.0
##   PHS               30.9      69.1
##   PMB               35.0      65.0
##   PMN               25.0      75.0
##   PODE              36.6      63.4
##   PP                28.6      71.4
##   PPL               29.4      70.6
##   PPS               28.6      71.4
##   PR                24.1      75.9
##   PRB               29.5      70.5
##   PROS              21.4      78.6
##   PRP               31.4      68.6
##   PRTB              32.1      67.9
##   PSB               16.7      83.3
##   PSC               32.1      67.9
##   PSD               30.6      69.4
##   PSDB              33.3      66.7
##   PSL               30.4      69.6
##   PSOL              31.2      68.8
##   PSTU               0.0     100.0
##   PT                32.0      68.0
##   PTB               21.4      78.6
##   PTC               23.3      76.7
##   PV                20.0      80.0
##   REDE              33.3      66.7
##   SOLIDARIEDADE     29.4      70.6
barplot(tabela_dep_fed,beside = TRUE, legend.text = rownames(tabela_dep_fed))

Análise de gênero dos deputados

tabela_dep_fed2 = table(dep_fed_2018$DS_GENERO, dep_fed_2018$SG_PARTIDO)

par(cex=0.6)
barplot(tabela_dep_fed2, legend.text = rownames(tabela_dep_fed2), col = c("pink","blue"), ylim = c(0, 100))

table(dep_fed_2018$DS_SIT_TOT_TURNO)
## 
##           #NULO# ELEITO POR MÉDIA    ELEITO POR QP       NÃO ELEITO 
##               45                8               38              265 
##         SUPLENTE 
##              798
dep_fed_eleito_2018 = dep_fed_2018 %>% filter(DS_SIT_TOT_TURNO == "ELEITO POR MÉDIA"|DS_SIT_TOT_TURNO == "ELEITO POR QP")

tabela_eleitos = table(dep_fed_eleito_2018$DS_GENERO, dep_fed_eleito_2018$SG_PARTIDO)
barplot(tabela_eleitos, col = c ("pink", "blue"), legend.text = rownames(tabela_eleitos))

Análise da cor dos deputados

dep_est_eleito_2018 = dep_est_2018 %>% filter(DS_SIT_TOT_TURNO == "ELEITO POR MÉDIA"| DS_SIT_TOT_TURNO == "ELEITO POR QP")

tabela_eleitos2 = table(dep_est_eleito_2018$DS_COR_RACA, dep_est_eleito_2018$SG_PARTIDO)
barplot(tabela_eleitos2, col = c("royalblue","lightblue","blue"), legend.text = rownames(tabela_eleitos2))

Análise simultanea de cor e genero

dep_fed_eleito_2018 %>% select(DS_COR_RACA, DS_GENERO)%>%table()%>%barplot(beside=TRUE)

Senadores

senador = banco2 %>% filter(DS_CARGO == "SENADOR")

senador$DS_GENERO
##  [1] "FEMININO"  "MASCULINO" "MASCULINO" "MASCULINO" "FEMININO"  "FEMININO" 
##  [7] "MASCULINO" "MASCULINO" "FEMININO"  "MASCULINO" "MASCULINO" "MASCULINO"
## [13] "MASCULINO" "MASCULINO" "MASCULINO" "MASCULINO" "MASCULINO"

Governadores

governadores = banco2 %>% filter(DS_CARGO== "GOVERNADOR")