Analysis of the Titanic Dataset.

3a)Total number of passengers on board the Titanic:

length(titanic$Survived)
## [1] 889

3b)Total number of passengers who survived the sinking of the Titanic:

length(titanic$Survived[titanic$Survived==1])
## [1] 340

3c)Percentage of passengers who survived the sinking of the Titanic:

length(titanic$Survived[titanic$Survived==1])/length(titanic$Survived)*100
## [1] 38.24522

3d)Number of first-class passengers who survived the sinking of the Titanic:

tab1<-xtabs(~Survived+Pclass, data=titanic)
addmargins(tab1)
##         Pclass
## Survived   1   2   3 Sum
##      0    80  97 372 549
##      1   134  87 119 340
##      Sum 214 184 491 889
tab1[2]
## [1] 134

3e)Percentage of first-class passengers who survived the sinking of the Titanic:

prop.table(tab1)[2]*100
## [1] 15.07312

3f)Number of females from First-Class who survived the sinking of the Titanic:

tab2<-xtabs(~Survived+Pclass+Sex, data=titanic)
addmargins(tab2)
## , , Sex = female
## 
##         Pclass
## Survived   1   2   3 Sum
##      0     3   6  72  81
##      1    89  70  72 231
##      Sum  92  76 144 312
## 
## , , Sex = male
## 
##         Pclass
## Survived   1   2   3 Sum
##      0    77  91 300 468
##      1    45  17  47 109
##      Sum 122 108 347 577
## 
## , , Sex = Sum
## 
##         Pclass
## Survived   1   2   3 Sum
##      0    80  97 372 549
##      1   134  87 119 340
##      Sum 214 184 491 889
tab2[2]
## [1] 89

3g)Percentage of survivors who were female:

tab3<-xtabs(~Survived+Sex, data=titanic)
addmargins(tab3)
##         Sex
## Survived female male Sum
##      0       81  468 549
##      1      231  109 340
##      Sum    312  577 889
prop.table(tab3)[2]*100
## [1] 25.98425

3h)Percentage of females on board the Titanic who survived

tab4<-xtabs(~Sex+Survived, data=titanic)
addmargins(tab4)
##         Survived
## Sex        0   1 Sum
##   female  81 231 312
##   male   468 109 577
##   Sum    549 340 889
prop.table(tab4)[3]*100
## [1] 25.98425

3i)Hypothesis: The proportion of females onboard who survived the sinking of the Titanic was higher than the proportion of males onboard who survived the sinking of the Titanic.

Pearson’s Chi-squared test to test the hypothesis:

chisq.test(tab3)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tab3
## X-squared = 258.43, df = 1, p-value < 2.2e-16

We observe that- since the p-value is <0.05, there is a relationship between Sex and Survival of people onboard the Titanic.Thus the null hypothesis is rejected.