R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Sinking of the RMS Titanic

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.

Reading the csv and view

titanic <- read.csv(paste("TitanicData.csv", sep=""))
View(titanic)

3a

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
totalpassengers <- tally(titanic)
totalpassengers
##     n
## 1 889

Total passengers are 889

3b

tc <- filter(titanic,Survived==1)
survivedpassengers <- tally(tc)
survivedpassengers
##     n
## 1 340

Total passengers who survived are:340

3c

td <- filter(titanic,Survived==0)
notsurvivedpassengers <- tally(td)
Percentagesurvived<-(survivedpassengers)/(survivedpassengers+notsurvivedpassengers)*100
Percentagesurvived
##          n
## 1 38.24522

Total Percentage of survived passengers is:38.24%

3d

mb<-filter(titanic,Survived==1,Pclass==1)
SurvivedFclass<-tally(mb)
SurvivedFclass
##     n
## 1 134

Number of first-class passengers who survived the sinking of the Titanic:134

3e

PercFclasssurvived<-(SurvivedFclass)/(survivedpassengers)*100
PercFclasssurvived
##          n
## 1 39.41176

Percentage of first-class passengers who survived the sinking of the Titanic:39.41%

3f

hp<-filter(titanic,Survived==1,Pclass==1,Sex=="female")
SurvivedFclassFemale<-tally(hp)
SurvivedFclassFemale
##    n
## 1 89

Number of females from First-Class who survived the sinking of the Titanic:89

3g

hs<-filter(titanic,Survived==1,Sex=="female")
hq<-tally(hs)
PercFemaleSurvived<-((hq)/(survivedpassengers))*100
PercFemaleSurvived
##          n
## 1 67.94118

Percentage of survivors who were female:67.94%

3h

hi<-filter(titanic,Sex=="female")
ht<-tally(hi)
TotPercFemaleSurvived<-(hq)/(ht)*100
TotPercFemaleSurvived
##          n
## 1 74.03846

Percentage of females on board the Titanic who survived:74.03%

3i

myd <- xtabs(~Survived+Sex,data=titanic)
addmargins(myd) 
##         Sex
## Survived female male Sum
##      0       81  468 549
##      1      231  109 340
##      Sum    312  577 889
chisq.test(myd)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  myd
## X-squared = 258.43, df = 1, p-value < 2.2e-16

Here pvalue<0.05.It means we can reject the null hypothesis.It suggests a relationship between the people who survived and their sex.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.