Setting up directory and importing Dataset
getwd()
## [1] "C:/Users/parvp/Desktop/internship"
titanic.df<-read.csv(paste("Titanic Data.csv", sep=""))
head(titanic.df)
## 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
Counting Total Numbers of Passengers
table(titanic.df$Survived)
##
## 0 1
## 549 340
addmargins(table(titanic.df$Survived))
##
## 0 1 Sum
## 549 340 889
Total number of passengers on board = 889.
Total who survived out of them = 340
prop.table(table(titanic.df$Survived))*100
##
## 0 1
## 61.75478 38.24522
38.14522% of passengers survived.
xtabs(~Survived + Pclass, data=titanic.df)
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
134 First class passengers survived the sinking of Titanic.
prop.table(xtabs(~Survived + Pclass, data=titanic.df),2)*100
## Pclass
## Survived 1 2 3
## 0 37.38318 52.71739 75.76375
## 1 62.61682 47.28261 24.23625
62.61682% of first class passengers survived.
xtabs(~Survived + Pclass + Sex, data=titanic.df)
## , , Sex = female
##
## Pclass
## Survived 1 2 3
## 0 3 6 72
## 1 89 70 72
##
## , , Sex = male
##
## Pclass
## Survived 1 2 3
## 0 77 91 300
## 1 45 17 47
ftable((xtabs(~Survived + Pclass + Sex, data=titanic.df)))
## Sex female male
## Survived Pclass
## 0 1 3 77
## 2 6 91
## 3 72 300
## 1 1 89 45
## 2 70 17
## 3 72 47
89 Female passengers survived.
prop.table(xtabs(~Survived + Sex, data=titanic.df),2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
74.03846% of female passengers on board survived.
prop.table(xtabs(~Survived + Sex, data=titanic.df))*100
## Sex
## Survived female male
## 0 9.111361 52.643420
## 1 25.984252 12.260967
25.984% female passengers survived out of 889 passengers including male and female.
chisq.test(xtabs(~Survived + Sex, data=titanic.df))
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: xtabs(~Survived + Sex, data = titanic.df)
## X-squared = 258.43, df = 1, p-value < 2.2e-16
since, p-value is less than 0.05 hence we can safely reject the Null hypothesis