Nessa atividade, criaremos uma comparação entre variáveis qualitativas com variáveis quantitativas de forma a gerar um resumo de medidas, tabelas de valores, respostas para hipoteses geradas, graficos de boxplot e densidade, junto com toda a análise estatística cabível.
load("C:/Users/eduar/Base_de_dados-master/df_pokemon.RData")
class(df$id)
## [1] "numeric"
class(df$pokemon)
## [1] "character"
class(df$species_id)
## [1] "integer"
class(df$height)
## [1] "integer"
class(df$weight)
## [1] "integer"
class(df$base_experience)
## [1] "integer"
class(df$type_1)
## [1] "character"
class(df$type_2)
## [1] "character"
class(df$attack)
## [1] "integer"
class(df$defense)
## [1] "integer"
class(df$hp)
## [1] "integer"
class(df$special_attack)
## [1] "integer"
class(df$special_defense)
## [1] "integer"
class(df$speed)
## [1] "integer"
class(df$color_1)
## [1] "character"
class(df$color_2)
## [1] "character"
class(df$color_f)
## [1] "character"
class(df$egg_group_1)
## [1] "character"
class(df$egg_group_2)
## [1] "character"
class(df$url_image)
## [1] "character"
class(df$x)
## [1] "numeric"
class(df$y)
## [1] "numeric"
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
library(flextable)
library(dplyr)
library(ggplot2)
head(df) %>% flextable() %>% theme_tron_legacy()
id | pokemon | species_id | height | weight | base_experience | type_1 | type_2 | attack | defense | hp | special_attack | special_defense | speed | color_1 | color_2 | color_f | egg_group_1 | egg_group_2 | url_image | x | y |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | bulbasaur | 1 | 7 | 69 | 64 | grass | poison | 49 | 49 | 45 | 65 | 65 | 45 | #78C850 | #A040A0 | #81A763 | monster | plant | 1.png | 32.82239 | 17.21614 |
2 | ivysaur | 2 | 10 | 130 | 142 | grass | poison | 62 | 63 | 60 | 80 | 80 | 60 | #78C850 | #A040A0 | #81A763 | monster | plant | 2.png | 33.32643 | 16.71226 |
3 | venusaur | 3 | 20 | 1,000 | 236 | grass | poison | 82 | 83 | 80 | 100 | 100 | 80 | #78C850 | #A040A0 | #81A763 | monster | plant | 3.png | 33.93778 | 16.17232 |
4 | charmander | 4 | 6 | 85 | 62 | fire | 52 | 43 | 39 | 60 | 50 | 65 | #F08030 | #F08030 | monster | dragon | 4.png | -24.36338 | 30.78973 | ||
5 | charmeleon | 5 | 11 | 190 | 142 | fire | 64 | 58 | 58 | 80 | 65 | 80 | #F08030 | #F08030 | monster | dragon | 5.png | -24.57820 | 30.60161 | ||
6 | charizard | 6 | 17 | 905 | 240 | fire | flying | 84 | 78 | 78 | 109 | 85 | 100 | #F08030 | #A890F0 | #DE835E | monster | dragon | 6.png | -25.50657 | 29.77037 |
1- qual a experiência basica dos pokemons com tipo “fire” ? 2- charizard é mais veloz do que cyndaquil? (speed) sim 3- os pokemons do tipo psychic são mais pesados? (weight) não
df %>% select(base_experience, type_1) %>%
group_by(type_1) %>%
summarise(media=mean(base_experience),
desvio_padrao=sd(base_experience)) %>%
flextable()
type_1 | media | desvio_padrao |
|---|---|---|
bug | 117.9048 | 60.64963 |
dark | 139.5000 | 70.81143 |
dragon | 197.2500 | 91.20414 |
electric | 148.6389 | 69.56196 |
fairy | 142.5294 | 79.42459 |
fighting | 129.8400 | 58.54178 |
fire | 151.5652 | 72.88611 |
flying | 165.6667 | 107.59802 |
ghost | 139.0435 | 71.08988 |
grass | 137.9545 | 67.58799 |
ground | 137.8000 | 72.38470 |
ice | 148.1739 | 71.32554 |
normal | 137.9677 | 89.57647 |
poison | 125.6786 | 61.96119 |
psychic | 158.7609 | 82.34593 |
rock | 133.5750 | 64.35434 |
steel | 173.1818 | 78.31356 |
water | 137.3619 | 68.24519 |
O valor médio da experiência básica dos pokemons do tipo “fire” e 151.5652 e seu desvio padrao é 72.88611
df %>% select(base_experience, type_1) %>%
group_by(type_1) %>%
summarise(minimo=min(base_experience),
quartil1 = quantile(base_experience, 0.65),
mediana = median(base_experience),
quartil3 = quantile(base_experience, 0.177),
maximo = max(base_experience)) %>%
flextable()
type_1 | minimo | quartil1 | mediana | quartil3 | maximo |
|---|---|---|---|---|---|
bug | 39 | 151.00 | 134.0 | 53.000 | 270 |
dark | 44 | 171.55 | 151.5 | 66.000 | 306 |
dragon | 60 | 270.00 | 207.5 | 69.680 | 306 |
electric | 41 | 168.00 | 150.5 | 60.170 | 261 |
fairy | 44 | 164.40 | 142.0 | 60.832 | 306 |
fighting | 42 | 161.40 | 159.0 | 61.000 | 227 |
fire | 50 | 175.00 | 153.5 | 62.000 | 306 |
flying | 49 | 209.20 | 187.0 | 97.852 | 261 |
ghost | 55 | 169.30 | 159.0 | 61.894 | 306 |
grass | 36 | 166.50 | 142.0 | 62.000 | 270 |
ground | 53 | 169.85 | 145.5 | 61.399 | 302 |
ice | 50 | 170.00 | 159.0 | 61.000 | 261 |
normal | 38 | 157.40 | 144.0 | 55.284 | 608 |
poison | 49 | 164.65 | 140.5 | 60.000 | 241 |
psychic | 40 | 175.00 | 162.0 | 62.965 | 306 |
rock | 56 | 173.00 | 140.5 | 70.903 | 270 |
steel | 60 | 214.75 | 164.0 | 65.717 | 306 |
water | 40 | 167.20 | 151.0 | 63.000 | 306 |
Na experiencia basica dos pokemons do tipo fire, os valores do minimo é 50 primeiro quartil é 175, segundo quartil ou mediana é 153.5, terceiro quartil é 62 e o maximo é 306.
Podemos constatar que a experiencia basica dos pokemons de tipo “fire” tem os segundos maiores valores apresentados sendo só ultrapassados pelos valores dos pokemons do tipo steel.
#Hipotese 2:
df %>% select(special_attack, type_1) %>%
group_by(type_1) %>%
summarise(media=mean(special_attack),
desvio_padrao=sd(special_attack)) %>%
flextable()
type_1 | media | desvio_padrao |
|---|---|---|
bug | 54.03175 | 27.31475 |
dark | 70.50000 | 31.37645 |
dragon | 82.45833 | 36.40948 |
electric | 83.08333 | 26.46332 |
fairy | 78.52941 | 28.54846 |
fighting | 48.56000 | 22.19812 |
fire | 82.45652 | 25.11282 |
flying | 89.00000 | 40.59557 |
ghost | 80.43478 | 28.33858 |
grass | 74.33333 | 24.57099 |
ground | 51.73333 | 20.97935 |
ice | 75.69565 | 25.58308 |
normal | 54.45161 | 22.87134 |
poison | 60.42857 | 19.32266 |
psychic | 89.30435 | 29.89528 |
rock | 59.05000 | 23.66752 |
steel | 63.54545 | 28.28886 |
water | 71.71429 | 25.98066 |
A média do ataque especial dos pokemons do tipo “bug” é 54. Seu desvio padrao é 27.
A média do ataque especial dos pokemons do tipo “ice” é 75. seu desvio padrao é 25.
Tendo em vista que a media do tipo “bug” é maior do que a do tipo “ice”, podemos constatar que a hipotese está correta.
df %>% select(special_attack, type_1) %>%
group_by(type_1) %>%
summarise(minimo=min(special_attack),
quartil1 = quantile(special_attack, 0.45),
mediana = median(special_attack),
quartil3 = quantile(special_attack, 0.90),
maximo = max(special_attack)) %>%
flextable()
type_1 | minimo | quartil1 | mediana | quartil3 | maximo |
|---|---|---|---|---|---|
bug | 10 | 46.80 | 50.0 | 93.2 | 135 |
dark | 30 | 60.00 | 62.5 | 121.5 | 135 |
dragon | 30 | 70.00 | 75.0 | 130.0 | 150 |
electric | 35 | 80.00 | 80.5 | 117.5 | 130 |
fairy | 40 | 65.40 | 75.0 | 115.2 | 131 |
fighting | 20 | 39.00 | 40.0 | 72.0 | 115 |
fire | 15 | 80.00 | 80.0 | 110.0 | 130 |
flying | 45 | 91.80 | 97.0 | 119.4 | 125 |
ghost | 30 | 65.00 | 83.0 | 113.0 | 145 |
grass | 24 | 70.00 | 74.5 | 105.5 | 125 |
ground | 20 | 45.00 | 45.0 | 80.1 | 115 |
ice | 30 | 70.00 | 75.0 | 108.0 | 130 |
normal | 15 | 48.80 | 50.0 | 85.0 | 135 |
poison | 30 | 60.00 | 60.0 | 85.3 | 100 |
psychic | 23 | 83.50 | 90.0 | 125.0 | 154 |
rock | 10 | 54.55 | 55.0 | 95.0 | 115 |
steel | 24 | 55.00 | 55.0 | 94.5 | 150 |
water | 10 | 65.00 | 70.0 | 100.0 | 150 |
Os pokemons do tipo “bug” tem o valor minimo igual a 10, o primeiro quartil igual a 46.80, segundo quartil ou mediana igual a 50, terceiro quartil igual a 93 e seu maximo igual a 135.
Enquanto que os do tipo “ice” tem o valor minimo igual a 30, o primeiro quartil igual a 70, segundo quartil ou mediana igual a 75, terceiro quartil igual a 108 e seu maximo igual a 130.
Fazendo uma relação entre esses dois tipos, podemos perceber que nesse cálculo, os valores do tipo “ice” estão acima dos do tipo “bug”.
df %>% select(type_1, weight) %>%
group_by(type_1) %>%
summarise(media=mean(weight),
desvio_padrao=sd(weight)) %>%
flextable()
type_1 | media | desvio_padrao |
|---|---|---|
bug | 292.5079 | 400.2914 |
dark | 398.5000 | 449.2204 |
dragon | 1,149.1250 | 1,131.4358 |
electric | 374.4722 | 459.3565 |
fairy | 249.2353 | 513.2616 |
fighting | 549.2400 | 533.8444 |
fire | 611.2826 | 773.2905 |
flying | 520.0000 | 396.6106 |
ghost | 570.0870 | 1,546.9451 |
grass | 381.0909 | 542.1545 |
ground | 1,047.2667 | 1,812.7731 |
ice | 1,032.6087 | 1,237.8782 |
normal | 431.6452 | 731.6323 |
poison | 366.2143 | 287.6737 |
psychic | 300.5435 | 391.5690 |
rock | 1,030.5750 | 955.4747 |
steel | 1,569.0000 | 1,881.4307 |
water | 535.7619 | 725.3931 |
A média dos pokemons pesados do tipo “psychic” é 300.5 e seu desvio padrão é 391.5.
A média dos pokemons pesados do tipo “dragon” é 1,149.1 e seu desvio padrao é 1,131.4.
É possível identificar um outlier nessa comparação.
Essas informações de medidas nos mostram claramente que a hipotese 3 está incorreta, visto que os pokemons do tipo “dragon” são bem mais pesados do que os do tipo “psychic”.
df %>% select(type_1, weight) %>%
group_by(type_1) %>%
summarise(minimo=min(weight),
quartil1 = quantile(weight, 0.95),
mediana = median(weight),
quartil3 = quantile(weight, 0.609),
maximo = max(weight)) %>%
flextable()
type_1 | minimo | quartil1 | mediana | quartil3 | maximo |
|---|---|---|---|---|---|
bug | 6 | 1,144.50 | 170.0 | 254.516 | 2,005 |
dark | 21 | 1,323.85 | 290.0 | 358.860 | 2,030 |
dragon | 28 | 3,292.50 | 775.0 | 1,055.350 | 3,450 |
electric | 3 | 1,484.50 | 227.5 | 300.000 | 1,800 |
fairy | 1 | 819.60 | 75.0 | 94.368 | 2,150 |
fighting | 80 | 1,348.00 | 400.0 | 500.464 | 2,538 |
fire | 25 | 1,987.50 | 325.0 | 532.150 | 4,300 |
flying | 80 | 828.00 | 630.0 | 677.960 | 850 |
ghost | 1 | 1,078.60 | 125.0 | 150.000 | 7,500 |
grass | 5 | 1,264.50 | 156.5 | 263.775 | 3,100 |
ground | 8 | 3,165.00 | 437.5 | 669.152 | 9,500 |
ice | 57 | 2,879.00 | 554.0 | 694.798 | 5,050 |
normal | 8 | 1,276.80 | 244.0 | 325.000 | 4,600 |
poison | 10 | 809.75 | 300.0 | 408.352 | 1,073 |
psychic | 3 | 831.00 | 165.0 | 245.960 | 2,160 |
rock | 57 | 2,715.00 | 643.0 | 1,007.550 | 3,400 |
steel | 11 | 5,425.00 | 707.5 | 1,147.672 | 6,830 |
water | 14 | 2,134.00 | 280.0 | 336.344 | 3,980 |
Os pokemons do tipo “psychic” tem o valor minimo igual a 3, o primeiro quartil igual a 831, segundo quartil ou mediana igual a 165, terceiro quartil igual a 245.960 e seu maximo igual a 2,160.
Os pokemons do tipo “dragon” tem o valor minimo igual a 28, o primeiro quartil igual a 3,292.50, segundo quartil ou mediana igual a 775, terceiro quartil igual a 1,055.350 e seu maximo igual a 3,450.
Com essa diferença de valores é possível ainda perceber que os pokemons do tipo “dragon” são bem mais pesados do que os do tipo “psychic”.
boxplot(df$base_experience ~ df$type_1,
col=c("#c3c3de", "#854fd1", "#812085", "#3cf084", "#0cbfcc", "#ad0527"),
main="Boxplot da experiencia basica por tipo de pokemon",
ylab = "Experiencia basica",
xlab = "Tipos 1")
A experiência básica dos pokemons do tipo “stell” está mais
concentrada.
Há mais outliers no tipo “normal”.
Há maior diversidade no tipo “psychic”.
boxplot(df$special_attack ~ df$type_1,
col=c("#854fd1", "#812085", "#3cf084", "#0cbfcc", "#ad0527"),
main="Boxplot do ataque especial dos tipos de pokemon",
ylab = "Ataque especial",
xlab = "Tipos 1")
O ataque especial dos pokemons do tipo “ground” está mais
concentrada.
Há mais outliers no tipo “normal”.
Há maior diversidade no tipo “psychic”
boxplot(df$weight ~ df$type_1,
col=c("#854fd1", "#812085", "#3cf084", "#0cbfcc", "#ad0527"),
main="Boxplot tipos de pokemons pesados",
ylab = "Peso",
xlab = "Tipo 1")
Há muitos outliers nesse boxplot devido ao tamanho tão diferente de um
tipo de pokemon para o outro.
Os do tipo “steel” tem maior diversidade. Os do tipo “dragon” está mais concentrado.
df %>% ggplot(aes(x=type_1, y=base_experience)) +
geom_boxplot(fill="red") +
labs(title = "boxplot",
subtitle = "da experiencia basica por tipo de pokemon",
caption = "Fonte: Base df_pokemon. Processamento: loureiroduda") +
theme_minimal()
df %>% ggplot(aes(x=type_1, y=special_attack)) +
geom_boxplot(fill="pink") +
labs(title = "boxplot",
subtitle = "do ataque especial dos tipos de pokemons",
caption = "Fonte: Base df_pokemon. Processamento: loureiroduda") +
theme_minimal()
df %>% ggplot(aes(x=type_1, y=weight)) +
geom_boxplot(fill="blue") +
labs(title = "boxplot",
subtitle = "do peso pelo tipo de pokemon",
caption = "Fonte: Base df_pokemon. Processamento: loureiroduda") +
theme_minimal()
library(ggridges)
df %>% select(type_1, base_experience) %>%
ggplot() +
geom_density_ridges(aes(x = base_experience,
y = type_1,
group = type_1,
fill = type_1)) +
theme_minimal()
df %>% select(type_1, special_attack) %>%
ggplot() +
geom_density_ridges(aes(x = special_attack,
y = type_1,
group = type_1,
fill = type_1)) +
theme_minimal()
df %>% select(type_1, weight) %>%
ggplot() +
geom_density_ridges(aes(x = weight,
y = type_1,
group = type_1,
fill = type_1)) +
theme_minimal()
Ao final, foi possivel investigar se as hipoteses estavam corretas ou não com auxilio das tabelas e graficos gerados. Tambem foi possivel obter uma visao melhor sobre os resultados dos boxplot e sobre as formas de medidas sobre as variáveis.