Reading the Titanic data set
titanic <- read.csv(paste("Titanic Data.csv",sep=""))
head(titanic)
## Survived Pclass Sex Age SibSp Parch Fare Embarked
## 1 0 3 male 22.0 1 0 7.2500 S
## 2 1 1 female 38.0 1 0 71.2833 C
## 3 1 3 female 26.0 0 0 7.9250 S
## 4 1 1 female 35.0 1 0 53.1000 S
## 5 0 3 male 35.0 0 0 8.0500 S
## 6 0 3 male 29.7 0 0 8.4583 Q
Average age of survivors and non-survivors.
aggregate(Age~Survived,data=titanic,mean)
## Survived Age
## 1 0 30.41530
## 2 1 28.42382
Here, we see that average age of survivors is less than that of non-survivors. Now, we will perform the t-test
Hypothesis: H1: “The Titanic survivors were younger than the passengers who died.”
t.test(titanic$Age ~ titanic$Survived)
##
## Welch Two Sample t-test
##
## data: titanic$Age by titanic$Survived
## t = 2.1816, df = 667.56, p-value = 0.02949
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.1990628 3.7838912
## sample estimates:
## mean in group 0 mean in group 1
## 30.41530 28.42382
Since the p-value is less than 0.05, thus we can reject the null hypothesis that the ages of the survivors and the dead people are the same. Hence, there is a significant difference between age of survivors and non-survivors of RMS Titanic.