### Setup
getwd()
## [1] "C:/Users/Jerome/Documents/0000_Work_Files/0000_Montgomery_College/Data_Science_101/Data_101_Fall_2022/221107_Quiz_3"
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.5 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(dplyr)
library(readr)
### Read the Dataset
heroes <- read_csv("heroes_information.csv")
## New names:
## Rows: 734 Columns: 11
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (8): name, Gender, Eye color, Race, Hair color, Publisher, Skin color, A... dbl
## (3): ...1, Height, Weight
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
### Question 1 - Examine the data

dim(heroes)
## [1] 734  11
str(heroes)
## spec_tbl_df [734 × 11] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ...1      : num [1:734] 0 1 2 3 4 5 6 7 8 9 ...
##  $ name      : chr [1:734] "A-Bomb" "Abe Sapien" "Abin Sur" "Abomination" ...
##  $ Gender    : chr [1:734] "Male" "Male" "Male" "Male" ...
##  $ Eye color : chr [1:734] "yellow" "blue" "blue" "green" ...
##  $ Race      : chr [1:734] "Human" "Icthyo Sapien" "Ungaran" "Human / Radiation" ...
##  $ Hair color: chr [1:734] "No Hair" "No Hair" "No Hair" "No Hair" ...
##  $ Height    : num [1:734] 203 191 185 203 -99 193 -99 185 173 178 ...
##  $ Publisher : chr [1:734] "Marvel Comics" "Dark Horse Comics" "DC Comics" "Marvel Comics" ...
##  $ Skin color: chr [1:734] "-" "blue" "red" "-" ...
##  $ Alignment : chr [1:734] "good" "good" "good" "bad" ...
##  $ Weight    : num [1:734] 441 65 90 441 -99 122 -99 88 61 81 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ...1 = col_double(),
##   ..   name = col_character(),
##   ..   Gender = col_character(),
##   ..   `Eye color` = col_character(),
##   ..   Race = col_character(),
##   ..   `Hair color` = col_character(),
##   ..   Height = col_double(),
##   ..   Publisher = col_character(),
##   ..   `Skin color` = col_character(),
##   ..   Alignment = col_character(),
##   ..   Weight = col_double()
##   .. )
##  - attr(*, "problems")=<externalptr>
glimpse(heroes)
## Rows: 734
## Columns: 11
## $ ...1         <dbl> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,…
## $ name         <chr> "A-Bomb", "Abe Sapien", "Abin Sur", "Abomination", "Abrax…
## $ Gender       <chr> "Male", "Male", "Male", "Male", "Male", "Male", "Male", "…
## $ `Eye color`  <chr> "yellow", "blue", "blue", "green", "blue", "blue", "blue"…
## $ Race         <chr> "Human", "Icthyo Sapien", "Ungaran", "Human / Radiation",…
## $ `Hair color` <chr> "No Hair", "No Hair", "No Hair", "No Hair", "Black", "No …
## $ Height       <dbl> 203, 191, 185, 203, -99, 193, -99, 185, 173, 178, 191, 18…
## $ Publisher    <chr> "Marvel Comics", "Dark Horse Comics", "DC Comics", "Marve…
## $ `Skin color` <chr> "-", "blue", "red", "-", "-", "-", "-", "-", "-", "-", "-…
## $ Alignment    <chr> "good", "good", "good", "bad", "bad", "bad", "good", "goo…
## $ Weight       <dbl> 441, 65, 90, 441, -99, 122, -99, 88, 61, 81, 104, 108, 90…
colSums(is.na(heroes))
##       ...1       name     Gender  Eye color       Race Hair color     Height 
##          0          0          0          0          0          0          0 
##  Publisher Skin color  Alignment     Weight 
##         15          0          0          2
names(heroes)
##  [1] "...1"       "name"       "Gender"     "Eye color"  "Race"      
##  [6] "Hair color" "Height"     "Publisher"  "Skin color" "Alignment" 
## [11] "Weight"
### There are no factor variables - gender, for example, or Publisher, might be good factor variables. There aren't many NAs, but there are many blanks in the data set. The blanks could be a headache. 
### Question 2
table(heroes$Race)
## 
##                  -              Alien              Alpha             Amazon 
##                304                  7                  5                  2 
##            Android             Animal          Asgardian          Atlantean 
##                  9                  4                  5                  5 
##            Bizarro         Bolovaxian              Clone      Cosmic Entity 
##                  1                  1                  1                  4 
##             Cyborg           Czarnian Dathomirian Zabrak           Demi-God 
##                 11                  1                  1                  2 
##              Demon            Eternal     Flora Colossus        Frost Giant 
##                  6                  2                  1                  2 
##      God / Eternal            Gorilla             Gungan              Human 
##                 14                  1                  1                208 
##         Human-Kree      Human-Spartoi       Human-Vulcan    Human-Vuldarian 
##                  2                  1                  1                  1 
##    Human / Altered      Human / Clone     Human / Cosmic  Human / Radiation 
##                  3                  1                  2                 11 
##      Icthyo Sapien            Inhuman              Kaiju    Kakarantharaian 
##                  1                  4                  1                  1 
##          Korugaran         Kryptonian          Luphomoid              Maiar 
##                  1                  7                  1                  1 
##            Martian          Metahuman             Mutant     Mutant / Clone 
##                  1                  2                 63                  1 
##            New God           Neyaphem          Parademon             Planet 
##                  3                  1                  1                  1 
##             Rodian             Saiyan            Spartoi          Strontian 
##                  1                  2                  1                  1 
##           Symbiote           Talokite         Tamaranean            Ungaran 
##                  9                  1                  1                  1 
##            Vampire    Xenomorph XX121             Yautja     Yoda's species 
##                  2                  1                  1                  1 
##      Zen-Whoberian             Zombie 
##                  1                  1
### There are 208 Human superheroes in the data set, w/ another 22 variants of human. The 2nd highest category is mutant. The largest group is blank, but we are not to count the blanks.
 as.factor(heroes$Race)
##   [1] Human              Icthyo Sapien      Ungaran           
##   [4] Human / Radiation  Cosmic Entity      Human             
##   [7] -                  Human              -                 
##  [10] Human              -                  -                 
##  [13] Cyborg             -                  Human             
##  [16] -                  Human              Xenomorph XX121   
##  [19] -                  Android            Human             
##  [22] -                  -                  Vampire           
##  [25] Mutant             -                  -                 
##  [28] Human              -                  Human             
##  [31] Human              God / Eternal      -                 
##  [34] Symbiote           Mutant             -                 
##  [37] Atlantean          Atlantean          Human             
##  [40] Mutant             -                  Alien             
##  [43] -                  -                  -                 
##  [46] Human              -                  Mutant            
##  [49] God / Eternal      -                  -                 
##  [52] -                  Human              -                 
##  [55] -                  Mutant             Neyaphem          
##  [58] Human              -                  Human             
##  [61] Human              -                  -                 
##  [64] Human              -                  Human             
##  [67] -                  -                  Human             
##  [70] Human              Human              -                 
##  [73] Human              -                  Mutant            
##  [76] Human              -                  -                 
##  [79] -                  God / Eternal      New God           
##  [82] -                  -                  Alpha             
##  [85] -                  -                  Cyborg            
##  [88] -                  Human              Human             
##  [91] God / Eternal      Mutant             Bizarro           
##  [94] -                  -                  Inhuman           
##  [97] Human              Metahuman          Human             
## [100] God / Eternal      -                  Human             
## [103] -                  -                  Human             
## [106] Human              Human              -                 
## [109] Demon              -                  Alien             
## [112] Vampire            -                  -                 
## [115] Mutant             -                  -                 
## [118] -                  -                  Human             
## [121] Mutant             -                  -                 
## [124] -                  -                  Human             
## [127] Human / Clone      -                  -                 
## [130] Mutant             -                  Human             
## [133] -                  -                  -                 
## [136] Android            -                  Human             
## [139] Mutant             Human              Human             
## [142] Human              -                  Human             
## [145] Mutant             -                  Alpha             
## [148] -                  Human              Human / Radiation 
## [151] Human              Human              -                 
## [154] Human              -                  Human-Kree        
## [157] Human              Human              Human             
## [160] God / Eternal      God / Eternal      Symbiote          
## [163] -                  -                  Human             
## [166] -                  Alien              Mutant            
## [169] Mutant             -                  -                 
## [172] Human              Human              Human             
## [175] -                  -                  Human             
## [178] -                  -                  -                 
## [181] Human              -                  -                 
## [184] -                  Mutant             Mutant            
## [187] -                  Human              -                 
## [190] -                  Inhuman            -                 
## [193] -                  Cyborg             Cyborg            
## [196] Mutant             -                  -                 
## [199] -                  -                  Human             
## [202] Human              -                  New God           
## [205] -                  Mutant             Dathomirian Zabrak
## [208] Cyborg             Human              Android           
## [211] Mutant             Human              Mutant            
## [214] Human              Cyborg             Human             
## [217] Demon              -                  Human             
## [220] -                  Human / Radiation  Human             
## [223] -                  Human              Human             
## [226] Human              Human              Mutant            
## [229] Amazon             Alien              -                 
## [232] -                  Human / Cosmic     Human / Altered   
## [235] -                  Human              Human             
## [238] Human              -                  -                 
## [241] -                  Human              -                 
## [244] -                  Human              Demon             
## [247] Mutant             Alien              Mutant            
## [250] -                  Human              -                 
## [253] Kryptonian         -                  -                 
## [256] Kakarantharaian    -                  -                 
## [259] Mutant             -                  Human             
## [262] -                  Human              -                 
## [265] Human              Human              Human             
## [268] -                  Mutant             -                 
## [271] -                  -                  Cosmic Entity     
## [274] Mutant             Zen-Whoberian      Mutant            
## [277] Alpha              Kryptonian         -                 
## [280] Demon              -                  Human             
## [283] -                  -                  Strontian         
## [286] -                  Kaiju              -                 
## [289] Saiyan             -                  Human             
## [292] Human              -                  Gorilla           
## [295] -                  Human              Rodian            
## [298] Human              Human              -                 
## [301] -                  -                  Flora Colossus    
## [304] Human              Human-Vuldarian    Human             
## [307] Human              Human              Human             
## [310] Human              Mutant             -                 
## [313] Human              Human              -                 
## [316] -                  -                  -                 
## [319] -                  Human              Asgardian         
## [322] Demon              Human              -                 
## [325] Demi-God           -                  Human             
## [328] -                  -                  -                 
## [331] -                  Human / Radiation  Human / Radiation 
## [334] -                  Mutant             Symbiote          
## [337] -                  Eternal            Mutant            
## [340] Human              Human              Alien             
## [343] Mutant             Human / Radiation  Human             
## [346] Human              -                  -                 
## [349] -                  Human              Human             
## [352] Human              Human              Gungan            
## [355] Human              Mutant             Human             
## [358] -                  Human              Human             
## [361] Human              -                  -                 
## [364] -                  -                  -                 
## [367] Human              Human              -                 
## [370] Human              -                  Mutant            
## [373] Human              Human              Mutant            
## [376] Human              Human              Android           
## [379] -                  Human              Human             
## [382] Human              Human              Human             
## [385] Human              -                  Metahuman         
## [388] Human              Bolovaxian         Animal            
## [391] Animal             Human              Human             
## [394] -                  Human              Human             
## [397] Kryptonian         Human              Human             
## [400] -                  Cyborg             -                 
## [403] -                  Mutant             Mutant            
## [406] Human              -                  -                 
## [409] -                  -                  Cosmic Entity     
## [412] -                  Human              Czarnian          
## [415] Asgardian          Human              Human             
## [418] -                  Human              Human             
## [421] -                  -                  -                 
## [424] Mutant             -                  -                 
## [427] God / Eternal      Human              -                 
## [430] -                  Human              Human-Kree        
## [433] Martian            -                  -                 
## [436] Human / Altered    -                  -                 
## [439] -                  -                  -                 
## [442] Inhuman            -                  -                 
## [445] Atlantean          Android            -                 
## [448] -                  -                  -                 
## [451] Mutant             -                  -                 
## [454] -                  -                  -                 
## [457] Human / Radiation  Human              Spartoi           
## [460] God / Eternal      Human / Altered    Human             
## [463] Human              Cyborg             Planet            
## [466] -                  -                  -                 
## [469] -                  -                  Human             
## [472] -                  -                  -                 
## [475] -                  Mutant             Human             
## [478] -                  -                  Human             
## [481] Mutant             -                  Atlantean         
## [484] -                  -                  Human             
## [487] -                  Luphomoid          Mutant            
## [490] Human              -                  Human             
## [493] -                  Alpha              -                 
## [496] -                  Human              Human / Cosmic    
## [499] God / Eternal      -                  -                 
## [502] -                  Human              Cosmic Entity     
## [505] Mutant             Human              -                 
## [508] -                  Human              Parademon         
## [511] Human              -                  -                 
## [514] -                  Human              -                 
## [517] -                  -                  Mutant            
## [520] Mutant             -                  Human             
## [523] -                  Human              Mutant            
## [526] Kryptonian         Mutant             Yautja            
## [529] Mutant             Human              -                 
## [532] Mutant             Human              Human             
## [535] -                  God / Eternal      -                 
## [538] Human              Mutant             -                 
## [541] Human              Alpha              Human             
## [544] Mutant             Human              Human             
## [547] -                  Human              Human             
## [550] Human / Radiation  -                  Human             
## [553] -                  Android            -                 
## [556] -                  -                  Human             
## [559] Human / Radiation  -                  -                 
## [562] Human              -                  Human             
## [565] Human              Human              Human             
## [568] Human              Animal             -                 
## [571] Human              Human              Mutant            
## [574] -                  Human              -                 
## [577] Maiar              -                  Human             
## [580] Human              Clone              Mutant            
## [583] -                  Human              Mutant            
## [586] Mutant             -                  Talokite          
## [589] Mutant             Human              -                 
## [592] Human              Human / Radiation  Human             
## [595] -                  -                  Asgardian         
## [598] Human              -                  -                 
## [601] Alien              -                  Human             
## [604] Korugaran          Atlantean          -                 
## [607] -                  -                  Animal            
## [610] -                  -                  Zombie            
## [613] -                  Human              Demon             
## [616] God / Eternal      -                  Human             
## [619] Human              Symbiote           Human             
## [622] Human              Human              Human             
## [625] Human              Human              -                 
## [628] -                  -                  Human-Vulcan      
## [631] Mutant             -                  Human-Spartoi     
## [634] -                  Tamaranean         Human             
## [637] Mutant             -                  -                 
## [640] New God            Mutant             Human             
## [643] Mutant             -                  Kryptonian        
## [646] Kryptonian         Kryptonian         God / Eternal     
## [649] Mutant             -                  -                 
## [652] Android            Cyborg             Cyborg            
## [655] Cyborg             Human              -                 
## [658] Eternal            -                  Human             
## [661] Human / Radiation  Asgardian          Asgardian         
## [664] -                  -                  -                 
## [667] -                  -                  Human             
## [670] -                  -                  -                 
## [673] Mutant             Symbiote           Symbiote          
## [676] -                  Human              God / Eternal     
## [679] -                  Inhuman            -                 
## [682] -                  Android            Frost Giant       
## [685] -                  -                  -                 
## [688] -                  Saiyan             Symbiote          
## [691] -                  Symbiote           Symbiote          
## [694] -                  Human              Human             
## [697] -                  -                  Human             
## [700] Android            -                  Human             
## [703] -                  Human              Human             
## [706] Human              -                  -                 
## [709] -                  Mutant             Human             
## [712] -                  -                  Human             
## [715] -                  -                  Human             
## [718] -                  -                  Mutant            
## [721] Demi-God           -                  Amazon            
## [724] -                  -                  Mutant / Clone    
## [727] -                  -                  Human             
## [730] Human              Frost Giant        Yoda's species    
## [733] Human              -                 
## 62 Levels: - Alien Alpha Amazon Android Animal Asgardian Atlantean ... Zombie
 class(heroes$Race)
## [1] "character"
 heroes %>% group_by(Race)%>% summarise(Num_Races = n()) %>% arrange(desc(Num_Races))
## # A tibble: 62 × 2
##    Race              Num_Races
##    <chr>                 <int>
##  1 -                       304
##  2 Human                   208
##  3 Mutant                   63
##  4 God / Eternal            14
##  5 Cyborg                   11
##  6 Human / Radiation        11
##  7 Android                   9
##  8 Symbiote                  9
##  9 Alien                     7
## 10 Kryptonian                7
## # … with 52 more rows
### Question 3 

table(heroes$Gender)
## 
##      - Female   Male 
##     29    200    505
### There are 200 female superheroes. Not counting gender blank, female superheroes are 28.37% of the total. 
200/705
## [1] 0.2836879
### Question #4
table(heroes$Gender, heroes$Alignment)
##         
##            - bad good neutral
##   -        1   7   19       2
##   Female   0  35  161       4
##   Male     6 165  316      18
161/200
## [1] 0.805
316/499
## [1] 0.6332665
### The table tells us that 80% of the female superheroes are good, as compared to only 63% of the males. (Ignoring the no data column.)
### Question 5
no_hw <- filter(heroes, Height > 0 & Weight > 0)
### Question 6
mean(no_hw$Height)
## [1] 187.1239
median(no_hw$Height)
## [1] 183
sd(no_hw$Height)
## [1] 58.99002
mean(no_hw$Weight)
## [1] 112.1796
median(no_hw$Weight)
## [1] 81
sd(no_hw$Weight)
## [1] 104.4227
hist(no_hw$Weight)

### The distribution is not normally distributed; it is skewed to the right; the mean is higher than the median and the mode. Most superheroes weigh 200# or less. 
### Question 8 

plot(no_hw$Height, no_hw$Weight) 

cor(no_hw$Height, no_hw$Weight) #I did the correlation after class. I couldn't get it to work in class. Or if I did, i didn't see it in the R Console. So i got the interpretation wrong b/c there is no correlation. 
## [1] 0.1934412
### The plot tells us most of the superheroes are the same height and weight. 
### Question 9
boxplot(no_hw$Weight ~ no_hw$Alignment)

fivenum(no_hw$Weight)
## [1]   4  61  81 106 900
fivenum(no_hw$Height)
## [1]  15.2 173.0 183.0 188.0 975.0
### Question 10
### The boxplot tells us nothing. Good and bad seem to be the same; maybe neutral is a little different; a higher IQR maybe.