title: “TITANIC” author: “Krushali Shah” date: “January 5, 2018” output: html_document This is a R markdown document of the passengers in the Titanic.

setwd("C:/Users/Dell/Downloads/Sameer Mathur")
titanic.df<-read.csv("Titanic Data.csv")
View(titanic.df)

The total number of passengers on board the Titanic.

dim(titanic.df)
## [1] 889   8

The number of passengers and the percentage of passengers who survived the sinking of the Titanic.

mytable<-with(titanic.df,table(Survived))
mytable
## Survived
##   0   1 
## 549 340
prop.table(mytable)*100
## Survived
##        0        1 
## 61.75478 38.24522

The number of first-class passengers and the percentage of first-class passengers who survived the sinking of the Titanic.

mytable<- xtabs(~Pclass + Survived, data = titanic.df)
mytable
##       Survived
## Pclass   0   1
##      1  80 134
##      2  97  87
##      3 372 119
prop.table(mytable,1)*100
##       Survived
## Pclass        0        1
##      1 37.38318 62.61682
##      2 52.71739 47.28261
##      3 75.76375 24.23625

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

mytable<- xtabs(~Sex + Pclass + Survived, data = titanic.df)
ftable(mytable)
##               Survived   0   1
## Sex    Pclass                 
## female 1                 3  89
##        2                 6  70
##        3                72  72
## male   1                77  45
##        2                91  17
##        3               300  47

The percentage of survivors who were female.

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

The percentage of females on board the Titanic who survived.

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

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.

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