Total number of passengers on board the Titanic - 889
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
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
The number of passengers who survived the sinking of the Titanic - 340
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
table(Titanic$Survived)
##
## 0 1
## 549 340
The percentage of passengers who survived the sinking of the Titanic - 38.24522
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
Surive_sinking = length(Titanic$Survived[Titanic$Survived >= 1]) / length(Titanic$Survived)* 100
print(Surive_sinking)
## [1] 38.24522
The number of first-class passengers who survived the sinking of the Titanic - 134
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
xtabs(~Titanic$Pclass + Titanic$Survived)
## Titanic$Survived
## Titanic$Pclass 0 1
## 1 80 134
## 2 97 87
## 3 372 119
The percentage of first-class passengers who survived the sinking of the Titanic - 15.073116
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
prop.table(table(Titanic$Pclass, Titanic$Survive))
##
## 0 1
## 1 0.08998875 0.15073116
## 2 0.10911136 0.09786277
## 3 0.41844769 0.13385827
The number of females from First-Class who survived the sinking of the Titanic - 89
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
library(plyr)
by(Titanic$Pclass, list(Titanic$Survived, Titanic$Sex), count)
## : 0
## : female
## x freq
## 1 1 3
## 2 2 6
## 3 3 72
## --------------------------------------------------------
## : 1
## : female
## x freq
## 1 1 89
## 2 2 70
## 3 3 72
## --------------------------------------------------------
## : 0
## : male
## x freq
## 1 1 77
## 2 2 91
## 3 3 300
## --------------------------------------------------------
## : 1
## : male
## x freq
## 1 1 45
## 2 2 17
## 3 3 47
The percentage of survivors who were female - (231/340)*100 = 67.9411
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
table(Titanic$Survived, Titanic$Sex)
##
## female male
## 0 81 468
## 1 231 109
The percentage of females on board the Titanic who survived - 25.984252
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
prop.table(table(Titanic$Sex, Titanic$Survive))
##
## 0 1
## female 0.09111361 0.25984252
## male 0.52643420 0.12260967
Chi-squared test
Titanic<-read.csv("C:/Users/here_is_sachin/Downloads/Titanic Data.csv")
mytable<-xtabs(~Titanic$Survived + Titanic$Sex)
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