# 2a and 2b
titanic <- read.csv(paste("Titanic Data.csv"),sep = ",")
View(titanic)
# 3a
dim(titanic)
## [1] 889 8
total number of enteries(rows) is equal to total passengers=889
#3b
table(titanic$Survived)
##
## 0 1
## 549 340
true is 1 and hence 340 survived
#3c
prop.table(table(titanic$Survived))*100
##
## 0 1
## 61.75478 38.24522
people who survived after the sink are 38.25%
#3d
xtabs(~Pclass + Survived, data = titanic)
## Survived
## Pclass 0 1
## 1 80 134
## 2 97 87
## 3 372 119
total number of passengers who survived after the sink of titanic is 134
#3e
prop.table(xtabs(~Pclass + Survived, data = titanic))*100
## Survived
## Pclass 0 1
## 1 8.998875 15.073116
## 2 10.911136 9.786277
## 3 41.844769 13.385827
first passengers survived after the sink of titanic is 15.07%
#3f
xtabs(~Sex+Survived+Pclass, data = titanic)
## , , 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
total first class survived females = 89
#3g
prop.table(xtabs(~Sex+Survived, data = titanic),2)*100
## Survived
## Sex 0 1
## female 14.75410 67.94118
## male 85.24590 32.05882
total female survivors are 67.94%
#3h
prop.table(xtabs(~Sex+Survived, data = titanic),1)*100
## Survived
## Sex 0 1
## female 25.96154 74.03846
## male 81.10919 18.89081
total 74.03 females in the board survived in titanic
#3i
hold <- xtabs(~Sex+Survived, data = titanic)
addmargins(hold)
## Survived
## Sex 0 1 Sum
## female 81 231 312
## male 468 109 577
## Sum 549 340 889
chisq.test(hold)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: hold
## X-squared = 258.43, df = 1, p-value < 2.2e-16
since p < 0.05 it conclude to be null hypothesis