Recall the Titanic Data.csv data associated with the “Sinking of the RMS Titanic” that you analyzed on WEEK 1, DAY 5
setwd("C:/Users/jaya/downloads")
titanic.df<-read.csv(paste("Titanic Data.csv",sep=""))
View(titanic.df)
Use R to create a table showing the average age of the survivors and the average age of the people who died.
mytable <-aggregate(titanic.df$Age,by=list(survived=titanic.df$Survived),FUN=mean)
mytable
## survived x
## 1 0 30.41530
## 2 1 28.42382
Average age of the survivor is 28 Average age of the people who died is 30.
Use R to run a t-test to test the following hypothesis: H2: The Titanic survivors were younger than the passengers who died.
t.test(mytable,var.equal = TRUE)
##
## One Sample t-test
##
## data: mytable
## t = 1.7893, df = 3, p-value = 0.1715
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -11.64783 41.56739
## sample estimates:
## mean of x
## 14.95978
The p-value is higher than 0.05,so there is no significant proof for the null hypothesis to be rejected.This assumption is thus true. So,this concludes that titanic survivors were younger than the passenger who died.