Loading necessary packages

#install.packages("Rserve")
library(Rserve)
## Warning: package 'Rserve' was built under R version 3.1.3
Rserve()
## Starting Rserve...
##  "C:\Users\user\DOCUME~1\R\WIN-LI~1\3.1\Rserve\libs\x64\Rserve.exe"
library(XML)
## Warning: package 'XML' was built under R version 3.1.3
library(maps)
data(county.fips)
require(mapproj)
## Loading required package: mapproj
require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.1.3
data(state.fips)
data(city.fips)
## Warning in data(city.fips): data set 'city.fips' not found
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.1.3
## 
## Attaching package: 'dplyr'
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(knitr)

Data Formatting

## NYC data format
nyc_df<- data.frame("Cause"= nyc_dt$MCD...ICD.10.113.Cause.List,  
                 "County"= nyc_dt$County, 
                 "County_Code"= nyc_dt$County.Code, 
                 "Gender"= nyc_dt$Gender.Code,   
                 "Race"= nyc_dt$Race, 
                 "Age"= nyc_dt$Ten.Year.Age.Groups,
                 "Deaths"= nyc_dt$Deaths
)

# NYC sample data 
kable(head(nyc_df))
Cause County County_Code Gender Race Age Deaths
Septicemia (A40-A41) Bronx County, NY 36005 F White 45-54 years 15
Septicemia (A40-A41) Bronx County, NY 36005 M White 45-54 years 16
Septicemia (A40-A41) Bronx County, NY 36005 F White 55-64 years 13
Septicemia (A40-A41) Bronx County, NY 36005 M White 55-64 years 26
Septicemia (A40-A41) Bronx County, NY 36005 F White 65-74 years 29
Septicemia (A40-A41) Bronx County, NY 36005 M White 65-74 years 31
## NY state data format

nys_df<- data.frame("Cause"= nys_dt$MCD...ICD.10.113.Cause.List,  
                    "County"= nys_dt$County, 
                    "County_Code"= nys_dt$County.Code, 
                    "Gender"= nys_dt$Gender.Code,   
                    "Race"= nys_dt$Race, 
                    "Age"= nys_dt$Ten.Year.Age.Groups,
                    "Deaths"= nys_dt$Deaths
)

# NYS data sample outpt
kable(head(nys_df))
Cause County County_Code Gender Race Age Deaths
Septicemia (A40-A41) Bronx County, NY 36005 F White 45-54 years 15
Septicemia (A40-A41) Bronx County, NY 36005 M White 45-54 years 16
Septicemia (A40-A41) Bronx County, NY 36005 F White 55-64 years 13
Septicemia (A40-A41) Bronx County, NY 36005 M White 55-64 years 26
Septicemia (A40-A41) Bronx County, NY 36005 F White 65-74 years 29
Septicemia (A40-A41) Bronx County, NY 36005 M White 65-74 years 31
## US Female data format 

usf_df<- data.frame("Cause"= usf_dt$MCD...ICD.10.113.Cause.List,  
                    "State"= usf_dt$State, 
                    "State_Code"= usf_dt$State.Code, 
                    "Gender"= usf_dt$Gender.Code,   
                    "Race"= usf_dt$Race, 
                    "Age"= usf_dt$Ten.Year.Age.Groups,
                    "Deaths"= usf_dt$Deaths
)

# US Female sample data
kable(head(usf_df))
Cause State State_Code Gender Race Age Deaths
Certain other intestinal infections (A04,A07-A09) California 6 FALSE White 45-54 years 10
Certain other intestinal infections (A04,A07-A09) California 6 FALSE White 75-84 years 17
Certain other intestinal infections (A04,A07-A09) California 6 FALSE White 85+ years 24
Certain other intestinal infections (A04,A07-A09) Florida 12 FALSE White 85+ years 12
Septicemia (A40-A41) Arizona 4 FALSE White 45-54 years 11
Septicemia (A40-A41) Arizona 4 FALSE White 55-64 years 12
## US Male data format 
usm_df<- data.frame("Cause"= usm_dt$MCD...ICD.10.113.Cause.List,  
                    "State"= usm_dt$State, 
                    "State_Code"= usm_dt$State.Code, 
                    "Gender"= usm_dt$Gender.Code,   
                    "Race"= usm_dt$Race, 
                    "Age"= usm_dt$Ten.Year.Age.Groups,
                    "Deaths"= usm_dt$Deaths
)

# US Male sample data
kable(head(usm_df))
Cause State State_Code Gender Race Age Deaths
Certain other intestinal infections (A04,A07-A09) California 6 M White 65-74 years 10
Certain other intestinal infections (A04,A07-A09) California 6 M White 75-84 years 14
Septicemia (A40-A41) Arizona 4 M White 55-64 years 23
Septicemia (A40-A41) Arizona 4 M White 65-74 years 15
Septicemia (A40-A41) Arizona 4 M White 75-84 years 20
Septicemia (A40-A41) California 6 M White < 1 year 10
##  Chicago data format 
chicago_df<- data.frame("Cause"= chicago_dt$ICD.10.113.Cause.List,  
                    "State"= chicago_dt$State, 
                    "State_Code"= chicago_dt$State.Code,
                    "Gender"= chicago_dt$Gender.Code,
                    "Race"= chicago_dt$Race, 
                    "Age"= chicago_dt$Ten.Year.Age.Groups,
                    "Deaths"= chicago_dt$Deaths
  )

#  Chicago sample data 
kable(head(chicago_df))
Cause State State_Code Gender Race Age Deaths
Certain other intestinal infections (A04,A07-A09) Illinois 17 F White 75-84 years 28
Certain other intestinal infections (A04,A07-A09) Illinois 17 M White 75-84 years 20
Certain other intestinal infections (A04,A07-A09) Illinois 17 F White 85+ years 46
#Septicemia (A40-A41) Illinois 17 M Black or African American 35-44 years 15
#Septicemia (A40-A41) Illinois 17 F Black or African American 45-54 years 17
#Septicemia (A40-A41) Illinois 17 F White 45-54 years 16
## Illinois data format
illinois_df<- data.frame("Cause"= illinois_dt$ICD.10.113.Cause.List,  
                        "County"= illinois_dt$County, 
                        "County_Code"= illinois_dt$County.Code,
                        "Gender"= illinois_dt$Gender.Code,
                        "Race"= illinois_dt$Race, 
                        "Age"= illinois_dt$Ten.Year.Age.Groups,
                        "Deaths"= illinois_dt$Deaths
)

# Illinois sample data
kable(head(illinois_df))
Cause County County_Code Gender Race Age Deaths
Certain other intestinal infections (A04,A07-A09) Cook County, IL 17031 F White 75-84 years 28
Certain other intestinal infections (A04,A07-A09) Cook County, IL 17031 M White 75-84 years 20
Certain other intestinal infections (A04,A07-A09) Cook County, IL 17031 F White 85+ years 46
#Septicemia (A40-A41) Cook County, IL 17031 M Black or African American 35-44 years 15
#Septicemia (A40-A41) Cook County, IL 17031 F Black or African American 45-54 years 17
#Septicemia (A40-A41) Cook County, IL 17031 F White 45-54 years 16
All_male_il_df <- data.frame(All_male_il)

kable(All_male_il_df)
V1 V2
Leading Causes of Death, 2007 – All Ages NA
All causes 100,254
Diseases of heart 25,766
Malignant neoplasms 24,084
Cerebrovascular diseases 5,851
Chronic lower respiratory diseases 4,731
Accidents 4,319
      Motor vehicle accidents 1,352
      All other accidents 2,967
Diabetes mellitus 2,850
Alzheimer’s disease 2,729
Influenza and pneumonia 2,549
Nephritis, nephrotic syndrome and nephrosis 2,532
Septicemia 2,099
Intentional self-harm (suicide) 1,102
Chronic liver disease and cirrhosis 1,029
Essential hypertension and hypertensive renal disease 855
Assault (homicide) 854
Pneumonitis due to solids and liquids 821
Parkinsons’s disease 817
In situ neoplasms, benign neoplasms and neoplasms of uncertain or unknown behavior 679
Certain conditions originating in the perinatal period 670
Aortic aneurysm and dissection 576
Congenital malformations, deformations and chromosomal abnormalities 402
Atherosclerosis 306
Human immunodeficiency virus (HIV) disease 298
Anemias 249

Statistical Analysis

# NYC summary level descriptive statistics: the mean, median, 25th and 75th
# quartiles, min, and max for each of the applicable variables in your data set 
summary(nyc_df)
##                                                             Cause    
##  Major cardiovascular diseases (I00-I78)                       : 67  
##  Diseases of heart (I00-I09,I11,I13,I20-I51)                   : 66  
##  Other heart diseases (I26-I51)                                : 61  
##  All other forms of heart disease (I26-I28,I34-I38,I42-I49,I51): 60  
##  All other diseases (Residual)                                 : 49  
##  Ischemic heart diseases (I20-I25)                             : 49  
##  (Other)                                                       :662  
##                  County     County_Code    Gender 
##  Bronx County, NY   :323   Min.   :36005   F:462  
##  Kings County, NY   :263   1st Qu.:36005   M:552  
##  New York County, NY:238   Median :36047          
##  Queens County, NY  :161   Mean   :36043          
##  Richmond County, NY: 29   3rd Qu.:36061          
##                            Max.   :36085          
##                                                   
##                         Race              Age          Deaths      
##  Black or African American: 55   75-84 years:229   Min.   : 10.00  
##  White                    :959   65-74 years:202   1st Qu.: 14.00  
##                                  85+ years  :184   Median : 21.00  
##                                  55-64 years:167   Mean   : 40.16  
##                                  45-54 years:132   3rd Qu.: 48.00  
##                                  35-44 years: 63   Max.   :280.00  
##                                  (Other)    : 37
# NYS summary level descriptive statistics: the mean, median, 25th and 75th
# quartiles, min, and max for each of the applicable variables in your data set 
summary(nys_df)
##                                                             Cause    
##  Major cardiovascular diseases (I00-I78)                       :102  
##  Diseases of heart (I00-I09,I11,I13,I20-I51)                   : 99  
##  Other heart diseases (I26-I51)                                : 92  
##  All other forms of heart disease (I26-I28,I34-I38,I42-I49,I51): 89  
##  Ischemic heart diseases (I20-I25)                             : 59  
##  All other diseases (Residual)                                 : 57  
##  (Other)                                                       :694  
##                     County     County_Code    Gender 
##  Bronx County, NY      :323   Min.   :36005   F:549  
##  Kings County, NY      :263   1st Qu.:36005   M:643  
##  New York County, NY   :238   Median :36059          
##  Queens County, NY     :161   Mean   :36051          
##  Suffolk County, NY    : 60   3rd Qu.:36081          
##  Westchester County, NY: 52   Max.   :36119          
##  (Other)               : 95                          
##                         Race               Age          Deaths      
##  Black or African American:  55   75-84 years:276   Min.   : 10.00  
##  White                    :1137   65-74 years:233   1st Qu.: 13.00  
##                                   85+ years  :232   Median : 20.00  
##                                   55-64 years:195   Mean   : 36.86  
##                                   45-54 years:144   3rd Qu.: 41.00  
##                                   35-44 years: 71   Max.   :280.00  
##                                   (Other)    : 41
# Chicago summary level descriptive statistics: the mean, median, 25th and 75th
# quartiles, min, and max for each of the applicable variables in your data set 
summary(chicago_df)
##                                                    Cause    
##  #Malignant neoplasms (C00-C97)                       : 39  
##  Major cardiovascular diseases (I00-I78)              : 37  
##  #Diseases of heart (I00-I09,I11,I13,I20-I51)         : 36  
##  #Accidents (unintentional injuries) (V01-X59,Y85-Y86): 30  
##  Ischemic heart diseases (I20-I25)                    : 30  
##  All other diseases (Residual)                        : 29  
##  (Other)                                              :870  
##       State        State_Code Gender                         Race    
##  Illinois:1071   Min.   :17   F:492   Asian or Pacific Islander: 48  
##                  1st Qu.:17   M:579   Black or African American:430  
##                  Median :17           White                    :593  
##                  Mean   :17                                          
##                  3rd Qu.:17                                          
##                  Max.   :17                                          
##                                                                      
##           Age          Deaths       
##  75-84 years:220   Min.   :  10.00  
##  85+ years  :185   1st Qu.:  17.00  
##  65-74 years:184   Median :  33.00  
##  55-64 years:176   Mean   :  85.88  
##  45-54 years:145   3rd Qu.:  75.00  
##  35-44 years: 77   Max.   :2754.00  
##  (Other)    : 84
# Illinois summary level descriptive statistics: the mean, median, 25th and 75th
# quartiles, min, and max for each of the applicable variables in your data set 
summary(illinois_df)
##                                                      Cause     
##  Major cardiovascular diseases (I00-I78)                : 479  
##  #Malignant neoplasms (C00-C97)                         : 407  
##  #Diseases of heart (I00-I09,I11,I13,I20-I51)           : 394  
##  Ischemic heart diseases (I20-I25)                      : 256  
##  All other diseases (Residual)                          : 168  
##  Other forms of chronic ischemic heart disease (I20,I25): 161  
##  (Other)                                                :2072  
##                   County      County_Code    Gender  
##  Cook County, IL     :1071   Min.   :17001   F:1942  
##  DuPage County, IL   : 240   1st Qu.:17031   M:1995  
##  Will County, IL     : 188   Median :17091           
##  Lake County, IL     : 182   Mean   :17093           
##  Madison County, IL  : 134   3rd Qu.:17143           
##  St. Clair County, IL: 134   Max.   :17203           
##  (Other)             :1988                           
##                         Race               Age           Deaths       
##  Asian or Pacific Islander:  50   85+ years  :1236   Min.   :  10.00  
##  Black or African American: 490   75-84 years:1111   1st Qu.:  13.00  
##  White                    :3397   65-74 years: 645   Median :  19.00  
##                                   55-64 years: 443   Mean   :  42.56  
##                                   45-54 years: 280   3rd Qu.:  36.00  
##                                   35-44 years: 101   Max.   :2754.00  
##                                   (Other)    : 121
# USA Female summary level descriptive statistics: the mean, median, 25th and 75th
# quartiles, min, and max for each of the applicable variables in your data set 
summary(usf_df)
##                                                             Cause     
##  Major cardiovascular diseases (I00-I78)                       :  90  
##  Diseases of heart (I00-I09,I11,I13,I20-I51)                   :  79  
##  All other diseases (Residual)                                 :  74  
##  Other heart diseases (I26-I51)                                :  69  
##  Malignant neoplasms (C00-C97)                                 :  65  
##  All other forms of heart disease (I26-I28,I34-I38,I42-I49,I51):  62  
##  (Other)                                                       :1339  
##         State       State_Code      Gender       
##  California:448   Min.   : 4.00   Mode :logical  
##  Texas     :303   1st Qu.: 6.00   FALSE:1778     
##  New York  :275   Median :12.00   NA's :0        
##  Florida   :265   Mean   :22.52                  
##  Arizona   :123   3rd Qu.:36.00                  
##  Illinois  :111   Max.   :55.00                  
##  (Other)   :253                                  
##                                Race               Age     
##  American Indian or Alaska Native:   1   75-84 years:380  
##  Black or African American       :  56   85+ years  :338  
##  White                           :1721   65-74 years:319  
##                                          55-64 years:257  
##                                          45-54 years:194  
##                                          35-44 years:104  
##                                          (Other)    :186  
##      Deaths       
##  Min.   :  10.00  
##  1st Qu.:  15.00  
##  Median :  26.00  
##  Mean   :  82.19  
##  3rd Qu.:  60.00  
##  Max.   :2157.00  
## 
# USA Male summary level descriptive statistics: the mean, median, 25th and 75th
# quartiles, min, and max for each of the applicable variables in your data set 
summary(usm_df)
##                                                             Cause     
##  Major cardiovascular diseases (I00-I78)                       : 111  
##  Diseases of heart (I00-I09,I11,I13,I20-I51)                   :  98  
##  All other non causes of death                                 :  96  
##  All other diseases (Residual)                                 :  91  
##  Other heart diseases (I26-I51)                                :  76  
##  All other forms of heart disease (I26-I28,I34-I38,I42-I49,I51):  70  
##  (Other)                                                       :1758  
##         State       State_Code    Gender  
##  California:529   Min.   : 4.00   M:2300  
##  Texas     :366   1st Qu.: 6.00           
##  Florida   :345   Median :17.00           
##  New York  :316   Mean   :22.46           
##  Arizona   :185   3rd Qu.:36.00           
##  Illinois  :161   Max.   :55.00           
##  (Other)   :398                           
##                         Race               Age          Deaths       
##  Black or African American:  49   75-84 years:389   Min.   :  10.00  
##  White                    :2251   65-74 years:383   1st Qu.:  15.00  
##                                   55-64 years:353   Median :  27.00  
##                                   45-54 years:308   Mean   :  75.22  
##                                   85+ years  :275   3rd Qu.:  65.25  
##                                   35-44 years:214   Max.   :1732.00  
##                                   (Other)    :378

Graphical Analysis

## geom_smooth: Only one unique x value each group.Maybe you want aes(group = 1)?

## geom_smooth: Only one unique x value each group.Maybe you want aes(group = 1)?

## geom_smooth: Only one unique x value each group.Maybe you want aes(group = 1)?

Geographic Analysis

The Leading Cause of Deaths in New York State by County

The Leading Cause of Deaths in Illinois State by County

The Leading Cause of Male Deaths in the US by County

The Leading Cause of Female Deaths in the US by State

Final Graphics

## Warning: package 'scatterplot3d' was built under R version 3.1.3