DAY 5 - ASSIGNMENT (TITANINC)

TITANIC INCIDENT: The sinking of the RMS Titanic occurred on the night of 14 April through to the morning of 15 April 1912 in the North Atlantic Ocean, four days into the ship’s maiden voyage from Southampton to New York City. The largest passenger liner in service at the time, Titanic had an estimated 2,224 people on board when she struck an iceberg at around 23:40 (ship’s time) on Sunday, 14 April 1912. Her sinking two hours and forty minutes later at 02:20 (05:18 GMT) on Monday, 15 April resulted in the deaths of more than 1,500 people, which made it one of the deadliest peacetime maritime disasters in history.

Task 2b

Creating Titanic Data set, by creating titanic Dataframe

setwd("C:/Users/hp/Desktop/IIML/My Project files")
titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
View(titanic.df)

Task 3a

Calculate No. of Passender

## [1] 889   8
## [1] 889

Ans- 889

Task 3b

the number of passengers who survived the sinking of the Titanic.

sum(titanic.df$Survived==1)
## [1] 340

Or

mytable <- with(titanic.df, table(Survived))
mytable
## Survived
##   0   1 
## 549 340

340 Survived

Task 3c

the percentage of passengers who survived the sinking of the Titanic

sum(titanic.df$Survived==1)/length(titanic.df$Survived)*100
## [1] 38.24522

Or

prop.table(mytable)*100
## Survived
##        0        1 
## 61.75478 38.24522

38 percent survived

Task 3d

the number of first-class passengers who survived the sinking of the Titanic.

mytable <- xtabs(~ Survived + Pclass, data= titanic.df)
mytable
##         Pclass
## Survived   1   2   3
##        0  80  97 372
##        1 134  87 119

Ans 134

Task 3e

the percentage of first-class passengers who survived the sinking of the Titanic

prop.table(mytable,2)*100
##         Pclass
## Survived        1        2        3
##        0 37.38318 52.71739 75.76375
##        1 62.61682 47.28261 24.23625

Ans- 62.6

Task 3f

the number of females from First-Class who survived the sinking of the Titanic

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

or

sum(titanic.df$Survived==1 & titanic.df$Pclass==1 & titanic.df$Sex=="female")
## [1] 89

Ans- 89

Task 3g

the percentage of survivors who were female

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

Ans- 85.24

Task 3h

the percentage of females on board the Titanic who survived

prop.table(mytable,2)*100
##         Sex
## Survived   female     male
##        0 25.96154 81.10919
##        1 74.03846 18.89081

Ans- 74

Task 3i

Pearson’s Chi-squared test to test the following hypothesis:

Hypothesis: 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)
mytable
##         Survived
## Sex        0   1
##   female  81 231
##   male   468 109
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

Since p valve is very less than 0.05 Null hypothesis rejected.