Titanic dataset reading

setwd("C:/Users/Jaswanth/Downloads")
titanic.df<-read.csv(paste("Titanic Data.csv",sep = ""))
View(titanic.df)

Number of passengers on the titanic

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

889

Number of passengers who survived

sum(titanic.df$Survived[titanic.df$Survived==1])
## [1] 340

Percentage of passengers who survived

titanictable<-table(titanic.df$Survived)
titanictable
## 
##   0   1 
## 549 340
prop.table(titanictable)*100
## 
##        0        1 
## 61.75478 38.24522

Number of first class passengers who survived the sinking

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

Percentage of first class passengers who survived the sinking

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

Number of female first class passengers who survived the sinking

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

Percentage of survivors who were female

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

Percentage of female who survived

female
##         Sex
## Survived female male
##        0     81  468
##        1    231  109
prop.table(female,2)*100
##         Sex
## Survived   female     male
##        0 25.96154 81.10919
##        1 74.03846 18.89081

Chi square test

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

p value is lesser so hence dependent