This is an assignment given on Week 1, Day 5 of the Data Analytics Internship under Prof. Sameer Mathur, IIML.
TASk 2a: Download and review the Titanic Data.csv data file associated with some Titanic Survivors.
TASK 2b: Read the Titanic data set into R. Create a dataframe called “titanic”.
setwd("C:/Users/Krushna/Downloads/UDEMY")
Titanic.df <- read.csv(paste("Titanic.csv", sep=""))
View(Titanic.df)
TASK 3a Use R to count the total number of passengers on board the Titanic.
dim(Titanic.df)
TASK 3b Use R to count the number of passengers who survived the sinking of the Titanic.
table(Titanic.df$Survived)
TASK 3c Use R to measure the percentage of passengers who survived the sinking of the Titanic.
prop.table(table(Titanic.df$Survived))*100
TASK 3d Use R to count the number of first-class passengers who survived the sinking of the Titanic.
mytable <- xtabs(~ Survived+Pclass, data=Titanic.df)
mytable
TASK 3e Use R to measure the percentage of first-class passengers who survived the sinking of the Titanic.
prop.table(mytable,2)*100
TASK 3f Use R to count the number of females from First-Class who survived the sinking of the Titanic
mytable <- xtabs(~ Survived+Pclass+Sex, data=Titanic.df)
mytable
TASK 3g Use R to measure the percentage of survivors who were female
mytable <- xtabs(~ Survived+Sex, data=Titanic.df)
prop.table(mytable,1)*100
TASK 3h Use R to measure the percentage of females on board the Titanic who survived
mytable <- xtabs(~ Survived+Sex, data=Titanic.df)
prop.table(mytable,2)*100
TASK 3i 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.
mytable <- xtabs(~Survived+Sex, data=Titanic.df)
addmargins(mytable)
chisq.test(mytable)
Hence assumed hypothesis is true.