1. Synopsis

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.

2. Exercise

Use R to create a table showing the average age of the survivors and the average age of the people who died.

Titanic<-read.csv(paste("Titanic Data.csv",sep = ""))
Titanic$Survived=factor(Titanic$Survived,levels = c(0,1), labels = c("No","Yes"))
attach(Titanic)
aggregate(Age~Survived,data = Titanic, FUN= mean)
##   Survived      Age
## 1       No 30.41530
## 2      Yes 28.42382

Use R to run a t-test to test the following hypothesis:

H2: The Titanic survivors were younger than the passengers who died.

Titanic<-read.csv(paste("Titanic Data.csv",sep = ""))
attach(Titanic)
## The following objects are masked from Titanic (pos = 3):
## 
##     Age, Embarked, Fare, Parch, Pclass, Sex, SibSp, Survived
t.test(log(Age),Survived,paired=TRUE)
## 
##  Paired t-test
## 
## data:  log(Age) and Survived
## t = 93.662, df = 888, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  2.790999 2.910470
## sample estimates:
## mean of the differences 
##                2.850735

Conclusion

The average age of the survivors is less than the average age of the people who died, as shown by the table. From the Paired t-test, since the p-value is less than 2.2e-16, we can reject the null hypothesis.This means that there is a significant difference between the average ages of survivors and the passengers who died. Thus, our hypothesis that the Titanic survivors were younger than the passengers who died, is proved true.