setwd("C:/Users/RRD/Downloads")
titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
length(titanic.df$Survived)
## [1] 889
From here we can see that 899 pessangers on borded the Titanic.
SURVIVED <- with(titanic.df, table(Survived))
SURVIVED
## Survived
## 0 1
## 549 340
340 passengers survived the sinking of the Titanic #Survival {0 = No, 1 = Yes}
prop.table(SURVIVED)*100
## Survived
## 0 1
## 61.75478 38.24522
38.24522% of the passengers survived the sinking of the Titanic
SURVIVED <- xtabs(~ Survived+Pclass, data=titanic.df)
SURVIVED
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
134 first-class passengers survived the sinking of the Titanic
SURVived1<-prop.table(SURVIVED)*100
SURVived1
## Pclass
## Survived 1 2 3
## 0 8.998875 10.911136 41.844769
## 1 15.073116 9.786277 13.385827
62.61682% of first-class passengers survived the sinking of the Titanic.
SURVived2 <- xtabs(~ Survived+Pclass+Sex, data=titanic.df)
SURVived2
## , , 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
89 females from first class survived the sinking of the Titanic
survived3 <- xtabs(~ Survived+Pclass+Sex, data=titanic.df)
survived3
## , , 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
prop.table(survived3,1)*100
## , , Sex = female
##
## Pclass
## Survived 1 2 3
## 0 0.5464481 1.0928962 13.1147541
## 1 26.1764706 20.5882353 21.1764706
##
## , , Sex = male
##
## Pclass
## Survived 1 2 3
## 0 14.0255009 16.5755920 54.6448087
## 1 13.2352941 5.0000000 13.8235294
67.94118% of the survivors were females
survived4 <- xtabs(~ Survived+Pclass+Sex, data=titanic.df)
survived4
## , , 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
prop.table(survived4,2)*100
## , , Sex = female
##
## Pclass
## Survived 1 2 3
## 0 1.401869 3.260870 14.663951
## 1 41.588785 38.043478 14.663951
##
## , , Sex = male
##
## Pclass
## Survived 1 2 3
## 0 35.981308 49.456522 61.099796
## 1 21.028037 9.239130 9.572301
The percentage of females on board the Titanic who survived was 74.03846%
survived5 <- xtabs(~ Survived+Sex, data=titanic.df)
survived5
## Sex
## Survived female male
## 0 81 468
## 1 231 109
chisq.test(survived5)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: survived5
## X-squared = 258.43, df = 1, p-value < 2.2e-16
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.