No Titanic é válida a tese “mulheres e crianças primeiro” Há uma desigualdade social da sobrevivência
Variável-chave “sobrevivência” Variável de interesse, Variável resposta, Desfecho.
Variáveis explicativas: Sexo, idade e classe do Titanic
load("C:/Users/sandr/Desktop/Base_de_dados-master/df_pokemon.RData")
load("C:/Users/sandr/Desktop/Base_de_dados-master/Titanic.RData")
summary(df)
## id pokemon species_id height
## Min. : 1.0 Length:718 Min. : 1.0 Min. : 1.00
## 1st Qu.:180.2 Class :character 1st Qu.:180.2 1st Qu.: 6.00
## Median :359.5 Mode :character Median :359.5 Median : 10.00
## Mean :359.5 Mean :359.5 Mean : 11.41
## 3rd Qu.:538.8 3rd Qu.:538.8 3rd Qu.: 14.00
## Max. :718.0 Max. :718.0 Max. :145.00
## weight base_experience type_1 type_2
## Min. : 1.0 Min. : 36.00 Length:718 Length:718
## 1st Qu.: 95.0 1st Qu.: 65.25 Class :character Class :character
## Median : 280.0 Median :147.00 Mode :character Mode :character
## Mean : 568.2 Mean :141.55
## 3rd Qu.: 609.5 3rd Qu.:177.00
## Max. :9500.0 Max. :608.00
## attack defense hp special_attack
## Min. : 5.00 Min. : 5.00 Min. : 1.00 Min. : 10.00
## 1st Qu.: 53.00 1st Qu.: 50.00 1st Qu.: 50.00 1st Qu.: 45.00
## Median : 73.00 Median : 65.00 Median : 65.00 Median : 65.00
## Mean : 74.85 Mean : 70.67 Mean : 68.37 Mean : 68.47
## 3rd Qu.: 95.00 3rd Qu.: 85.00 3rd Qu.: 80.00 3rd Qu.: 90.00
## Max. :165.00 Max. :230.00 Max. :255.00 Max. :154.00
## special_defense speed color_1 color_2
## Min. : 20.00 Min. : 5.00 Length:718 Length:718
## 1st Qu.: 50.00 1st Qu.: 45.00 Class :character Class :character
## Median : 65.00 Median : 65.00 Mode :character Mode :character
## Mean : 69.09 Mean : 65.72
## 3rd Qu.: 85.00 3rd Qu.: 85.00
## Max. :230.00 Max. :160.00
## color_f egg_group_1 egg_group_2 url_image
## Length:718 Length:718 Length:718 Length:718
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## x y
## Min. :-49.152 Min. :-45.793
## 1st Qu.:-17.695 1st Qu.:-17.293
## Median : 0.705 Median : -0.628
## Mean : 0.000 Mean : 0.000
## 3rd Qu.: 15.905 3rd Qu.: 18.155
## Max. : 53.142 Max. : 46.593
str(Titanic)
## 'data.frame': 2200 obs. of 4 variables:
## $ Classe : Factor w/ 4 levels "Tripulação","Primeira",..: 2 2 2 2 2 2 2 2 2 2 ...
## $ Idade : Factor w/ 2 levels "criança","adulto": 2 2 2 2 2 2 2 2 2 2 ...
## $ Sexo : Factor w/ 2 levels "Feminino","Masculino": 2 2 2 2 2 2 2 2 2 2 ...
## $ Sobreviveu: Factor w/ 2 levels "Não sobreviveu",..: 2 2 2 2 2 2 2 2 2 2 ...
pie(table(Titanic$Sobreviveu))
tabela_sexo <- table(Titanic$Sexo,Titanic$Sobreviveu)
tabela_idade <- table(Titanic$Idade,Titanic$Sobreviveu)
tabela_sexo
##
## Não sobreviveu Sobreviveu
## Feminino 126 344
## Masculino 1364 366
tabela_idade
##
## Não sobreviveu Sobreviveu
## criança 52 57
## adulto 1438 653
prop.table(tabela_sexo,1)
##
## Não sobreviveu Sobreviveu
## Feminino 0.2680851 0.7319149
## Masculino 0.7884393 0.2115607
prop.table(tabela_sexo,2)
##
## Não sobreviveu Sobreviveu
## Feminino 0.08456376 0.48450704
## Masculino 0.91543624 0.51549296
prop.table(tabela_idade,1)*100
##
## Não sobreviveu Sobreviveu
## criança 47.70642 52.29358
## adulto 68.77092 31.22908
prop.table(tabela_idade,2)*100
##
## Não sobreviveu Sobreviveu
## criança 3.489933 8.028169
## adulto 96.510067 91.971831
barplot(tabela_sexo)
barplot(tabela_sexo, main = "Gráfico 1 - Sobrevivência por sexo", col = c("yellow","royalblue"))
?barplot
## starting httpd help server ... done
library(RColorBrewer)
brewer.pal(5,"Blues")
## [1] "#EFF3FF" "#BDD7E7" "#6BAED6" "#3182BD" "#08519C"
display.brewer.all()
COR <- brewer.pal(2,"Dark2")
## Warning in brewer.pal(2, "Dark2"): minimal value for n is 3, returning requested palette with 3 different levels
barplot(tabela_sexo, main = "Gráfico 1 - Sobrevivência por sexo", col = COR, horiz = FALSE,beside = TRUE)
COR <- c("#1B9E77", "#D95F02","#1B9E77", "#D95F02")
barplot(tabela_sexo,main ="Gráfico 1 - Sobrevivência por sexo",
col = COR,horiz =FALSE,beside=TRUE,
legend = rownames(tabela_sexo))
COR2 <- c("red", "blue","red", "blue")
barplot(tabela_idade,main ="Gráfico 2 - Sobrevivência por idade",
col = COR2,horiz =FALSE,beside=TRUE,ylim = c(0,2000),
legend = rownames(tabela_idade))
library(dplyr)
##
## 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
# tabela em números absolutos
tabela_classe <- Titanic %>% select(Classe,Sobreviveu) %>% table()
# tabela em proporção
tabela_classe_prop <- Titanic %>% select(Classe,Sobreviveu) %>% table() %>%
prop.table(1) %>% round(2)
tabela_classe_prop
## Sobreviveu
## Classe Não sobreviveu Sobreviveu
## Tripulação 0.76 0.24
## Primeira 0.38 0.62
## Segunda 0.59 0.41
## Terceira 0.75 0.25
# gráfico de barras por grupo
COR3 <- brewer.pal(4,"Set2")
tabela_classe %>% barplot(beside=T,
col=COR3,
main= "Gráfico 3",
legend = rownames(tabela_classe))
Sim, isso aconteceu! Os dados revelam que há uma desigualdade da sobrevivência no Titanic!!