Below R Markdown contains various tasks pertaining the Titanic Case Study.
library(vcd)
## Loading required package: grid
Titanic <- read.csv(paste("Titanic.csv",sep = ""))
View(Titanic)
Basically the categorical data file (Titanic.csv), contains various categorical variables. (i.e, Survived, Pclass, Sex, Age, SibSp, Parch, Fare and Embarked.). It broadly uncovers the survival number of people in the tragedy.
And the analysis of Titanic Case Study goes as follows:
library(psych)
describe(Titanic)
## vars n mean sd median trimmed mad min max range
## Survived 1 889 0.38 0.49 0.00 0.35 0.00 0.0 1.00 1.00
## Pclass 2 889 2.31 0.83 3.00 2.39 0.00 1.0 3.00 2.00
## Sex* 3 889 1.65 0.48 2.00 1.69 0.00 1.0 2.00 1.00
## Age 4 889 29.65 12.97 29.70 29.22 9.34 0.4 80.00 79.60
## SibSp 5 889 0.52 1.10 0.00 0.27 0.00 0.0 8.00 8.00
## Parch 6 889 0.38 0.81 0.00 0.19 0.00 0.0 6.00 6.00
## Fare 7 889 32.10 49.70 14.45 21.28 10.24 0.0 512.33 512.33
## Embarked* 8 889 2.54 0.79 3.00 2.67 0.00 1.0 3.00 2.00
## skew kurtosis se
## Survived 0.48 -1.77 0.02
## Pclass -0.63 -1.27 0.03
## Sex* -0.62 -1.61 0.02
## Age 0.43 0.96 0.43
## SibSp 3.68 17.69 0.04
## Parch 2.74 9.66 0.03
## Fare 4.79 33.23 1.67
## Embarked* -1.26 -0.23 0.03
Total Passengers : 889
table(Titanic$Survived)
##
## 0 1
## 549 340
Passengers Survived = 340
SurvivedTable <- xtabs(~Survived,data=Titanic)
prop.table(SurvivedTable)*100
## Survived
## 0 1
## 61.75478 38.24522
% of passengers survived = 38.24
F_classSurvived <- xtabs(~Pclass+Survived, data=Titanic)
addmargins(F_classSurvived)
## Survived
## Pclass 0 1 Sum
## 1 80 134 214
## 2 97 87 184
## 3 372 119 491
## Sum 549 340 889
F_ClassSurvided: 134
addmargins(prop.table(F_classSurvived)*100)
## Survived
## Pclass 0 1 Sum
## 1 8.998875 15.073116 24.071991
## 2 10.911136 9.786277 20.697413
## 3 41.844769 13.385827 55.230596
## Sum 61.754781 38.245219 100.000000
% of F_ClassSurvived = 15.07
F_FC_Survived <- xtabs(~Sex+Pclass+Survived, data=Titanic)
addmargins(F_FC_Survived)
## , , Survived = 0
##
## Pclass
## Sex 1 2 3 Sum
## female 3 6 72 81
## male 77 91 300 468
## Sum 80 97 372 549
##
## , , Survived = 1
##
## Pclass
## Sex 1 2 3 Sum
## female 89 70 72 231
## male 45 17 47 109
## Sum 134 87 119 340
##
## , , Survived = Sum
##
## Pclass
## Sex 1 2 3 Sum
## female 92 76 144 312
## male 122 108 347 577
## Sum 214 184 491 889
First Class Females Survivors = 89
F_Survivors <- xtabs(~Survived+Sex, data = Titanic)
prop.table(F_Survivors)*100
## Sex
## Survived female male
## 0 9.111361 52.643420
## 1 25.984252 12.260967
Percentage of Female Survivors : 25.98
mytable <- xtabs(~Sex+Survived, data=Titanic)
ftable(mytable)
## Survived 0 1
## Sex
## female 81 231
## male 468 109
margin.table(mytable,1)
## Sex
## female male
## 312 577
table((231/312)*100)
##
## 74.0384615384615
## 1
Percentage of Female Survivors : 74.03
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
And from the Chi Square Test, we can conclude by rejecting the Null Hypothesis, as the probablity tends to be less than 0.05 (i.e, P<<0.05).