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/Dell/Desktop/Project/Week 1/Day 5/Task 2 (Titanic)")
titanic.df=read.csv("Titanic Data.csv")
View(titanic.df)
titanic.df$index=1
sum(titanic.df$index)
## [1] 889
prop.table(xtabs(~Survived, titanic.df),margin=NULL)
## Survived
## 0 1
## 0.6175478 0.3824522
library(datasets)
m=xtabs(~Survived+Pclass, titanic.df)
m[2,1]
## [1] 134
prop.table(m[,1],margin=NULL)
## 0 1
## 0.3738318 0.6261682
n=xtabs(~Survived+Sex+Pclass,titanic.df)
n[2,1,1]
## [1] 89
p=xtabs(~Survived+Sex,titanic.df)
prop.table(p[2,],margin=NULL)
## female male
## 0.6794118 0.3205882
prop.table(p[,1],margin=NULL)
## 0 1
## 0.2596154 0.7403846
The following hypothesis is to be tested: 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.
q=table(titanic.df$Survived,titanic.df$Sex)
chisq.test(q)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: q
## X-squared = 258.43, df = 1, p-value < 2.2e-16
Since p-value is less than 0.05, the null hypothesis of the proportion of females onboard who survived the sinking of the Titanic being lower than the proportion of males onboard who survived the sinking of the Titanic is rejected. Thus, it is proved 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.