Data-set used is as follows:
setwd("C:\\Users\\Tejajay\\Desktop\\Internship\\3. Data Analytics")
titanic <- read.csv(paste("TitanicData.csv", sep=""))
survived <- titanic[ which(titanic$Survived=='1'), ]
View(survived)
agesurvived <- with(survived, table(Age))
View(agesurvived)
mean(survived$Age)
## [1] 28.42382
notsurvived <- titanic[ which(titanic$Survived=='0'), ]
View(notsurvived)
agenotsurvived <- with(notsurvived, table(Age))
View(agenotsurvived)
mean(notsurvived$Age)
## [1] 30.4153
t.test(Age ~ Survived, data = titanic)
##
## Welch Two Sample t-test
##
## data: Age by 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
We get output from t-test that “true difference in means is not equal to 0” which means that there is a significant difference in the ages. We also obtain that mean age of survivors is 28.42382 years, while mean age of non-survivors is 30.41530, which means that survivors are younger than non-survivors.