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/Shreyas Jadhav/Downloads")
titanic <- read.csv(paste("Titanic Data.csv",sep="."))
View(titanic)
summary(titanic)
## Survived Pclass Sex Age
## Min. :0.0000 Min. :1.000 female:312 Min. : 0.40
## 1st Qu.:0.0000 1st Qu.:2.000 male :577 1st Qu.:22.00
## Median :0.0000 Median :3.000 Median :29.70
## Mean :0.3825 Mean :2.312 Mean :29.65
## 3rd Qu.:1.0000 3rd Qu.:3.000 3rd Qu.:35.00
## Max. :1.0000 Max. :3.000 Max. :80.00
## SibSp Parch Fare Embarked
## Min. :0.0000 Min. :0.0000 Min. : 0.000 C:168
## 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.: 7.896 Q: 77
## Median :0.0000 Median :0.0000 Median : 14.454 S:644
## Mean :0.5242 Mean :0.3825 Mean : 32.097
## 3rd Qu.:1.0000 3rd Qu.:0.0000 3rd Qu.: 31.000
## Max. :8.0000 Max. :6.0000 Max. :512.329
dim(titanic)
## [1] 889 8
Therefore, there were 889 passengers on board.
table(titanic$Survived==1)
##
## FALSE TRUE
## 549 340
Therefore, 340 passengers survived the sinking of the titanic.
mytable <- with(titanic, table(Survived))
prop.table(mytable)*100
## Survived
## 0 1
## 61.75478 38.24522
Therefore, 38.24522% of the passengers survived.
mytable1 <- xtabs(~ Pclass + Survived,data=titanic)
mytable1
## Survived
## Pclass 0 1
## 1 80 134
## 2 97 87
## 3 372 119
Therefore, 134 first class passengers survived.
prop.table(mytable1,1)*100
## Survived
## Pclass 0 1
## 1 37.38318 62.61682
## 2 52.71739 47.28261
## 3 75.76375 24.23625
Therefore, 62.61682% of first class passengers survived.
mytable2 <- xtabs(~ Sex + Survived + Pclass,data=titanic)
ftable(mytable2)
## Pclass 1 2 3
## Sex Survived
## female 0 3 6 72
## 1 89 70 72
## male 0 77 91 300
## 1 45 17 47
Therefore, 89 first class female passengers survived.
mytable2<-xtabs(~ Survived + Sex,data=titanic)
prop.table(mytable2,1)*100
## Sex
## Survived female male
## 0 14.75410 85.24590
## 1 67.94118 32.05882
Therefore, 67.94118% of survivors were female.
prop.table(mytable2,2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
Therefore, 74.03846% of female passengers survived.
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.
chisq.test(mytable2)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mytable2
## X-squared = 258.43, df = 1, p-value < 2.2e-16
Therefore value of p is < 2.2e-16 i.e p < 0.05.