SYNOPSIS
This is an R Markdown document analysing the case study-Sinking of RMS Titanic.
1)Reading the dataset
setwd("~/winter internship")
titanic <- read.csv(paste("Titanic Data.csv",sep=""))
View(titanic)
dim(titanic)
## [1] 889 8
3)counting the number of passengers who survived the sinking of the Titanic.
table(titanic$Survived)
##
## 0 1
## 549 340
4)measure the percentage of passengers who survived the sinking of the Titanic.
x <- prop.table(table(titanic$Survived))
x*100
##
## 0 1
## 61.75478 38.24522
5)counting the number of first-class passengers who survived the sinking of the Titanic
library(vcd)
## Loading required package: grid
mytable <- xtabs(~ Pclass + Survived,data=titanic)
mytable
## Survived
## Pclass 0 1
## 1 80 134
## 2 97 87
## 3 372 119
6)measuring the percentage of first-class passengers who survived the sinking of the Titanic
prop.table(mytable,1)*100
## Survived
## Pclass 0 1
## 1 37.38318 62.61682
## 2 52.71739 47.28261
## 3 75.76375 24.23625
7)count the number of females from First-Class who survived the sinking of the Titanic
mytable1 <- xtabs(~ Pclass + Survived + Sex,data=titanic)
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
8)measuring the percentage of survivors who were female
mytable2<- xtabs(~ Sex + Survived, data = titanic)
mytable2
## Survived
## Sex 0 1
## female 81 231
## male 468 109
prop.table(mytable2,2)*100
## Survived
## Sex 0 1
## female 14.75410 67.94118
## male 85.24590 32.05882
9)measuring the percentage of females on board the Titanic who survived
prop.table(mytable2,1)*100
## Survived
## Sex 0 1
## female 25.96154 74.03846
## male 81.10919 18.89081
10)Testing theHypothesis: 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 using chi square
addmargins(mytable2)
## Survived
## Sex 0 1 Sum
## female 81 231 312
## male 468 109 577
## Sum 549 340 889
chisq.test(mytable2)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mytable2
## X-squared = 258.43, df = 1, p-value < 2.2e-16