Read data
Titanic <- read.csv(file="Titanic Data.csv", header=TRUE, sep=",")
View(Titanic)
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
describe(Titanic$Survived)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 889 0.38 0.49 0 0.35 0 0 1 1 0.48 -1.77 0.02
dim(Titanic)
## [1] 889 8
library(vcd)
## Loading required package: grid
mytable <- with(Titanic, table(Survived))
mytable # frequencies
## Survived
## 0 1
## 549 340
prop.table(mytable)*100 #percentages
## Survived
## 0 1
## 61.75478 38.24522
mytable <- xtabs(~ Survived+Pclass, data=Titanic)
mytable # frequencies
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
prop.table(mytable) # cell proportions
## Pclass
## Survived 1 2 3
## 0 0.08998875 0.10911136 0.41844769
## 1 0.15073116 0.09786277 0.13385827
mytable
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
mytable <- xtabs(~ Sex+Pclass, data=Titanic)
mytable # frequencies
## Pclass
## Sex 1 2 3
## female 92 76 144
## male 122 108 347
prop.table(mytable) # cell proportions
## Pclass
## Sex 1 2 3
## female 0.10348706 0.08548931 0.16197975
## male 0.13723285 0.12148481 0.39032621
mytable
## Pclass
## Sex 1 2 3
## female 92 76 144
## male 122 108 347
mytable <- xtabs(~ Survived+Sex, data=Titanic)
mytable
## Sex
## Survived female male
## 0 81 468
## 1 231 109
mytable # frequencies
## Sex
## Survived female male
## 0 81 468
## 1 231 109
prop.table(mytable) # cell proportions
## Sex
## Survived female male
## 0 0.09111361 0.52643420
## 1 0.25984252 0.12260967
mytable
## Sex
## Survived female male
## 0 81 468
## 1 231 109
mytable <- xtabs(~ Sex+Pclass+Survived, data=Titanic)
mytable
## , , Survived = 0
##
## Pclass
## Sex 1 2 3
## female 3 6 72
## male 77 91 300
##
## , , Survived = 1
##
## Pclass
## Sex 1 2 3
## female 89 70 72
## male 45 17 47
ftable(mytable)
## Survived 0 1
## Sex Pclass
## female 1 3 89
## 2 6 70
## 3 72 72
## male 1 77 45
## 2 91 17
## 3 300 47
mytable
## , , Survived = 0
##
## Pclass
## Sex 1 2 3
## female 3 6 72
## male 77 91 300
##
## , , Survived = 1
##
## Pclass
## Sex 1 2 3
## female 89 70 72
## male 45 17 47
mytable <- xtabs(~ Survived+Sex, data=Titanic)
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