setwd("E:/Internship/Tasks/Week 1/Week 1, Day 5 (Fri)")
Directory is Set
titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
Dataframe is ready
View(titanic.df)
addmargins(xtabs(~Survived, data=titanic.df))
## Survived
## 0 1 Sum
## 549 340 889
(Task 3a)So sum is 889 so number of passengers are 889
xtabs(~Survived, data=titanic.df)
## Survived
## 0 1
## 549 340
(Task 3b) So clearly from above table 340 people have survived
prop.table(xtabs(~Survived, data=titanic.df))*100
## Survived
## 0 1
## 61.75478 38.24522
(Task 3c) so clearly 38.24% people have survived on the ship
xtabs(~Survived+Pclass,data=titanic.df)
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
(Task 3d) so from above table 134 people from first class have survived from the ship
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
(Task 3e) so 62.61% people have survived from the first class survived from the ship
(xtabs(~Sex+Survived+Pclass,data=titanic.df))
## , , Pclass = 1
##
## Survived
## Sex 0 1
## female 3 89
## male 77 45
##
## , , Pclass = 2
##
## Survived
## Sex 0 1
## female 6 70
## male 91 17
##
## , , Pclass = 3
##
## Survived
## Sex 0 1
## female 72 72
## male 300 47
(Task 3f) so 89 females from first class survived on the ship
prop.table(xtabs(~Survived+Sex,data=titanic.df),1)*100
## Sex
## Survived female male
## 0 14.75410 85.24590
## 1 67.94118 32.05882
(Task 3g) 67.94% of survivors were female
prop.table(xtabs(~Survived+Sex,data=titanic.df),2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
(Task 3h) 74.03% of female were able to survive
mytable <- xtabs(~Survived+Sex,data=titanic.df)
chisq.test(mytable)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mytable
## X-squared = 258.43, df = 1, p-value < 2.2e-16
(Task 3i) Hypothesis is coming negative