Importing Dataset.

titanic=read.csv('Titanic Data.csv')

Viewing Dataset.

View(titanic)

Counting the total number of passengers on board the Titanic.

First entry of output will give required answer.

dim(titanic)
## [1] 889   8

Counting the number of passengers who survived the sinking of the Titanic.

mytable <- with(titanic, table(Survived))
mytable
## Survived
##   0   1 
## 549 340

Measuring the percentage of passengers who survived the sinking of the Titanic.

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

Counting the number of first-class passengers who survived the sinking of the Titanic.

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

Measuring the percentage of first-class passengers who survived the sinking of the Titanic.

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

Counting the number of females from First-Class who survived the sinking of the Titanic.

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

Measuring the percentage of survivors who were female.

mytable <- xtabs(~ Survived + Sex, data=titanic)
prop.table(mytable, 1)*100
##         Sex
## Survived   female     male
##        0 14.75410 85.24590
##        1 67.94118 32.05882

Measuring 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

Runing a 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.

mytable <- xtabs(~ Survived + Sex, data=titanic)
addmargins(mytable)
##         Sex
## Survived female male Sum
##      0       81  468 549
##      1      231  109 340
##      Sum    312  577 889
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