Atividade 8 - Cruzamento de variável qualitativa e quantitativa

Atividade proposta foi interpretar as estatísticas de:

1.Média e Desvio-Padrão

Para uma variável quantitativa por grupos de uma variável qualitativa.

2.Boxplot

Para uma variável quantitativa por grupos de uma variável qualitativa.

Passo 0 - Carregar as bibliotecas

#Passo 0 - Carregar as bibliotecas:

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
library(flextable)
library(RColorBrewer)

Passo 1 - Importar a Base de Dados

Dessa vez a base escolhida para o trabalho fornece informações sobre os pokemons da primeira temporada do desenho que se passa na ilha de Kanto.

#Passo 1 - Importar a Base de Dados

load("C:/Users/loren/Downloads/Estatistica/Base_de_dados-master/df_pokemon.RData")

Passo 2 - Conhecendo a base

Analise inicial da base

Trabalharemos com um grupo de 718 amostras e 22 variáveis.

#Conhecendo a Base:
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  
head(df)
# A tibble: 6 x 22
     id pokemon    species_id height weight base_experience type_1 type_2 attack
  <dbl> <chr>           <int>  <int>  <int>           <int> <chr>  <chr>   <int>
1     1 bulbasaur           1      7     69              64 grass  poison     49
2     2 ivysaur             2     10    130             142 grass  poison     62
3     3 venusaur            3     20   1000             236 grass  poison     82
4     4 charmander          4      6     85              62 fire   <NA>       52
5     5 charmeleon          5     11    190             142 fire   <NA>       64
6     6 charizard           6     17    905             240 fire   flying     84
# ... with 13 more variables: defense <int>, hp <int>, special_attack <int>,
#   special_defense <int>, speed <int>, color_1 <chr>, color_2 <chr>,
#   color_f <chr>, egg_group_1 <chr>, egg_group_2 <chr>, url_image <chr>,
#   x <dbl>, y <dbl>

Passo 3 - Formatanto como tabela

Usarei o pacote Flextable para formatar como tabela as variáveis escolhidas para análise de correlação que são: Tipo 1 e ataque.

df %>% select(type_1,attack) %>% table() %>% data.frame() %>% flextable()

Passo 4 - Correlação de Qualitativa x Quantitativa

Com o Através do vetor A1 (Análise 1), extraímos as médias e desvios padrão das variáveis selecionadas.

A1 <- df %>% select(type_1,attack) %>%
  group_by(type_1) %>%
  summarise(media_ataque=mean(attack),
            desvio_padrao_ataque=sd(attack),
            quantidade=n()) %>%
  data.frame() %>% flextable()

A1 %>% theme_zebra()

Passo 5 - Gráfico Boxplot Qualitativa x Quantitativa

Analisando Tipo de Pokemon e a sua força de ataque

Passo 5 - Gráfico

#boxplot(attack~type_1,data=df, # main=“Gráfico 1- Tipo de Pokemon x Força de Ataque”, #col=c(COR))

#COR<- brewer.pal(12,“Set3”) #COR

#Apresentou o erro: Error in boxplot.default(split(mf[[response]], mf[-response]), ainda em análise para entendimento, pois o gráfico foi executado no Scrip.