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)
  1. counting the total number of passengers on board the Titanic.
dim(titanic)
## [1] 889   8

number of passengers is thus 889=no. of rows

3)counting the number of passengers who survived the sinking of the Titanic.

 table(titanic$Survived)
## 
##   0   1 
## 549 340

Therefore number of people who survived =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

Therefore, 38.24522% of passengers survived the sinking of titanic

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

number of first class passengers who survived are 134

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

therefore as we can see 62.61682% first class passengers survived

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

therefore 89 first class female passengers survived

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

Therefore 67.94118 % survivors were female

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

therefore 74.03846% of total females on board survived

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

since the value of p-value is less than 0.05 therefore null hypothesis is rejected and there is a correlation between number of survivors and the sex of passengers