length(Titanic.df$Survived)
## [1] 889
length(which(Titanic.df$Survived=="1"))
## [1] 340
num <- length(which(Titanic.df$Survived=="1"))
denominator <- length(Titanic.df$Survived)
(num/denominator)*100
## [1] 38.24522
mytable <- xtabs(~ Pclass+Survived, data = Titanic.df)
mytable[1,2]
## [1] 134
hello1 <- prop.table(mytable)*100
hello1[1,2]
## [1] 15.07312
hello2 <- xtabs(~ Pclass+Survived+Sex, data = Titanic.df)
hello2
## , , Sex = female
##
## Survived
## Pclass 0 1
## 1 3 89
## 2 6 70
## 3 72 72
##
## , , Sex = male
##
## Survived
## Pclass 0 1
## 1 77 45
## 2 91 17
## 3 300 47
89
## [1] 89
Total survivors who were female / Total Survivors
hello3 <- xtabs(~ Survived+Sex, data = Titanic.df)
hello3
## Sex
## Survived female male
## 0 81 468
## 1 231 109
hello3[2,1]/length(which(Titanic.df$Survived=="1"))*100
## [1] 67.94118
Total survivors who were female / Total Females
hello4 <- xtabs(~ Sex+Survived, data = Titanic.df)
hello4
## Survived
## Sex 0 1
## female 81 231
## male 468 109
hello4[1,2]/length(which(Titanic.df$Sex=="female"))*100
## [1] 74.03846
Running a chi squared test.
mytable4 <- xtabs(~ Survived+Sex, data=Titanic.df)
chisq.test(mytable4)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mytable4
## X-squared = 258.43, df = 1, p-value < 2.2e-16
There is no relationship between the two parameters as they are independent since pvalue is <0.05. Hence, the null hypothesis is rejected that proportion of female survivors is greater than male survivors.