Use the read.csv() function in R to read the data and store it in a dataframe called “Titanic_Data”.
count the number of passengers who survived the sinking of the Titanic.
nrow(subset(Titanic_Data,Survived==1))
340
measure the percentage of passengers who survived the sinking of the Titanic.
(prop.table(table(Titanic_Data$Survived))*100)[2]
38.24522
count the number of first-class passengers who survived the sinking of the Titanic.
mytable <- xtabs(~Survived+Pclass,data=Titanic_Data) mytable[2]
134
measure the percentage of first-class passengers who survived the sinking of the Titanic.
(prop.table(mytable)*100)[2]
15.07312
count the number of females from First-Class who survived the sinking of the Titanic
female <- xtabs(~Survived+Pclass+Sex,data=Titanic_Data) (ftable(female))[4]
89
measure the percentage of survivors who were female
mytable <- xtabs(~Survived+Sex,data=Titanic_Data) (prop.table(mytable,1)*100)[2,1]
67.94118
measure the percentage of females on board the Titanic who survived.
(prop.table(mytable,2)*100)[2,1]
74.03846
Run a 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.
chisq.test(mytable)
since the P-value < 0.05, we reject the null hypothesis.