The sinking of the RMS Titanic occurred on the night of 14 April through to the morning of 15 April 1912 in the North Atlantic Ocean, four days into the ship’s maiden voyage from Southampton to New York City. The largest passenger liner in service at the time, Titanic had an estimated 2,224 people on board when she struck an iceberg at around 23:40 (ship’s time) on Sunday, 14 April 1912. Her sinking two hours and forty minutes later at 02:20 (05:18 GMT) on Monday, 15 April resulted in the deaths of more than 1,500 people, which made it one of the deadliest peacetime maritime disasters in history.
titanic.df<-read.csv(paste("Titanic Data.csv",sep=""))
View(titanic.df)
Determine the total number of passengers aboard the Titanic
titanic.df<-read.csv(paste("Titanic Data.csv",sep=""))
nrow(titanic.df) #Total No. of passengers aboard
## [1] 889
The total number of passengers aboard the Titanic is 889.
table(titanic.df$Survived) #Total No. of passengers survived
##
## 0 1
## 549 340
The total number of passengers surviving the sinking of the Titanic is 340.
mytable<- with(titanic.df,table(Survived)) #Table of passengers surviving
prop.table(mytable)*100 #Percent of passengers surviving
## Survived
## 0 1
## 61.75478 38.24522
The % of passengers surviving the sinking of the Titanic is 38.24522.
mytable <- xtabs(~Survived + Pclass, data=titanic.df) #No. of first class passengers surviving
mytable
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
prop.table(mytable,2)*100 #% of first class passengers surviving
## Pclass
## Survived 1 2 3
## 0 37.38318 52.71739 75.76375
## 1 62.61682 47.28261 24.23625
The number of first class passengers who survived is 134. The % of first class passengers who survived is 62.61682.
mytable <- xtabs(~Survived + Pclass + Sex, data=titanic.df) #No. of first class female passengers surviving
mytable
## , , Sex = female
##
## Pclass
## Survived 1 2 3
## 0 3 6 72
## 1 89 70 72
##
## , , Sex = male
##
## Pclass
## Survived 1 2 3
## 0 77 91 300
## 1 45 17 47
mytable<-xtabs(~Survived+Sex, data=titanic.df)#% of females passengers surviving
prop.table(mytable,2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
The number of first class female passengers surviving is 89. The % of female passengers on board who survived is 74.03846.
mytable <- xtabs(~Survived + Sex, data=titanic.df) #No. of female passengers surviving
chisq.test(mytable)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mytable
## X-squared = 258.43, df = 1, p-value < 2.2e-16
The p value for the Pearson’s Chi-squared test is 2.2 e-16, which is <0.05. So, we can reject our null hypothesis that the sex of a person and his/her survival are independent of each other.
The proportion of females on board who survived the sinking of the Titanic was higher than the proportion of males on board who survived the sinking of the Titanic.