Sinking of the RMS Titanic

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.

  1. Reading data given in CSV format file into R
setwd("C:/Users/Dell/Desktop/Project/Week 1/Day 5/Task 2 (Titanic)")
titanic.df=read.csv("Titanic Data.csv")
View(titanic.df)
  1. Calculating the total numbers of passengers
titanic.df$index=1
sum(titanic.df$index)
## [1] 889
  1. Calculating the percentage of people who survived
prop.table(xtabs(~Survived, titanic.df),margin=NULL)
## Survived
##         0         1 
## 0.6175478 0.3824522
  1. Counting the number of first-class passengers who survived
library(datasets)
m=xtabs(~Survived+Pclass, titanic.df)
m[2,1]
## [1] 134
  1. Measuring the percentage of first-class passengers who survived
prop.table(m[,1],margin=NULL)
##         0         1 
## 0.3738318 0.6261682
  1. Counting the number of females from first-Class who survived
n=xtabs(~Survived+Sex+Pclass,titanic.df)
n[2,1,1]
## [1] 89
  1. Measuring the percentage of survivors who were female
p=xtabs(~Survived+Sex,titanic.df)
prop.table(p[2,],margin=NULL)
##    female      male 
## 0.6794118 0.3205882
  1. Measuring the percentage of females on board the Titanic who survived
prop.table(p[,1],margin=NULL)
##         0         1 
## 0.2596154 0.7403846

Pearson’s Chi-squared test

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.