Titanic Data Analysis
To find out the number of passengers on titanic
table(titanic$Sex)
##
## female male
## 312 577
Total Passengers are Male + Female, 889
Finding No. of passengers who survived
table(titanic$Survived)
##
## 0 1
## 549 340
340 Passengers Survived
Percentage of passengers survived
mytable <- xtabs(~ Survived + Sex, data=titanic)
mytable
## Sex
## Survived female male
## 0 81 468
## 1 231 109
addmargins(prop.table(mytable))
## Sex
## Survived female male Sum
## 0 0.09111361 0.52643420 0.61754781
## 1 0.25984252 0.12260967 0.38245219
## Sum 0.35095613 0.64904387 1.00000000
38.24% passengers survived
No. of First Class passengers who survived
mytable <- xtabs(~Survived + Pclass, data=titanic)
mytable
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
134 passengers from first class survived
Percentage of first-class passengers who survived
addmargins(prop.table(mytable))
## Pclass
## Survived 1 2 3 Sum
## 0 0.08998875 0.10911136 0.41844769 0.61754781
## 1 0.15073116 0.09786277 0.13385827 0.38245219
## Sum 0.24071991 0.20697413 0.55230596 1.00000000
15.07% of survivors were first-class passengers
No. of females from first class passengers who survived
mytable <- xtabs(~ Pclass + Sex + Survived, data=titanic)
ftable(mytable)
## Survived 0 1
## Pclass Sex
## 1 female 3 89
## male 77 45
## 2 female 6 70
## male 91 17
## 3 female 72 72
## male 300 47
89 females from first class survived
Percentage of survivors who were females
mytable <- xtabs(~ Sex + Survived, data=titanic)
mytable
## Survived
## Sex 0 1
## female 81 231
## male 468 109
addmargins(prop.table(mytable,2))
## Survived
## Sex 0 1 Sum
## female 0.1475410 0.6794118 0.8269527
## male 0.8524590 0.3205882 1.1730473
## Sum 1.0000000 1.0000000 2.0000000
67.94% of survivors were females
Percentage of females on board who survived
addmargins(prop.table(mytable,1))
## Survived
## Sex 0 1 Sum
## female 0.2596154 0.7403846 1.0000000
## male 0.8110919 0.1889081 1.0000000
## Sum 1.0707072 0.9292928 2.0000000
74.03% of females on board of Titanic survived
Chi-Square test to check the hypothesis
chisq.test(titanic$Sex, titanic$Survived)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: titanic$Sex and titanic$Survived
## X-squared = 258.43, df = 1, p-value < 2.2e-16
pvalue is less than 0.05. Therefore, the Null hypothesis that Sex and Survival are independent