Task 2(b)

Use the read.csv() function in R to read the data and store it in a dataframe called “Titanic_Data”.

Task 3(a)

count the total number of passengers on board the Titanic.

nrow(Titanic_Data)

889
##1 889

Task 3(b)

count the number of passengers who survived the sinking of the Titanic.

nrow(subset(Titanic_Data,Survived==1))
340

1 340

Task 3(c)

measure the percentage of passengers who survived the sinking of the Titanic.

(prop.table(table(Titanic_Data$Survived))*100)[2]
38.24522

1

38.24522

Task 3(d)

count the number of first-class passengers who survived the sinking of the Titanic.

mytable <- xtabs(~Survived+Pclass,data=Titanic_Data) mytable[2]
134

1 134

Task 3(e)

measure the percentage of first-class passengers who survived the sinking of the Titanic.

(prop.table(mytable)*100)[2]
15.07312

1 15.07312

Task 3(f)

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

1 89

Task 3(g)

measure the percentage of survivors who were female

mytable <- xtabs(~Survived+Sex,data=Titanic_Data) (prop.table(mytable,1)*100)[2,1]
67.94118

1 67.94118

Task 3(h)

measure the percentage of females on board the Titanic who survived.

(prop.table(mytable,2)*100)[2,1]
74.03846

1 74.03846

Task 3(i)

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)

Pearson’s Chi-squared test with Yates’ continuity correction

data: mytable

X-squared = 258.43, df = 1, p-value < 2.2e-16

since the P-value < 0.05, we reject the null hypothesis.