titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))
library(psych)
View(titanic.df)
library(rmarkdown)
Comments: 889 obs. of 8 variables is available for viewing as part of titanic dataframe
length(titanic.df$Survived)
## [1] 889
Comments: Total number of passengers on board = 889
table(titanic.df$Survived)
##
## 0 1
## 549 340
Comments: Total 340 passengers survived sinking of Titanic
mytable <- with(titanic.df, table(Survived))
prop.table(mytable)*100
## Survived
## 0 1
## 61.75478 38.24522
mytable <- xtabs (~Survived+Pclass, data=titanic.df)
mytable
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
Comments: the number of first-class passengers who survived the sinking of the Titanic is 134
mytable <- xtabs (~Survived+Pclass, data=titanic.df)
prop.table(mytable)*100
## Pclass
## Survived 1 2 3
## 0 8.998875 10.911136 41.844769
## 1 15.073116 9.786277 13.385827
Comments: 15% of first-class passengers survived the sinking of the Titanic
mytable <- xtabs(~Sex+Pclass+Survived, data=titanic.df)
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
Comments: 89 females from First-Class survived the sinking of the Titanic
mytable <- xtabs (~Survived+Sex, data=titanic.df)
addmargins(mytable)
## Sex
## Survived female male Sum
## 0 81 468 549
## 1 231 109 340
## Sum 312 577 889
prop.table(mytable)*100
## Sex
## Survived female male
## 0 9.111361 52.643420
## 1 25.984252 12.260967
Comments: 25.984% of survivors were female
mytable <- xtabs (~Sex+Survived, data=titanic.df)
prop.table(mytable)*100
## Survived
## Sex 0 1
## female 9.111361 25.984252
## male 52.643420 12.260967
Comments: 25.984% of females on board the Titanic survived
mytable <- xtabs(~Sex+Survived, data=titanic.df)
addmargins(mytable)
## Survived
## Sex 0 1 Sum
## female 81 231 312
## male 468 109 577
## Sum 549 340 889
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
Comments: Assumed hypothesis is true