This is a case study on the sinking of the Titanic ship.
Reading and Viewing the Titanic Database
setwd("D:/desktop/Data Analytics internship-sameer mathur/work/datasets")
titanic.df<-read.csv(paste("Titanic Data.csv", sep=""))
View(titanic.df)
3a: Number of passengers on board
length(titanic.df$Survived)
## [1] 889
There were 889 passengers on board the Titanic.
3b: the number of passengers who survived the sinking of the Titanic
with(titanic.df, table(Survived))
## Survived
## 0 1
## 549 340
340 passengers survived the sinking of the Titanic.
3c: the percentage of passengers who survived the sinking of the Titanic
with(titanic.df, prop.table(table(Survived))*100)
## Survived
## 0 1
## 61.75478 38.24522
Only 38.24522% of the passengers survived and the rest 61.75478% died.
3d: the number of first-class passengers who survived the sinking of the Titanic
mytable <- xtabs(~ Survived+Pclass, data=titanic.df)
mytable
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
134 first class passengers survived.
3e: the percentage of first-class passengers who survived the sinking of the Titanic
prop.table(mytable)*100
## Pclass
## Survived 1 2 3
## 0 8.998875 10.911136 41.844769
## 1 15.073116 9.786277 13.385827
Of the total no. of passengers who were on board, the percentage of first class passengers who survived is 15.073116%.
3f: the number of females from First-Class who survived the sinking of the Titanic
mytable <- xtabs(~ Survived+Pclass+Sex, data=titanic.df)
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
The number of females from First-Class who survived the sinking of the Titanic is 89.
3g: the percentage of survivors who were female
mytable <- xtabs(~ Survived+Sex, data=titanic.df)
mytable
## Sex
## Survived female male
## 0 81 468
## 1 231 109
prop.table(mytable,1)*100
## Sex
## Survived female male
## 0 14.75410 85.24590
## 1 67.94118 32.05882
The total numberr of female survivors is 231 and it is 67.94118% of the total survivors.
3h: the percentage of females on board the Titanic who survived
prop.table(mytable,2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
The percentage of females on board the Titanic who survived is 74.03846%.
Hypothesis: 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.
mytable <- xtabs(~ Sex+Survived, data=titanic.df)
mytable
## Survived
## Sex 0 1
## female 81 231
## male 468 109
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
Since the p-value is vey small(<0.01), we reject the Null hypothesis.