command used: read.csv
titanic <- read.csv(paste("Titanic Data.csv",sep=""))
View(titanic)
command used: nrow
nrow(titanic)
## [1] 889
command used: table
survived<-table(titanic$Survived)
survived
##
## 0 1
## 549 340
In orignal dataset, 1 corresponds to the people, who survived the attack and 0 otherwise. Therefore, total number of survivers is 340
library(lattice)
## Warning: package 'lattice' was built under R version 3.3.3
histogram(~Survived,data=titanic,type="count",
xlab="Survivers",
col=c("darkolivegreen","burlywood"))
command used: prop.table
prop.table(survived)*100
##
## 0 1
## 61.75478 38.24522
As the data suggests, percentage of survivers is approximately equal to 38.24%
library(lattice)
histogram(~Survived,data=titanic,type="percent",
xlab="Survivers",
col=c("darkolivegreen","burlywood"))
Command used: xtabs
data_table <- xtabs(~Survived+Pclass,data=titanic)
data_table
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
From the table we can see that number of surviver with a first class ticket is: 134
library(lattice)
histogram(~Survived | Pclass,data=titanic,type="count",
xlab="Survivers",
col=c("darkolivegreen","burlywood"))
command used: prop.table
prop.table(data_table,2)*100
## Pclass
## Survived 1 2 3
## 0 37.38318 52.71739 75.76375
## 1 62.61682 47.28261 24.23625
Total of 62.6% of the first class people survived the tragedy.
histogram(~Survived | Pclass,data=titanic,type="percent",
xlab="Survivers",
col=c("darkolivegreen","burlywood"))
command used: xtabs , ftable
myData <- xtabs(~Survived+Pclass+Sex,data=titanic)
ftable(myData)
## Sex female male
## Survived Pclass
## 0 1 3 77
## 2 6 91
## 3 72 300
## 1 1 89 45
## 2 70 17
## 3 72 47
Number of female survivers from first class = 89
histogram(~Survived | Pclass+Sex,data=titanic,type="count",
xlab="Survivers",
col=c("darkolivegreen","burlywood"))
#Task3g: Percentage of females from first class, who survived the sinking Command used:
ftable , prop.table
myData1 = xtabs(~Survived+Sex,data = titanic)
prop.table(myData1,1)*100
## Sex
## Survived female male
## 0 14.75410 85.24590
## 1 67.94118 32.05882
The percentage of survivers, who were women = 67.1764%
histogram(~Sex | Survived,data=titanic,type="percent",
xlab="Survivers",
col=c("darkolivegreen","burlywood"))
#Task3h: Percentage of females who survived command used:
prop.table
prop.table(myData1,2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
Approximately 74% of females survived the sinking of the titanic. On the other hand, 81% of the males were not able to survive the sinking.
histogram(~Survived | Sex,data=titanic,type="percent",
xlab="Survivers",
col=c("darkolivegreen","burlywood"))
command used: chisq.test Null 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.
myData = xtabs(~Survived+Sex,data=titanic)
chisq.test(myData)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: myData
## X-squared = 258.43, df = 1, p-value < 2.2e-16
Since, the number of value of p<0.01. Therefore, we reject the null hypothesis. Hence, The proportion of females onboard who survived the sinking of the Titanic was not higher than the proportion of makes onboard who survived the sinking of the Titanic.