R Markdown

Setting up

titanic <- read.csv(paste("TitanicData.csv", sep = ""))

library(psych)

All data shown does not include parents, children, siblings and spouses

Total number of passengers on board on the Titanic = 889

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

Number of passengers who survived the sinking of the Titanic = 340

table(titanic$Survived) 
## 
##   0   1 
## 549 340
new <- with(titanic, table(Survived))
new
## Survived
##   0   1 
## 549 340

Percentage of passengers who survived the sinking of the Titanic = 38.24%

prop.table(new)*100
## Survived
##        0        1 
## 61.75478 38.24522

Number of first class passengers who survived the sinking of the Titanic = 134

new1 <- xtabs(~titanic$Survived+titanic$Pclass) 
new1
##                 titanic$Pclass
## titanic$Survived   1   2   3
##                0  80  97 372
##                1 134  87 119

Percentage of first class passengers who survived the sinking of the Titanic = 15.07%

prop.table(new1)*100
##                 titanic$Pclass
## titanic$Survived         1         2         3
##                0  8.998875 10.911136 41.844769
##                1 15.073116  9.786277 13.385827

Number of first class passengers who were female who survived the sinking of the Titanic = 89

newF <- xtabs(~titanic$Sex+titanic$Survived+titanic$Pclass)
newF
## , , titanic$Pclass = 1
## 
##            titanic$Survived
## titanic$Sex   0   1
##      female   3  89
##      male    77  45
## 
## , , titanic$Pclass = 2
## 
##            titanic$Survived
## titanic$Sex   0   1
##      female   6  70
##      male    91  17
## 
## , , titanic$Pclass = 3
## 
##            titanic$Survived
## titanic$Sex   0   1
##      female  72  72
##      male   300  47

Percentage of survivors who were female = 67.94%

newF1<- xtabs(~titanic$Survived+titanic$Sex) #
 
 newF1
##                 titanic$Sex
## titanic$Survived female male
##                0     81  468
##                1    231  109
prop.table(newF1,1)*100
##                 titanic$Sex
## titanic$Survived   female     male
##                0 14.75410 85.24590
##                1 67.94118 32.05882

Percentage of females on board the Titanic who survived = 25.98%

prop.table(newF1)*100
##                 titanic$Sex
## titanic$Survived    female      male
##                0  9.111361 52.643420
##                1 25.984252 12.260967

Pearson’s Chi-squared test to test the following hypothesis:

Hypothesis: The proportion of females onboard who survived the sinking of the Titanic was higher than the proportion of males onboard who survived the sinking of the Titanic.

Test passed as 2.2e-16<0.05

addmargins(prop.table(newF1)*100,1)
##                 titanic$Sex
## titanic$Survived    female      male
##              0    9.111361 52.643420
##              1   25.984252 12.260967
##              Sum 35.095613 64.904387
chisq.test(newF1)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  newF1
## X-squared = 258.43, df = 1, p-value < 2.2e-16