An rmd file analysis based on the sinking of the titanic.
setwd("C:\\Users\\Adithya Nataraj\\Downloads")
titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
length(titanic.df$Survived)
## [1] 889
There were 889 passengers on the Titanic.
table(titanic.df$Survived)
##
## 0 1
## 549 340
340 passengers are the survivors.
mytable <- with(titanic.df, table(Survived))
mytable
## Survived
## 0 1
## 549 340
prop.table(mytable)*100
## Survived
## 0 1
## 61.75478 38.24522
Only 38.24522% of the passengers survived and the rest 61.75478% died.
mytable <- xtabs(~ Survived+Pclass, data=titanic.df)
mytable
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
134 first class passengers survived and 80 first class passengers died. As it is obvious, the numer of third class passengers who died is very high with a number of 372.
prop.table(mytable, 2)*100
## Pclass
## Survived 1 2 3
## 0 37.38318 52.71739 75.76375
## 1 62.61682 47.28261 24.23625
Only 62.61682% of the first class passengerssuvived.
prop.table(mytable)*100
## Pclass
## Survived 1 2 3
## 0 8.998875 10.911136 41.844769
## 1 15.073116 9.786277 13.385827
Of the total passengers who were on board, the percentage of first class passengers who survived is 15.073116%.
mytable <- xtabs(~ Survived+Pclass+Sex, data=titanic.df)
mytable
## , , 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
The number of females from First-Class who survived the sinking of the Titanic is 89.
mytable <- xtabs(~ Survived+Sex, data=titanic.df)
mytable
## Sex
## Survived female male
## 0 81 468
## 1 231 109
prop.table(mytable, 1)*100
## Sex
## Survived female male
## 0 14.75410 85.24590
## 1 67.94118 32.05882
The total numberr of female survivors is 231 and it is 67.94118% of the total survivors.
prop.table(mytable, 2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
The percentage of females on board the Titanic who survived is 74.03846%.
Now, let us check the hypothesis that 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.
mytable <- xtabs(~Sex+Survived, data=titanic.df)
addmargins(mytable)
## Survived
## Sex 0 1 Sum
## female 81 231 312
## male 468 109 577
## Sum 549 340 889
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
From the Chi-squared test which we performed, we find that the p-value is small(p < 0.01), which suggests that we have to reject the null hypothesis but females survived more than men.