titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
View(titanic.df)
dim(titanic.df)
## [1] 889 8
We can see the total number of passengers is 889 as it is the number of rows in the datasheet.
table(titanic.df$Survived)
##
## 0 1
## 549 340
We can see that 340 passengers survived the sinking of the titanic
prop.table(table(titanic.df$Survived))*100
##
## 0 1
## 61.75478 38.24522
From the above table we see that 38.24522 percent of the passengers survived.
mytable<-xtabs(~Pclass + Survived, data=titanic.df)
mytable
## Survived
## Pclass 0 1
## 1 80 134
## 2 97 87
## 3 372 119
134 first class passengers survived the sinking
prop.table(mytable,1)*100
## Survived
## Pclass 0 1
## 1 37.38318 62.61682
## 2 52.71739 47.28261
## 3 75.76375 24.23625
From the data above it is clear that 62.6182% of the first class passengers survived
mytable1 <- xtabs(~Pclass+Survived+Sex, data=titanic.df)
mytable1
## , , 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
Using the 3 way contingency table we find that 89 female first class passengers survived the sinking.
prop.table(xtabs(~Sex+Survived, data=titanic.df),2)*100
## Survived
## Sex 0 1
## female 14.75410 67.94118
## male 85.24590 32.05882
The percentage of survivors that were female is 67.94118
prop.table(xtabs(~Sex+Survived, data=titanic.df),1)*100
## Survived
## Sex 0 1
## female 25.96154 74.03846
## male 81.10919 18.89081
The percentage of females who survived is 74.03846
chisq.test(xtabs(~Sex+Survived, data=titanic.df))
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: xtabs(~Sex + Survived, data = titanic.df)
## X-squared = 258.43, df = 1, p-value < 2.2e-16
Since we that the p value is very low and p<0.01 we can reject the null hypothesis