Task2b: Read the Titanic data set into R. Create a dataframe called “titanic”.

titanic.df <-read.csv(paste("Titanic Data.csv",sep=""))
View(titanic.df)

Task3a: Count the total number of passengers on board the Titanic

nrow(titanic.df)
## [1] 889

Total number of passengers who boarded the ship are 889.

Task3b: Count the number of passengers who survived the sinking of the Titanic

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

The number of passengers who survived the sinking of Titanic are 340

Task3c: The percentage of passengers who survived the sinking of the Titanic

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

The percentage of passengers who survived are 38.24%

Task3d:Count the number of first-class passengers who survived the sinking of the Titanic

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

The number of first-class passengers who survived the sinking of the Titanic are 134

Task3e:The percentage of first-class passengers who survived the sinking of the Titanic

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

The percentage of passengers of first-class who survived the sinking of titanic is 62.61%

Tak3f: Count the number of females from First-Class who survived the sinking of the Titanic

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

Task3g: The percentage of survivors who were female

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

The percentage of survivors who were female is 67.94%

Task3h: The percentage of females on board the Titanic who survived

prop.table(info,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.03%

Task3i:Run 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.

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