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.
setwd("C:/Users/admin/Downloads")
titanic.df <- read.csv(paste("Titanic Data.csv",sep=""))
View(titanic.df)
By creating the data frame we can view the data with the variable like Survived,Pclass,Sex,Age,SibSp,Parch,Fare,Embarked.
mytable <- with( titanic.df,table(Sex))
addmargins(mytable)
## Sex
## female male Sum
## 312 577 889
This output shows there are 889 passenger in titanic.
mytable1 <- xtabs(~Sex+Survived,data = titanic.df)
addmargins(mytable1)
## Survived
## Sex 0 1 Sum
## female 81 231 312
## male 468 109 577
## Sum 549 340 889
This shows that out of 312 female passengers only 231 survives and out of 577 male passengers only 109 survives.We can clearly come to the judgement that male passengers death rate is higher than the female.
prop.table(mytable1)*100
## Survived
## Sex 0 1
## female 9.111361 25.984252
## male 52.643420 12.260967
Out of 100 percentage only 25 percent of female and 12 percent of male survives.
mytable2 <- xtabs(~Pclass+Survived,data = titanic.df)
addmargins(mytable2)
## Survived
## Pclass 0 1 Sum
## 1 80 134 214
## 2 97 87 184
## 3 372 119 491
## Sum 549 340 889
mytable2[Survived = '1', Pclass='1']
## [1] 134
Output shows out of 214 first class passengers 80 died and 134 survives.
prop.table(mytable2)*100
## Survived
## Pclass 0 1
## 1 8.998875 15.073116
## 2 10.911136 9.786277
## 3 41.844769 13.385827
Comparing all classes of passengers only 15 percent of first class passenger survives.
mytable3 <- xtabs(~Sex+Pclass+Survived,data = titanic.df)
mytable3
## , , Survived = 0
##
## Pclass
## Sex 1 2 3
## female 3 6 72
## male 77 91 300
##
## , , Survived = 1
##
## Pclass
## Sex 1 2 3
## female 89 70 72
## male 45 17 47
Output depicts that 89 females of first class passengers survives and 3 females died.
mytable4 <- xtabs(~Sex+Survived,data = titanic.df)
prop.table(mytable4)*100
## Survived
## Sex 0 1
## female 9.111361 25.984252
## male 52.643420 12.260967
Out of cent percent of passengers almost 26 percent of female passengers survives.
chisq.test(mytable4)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mytable4
## X-squared = 258.43, df = 1, p-value < 2.2e-16
Since,the value of p is below the level of sinificance(0.05) we can reject null hypothesis. We can conclude that 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.