TITANIC CASE STUDY

This is an R Markdown document which describes the analysis of the Titanic case study

 setwd("F:/FOR DA INTERN/TASKS/WEEK 1/D5")
 titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))

a.Total number of passengers on board the Titanic

 length(titanic.df$Survived)
## [1] 889

Thus there were 899 passengers on board the Titanic

b.Number of passengers who survived the sinking of the Titanic

 table(titanic.df$Survived)
## 
##   0   1 
## 549 340

Thus 340 passengers survived the sinking of the Titanic

table1 <- with(titanic.df, table(Survived))
table1
## Survived
##   0   1 
## 549 340

c.Percentage of passengers who survived the sinking of the Titanic

 prop.table(table1)*100
## Survived
##        0        1 
## 61.75478 38.24522

Thus 38.24522% of the passengers survived the sinking of the Titanic

d.Number of first-class passengers who survived the sinking of the Titanic

 table1 <- xtabs(~ Survived+Pclass, data=titanic.df)
 table1
##         Pclass
## Survived   1   2   3
##        0  80  97 372
##        1 134  87 119

Thus 134 first-class passengers survived the sinking of the Titanic

e.Percentage of first-class passengers who survived the sinking of the Titanic

  prop.table(table1,2)*100
##         Pclass
## Survived        1        2        3
##        0 37.38318 52.71739 75.76375
##        1 62.61682 47.28261 24.23625

Thus 62.61682% of first-class passengers survived the sinking of the Titanic

f.Number of females from First-Class who survived the sinking of the Titanic

 table1 <- xtabs(~ Survived+Pclass+Sex, data=titanic.df)
 table1
## , , 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

Thus the number of females from First-Class who survived the sinking of the Titanic was 89

g.Percentage of survivors who were females

 table1 <- xtabs(~ Survived+Sex, data=titanic.df)
 table1
##         Sex
## Survived female male
##        0     81  468
##        1    231  109
 prop.table(table1,1)*100
##         Sex
## Survived   female     male
##        0 14.75410 85.24590
##        1 67.94118 32.05882

Thus 67.94118% of the survivors were females

h.Percentage of females on board the Titanic who survived

 table1 <- xtabs(~ Survived+Sex, data=titanic.df)
 prop.table(table1,2)*100
##         Sex
## Survived   female     male
##        0 25.96154 81.10919
##        1 74.03846 18.89081

Thus the percentage of females on board the Titanic who survived was 74.03846%

i.Pearson’s Chi-squared test to test the following hypothesis:

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.

 table2 <- xtabs(~Sex+Survived, data=titanic.df)
 table2
##         Survived
## Sex        0   1
##   female  81 231
##   male   468 109
chisq.test(table2)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  table2
## X-squared = 258.43, df = 1, p-value < 2.2e-16

Thus from the Chi-squared test, we see that the value of p is lesser than 0.01 which suggests that we have to reject the null hypothesis