This is the analysis of Titanic Data to analyse the ages of passengers who have survived and those who have died using t-test. ( Assuming that the ages of survivors and those no.of passengers who died are independant)
titanic <- read.csv(paste("Titanic Data.csv", sep="")) #creating a data frame called "titanic"
View(titanic) # View the data frame
3 b)To create a table showing the average age of survivors and people who died
tabl=aggregate(Age~Survived,data=titanic,FUN = mean)
tabl
## Survived Age
## 1 0 30.41530
## 2 1 28.42382
Average age of Survivors of Titanic
tabl[2,2]
## [1] 28.42382
Average Age of people who died
tabl[1,2]
## [1] 30.4153
The average age of survivors is 28.42 and the average age of people who died is 30.41. So the survivors are younger than the people who died by looking at the average age.
Boxplots showing the ages of surivivors and those of people who died
survive = titanic[which(titanic$Survived == '1'), ] #dataframe containg the details of people who survived
notsurvive = titanic[which(titanic$Survived == '0'), ]#dataframe containg the details of people who did not survive
par(mfrow=c(1,2))
boxplot(survive$Age, main = "Ages of Survivors", ylab = "Age")
boxplot(notsurvive$Age, main = "Ages of People who died", ylab = "Age")
3 c) Use R to run a t-test to test the following hypothesis: H2: The Titanic survivors were younger than the passengers who died.
Let us consider this Null Hypothesis :The is no significant difference between the ages of Survivors and ages of people 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 p-value of the test is 0.02949, p<0.05, we rejest the Null Hypothesis that there is no significant difference the ages of survivors and the ages of people who died So, we can conclude that there is a signicant difference between ages of survivors and the ages of people who died, ie, The titanic survivors are younger than the passengers who died.