This Project is given by Prof. Sameer Mathur (IIM Lucknow) during the Data Analytics and Science Internship. In this we are supposed to do the case study of Titanic to get a complete knowledge and hands-on R language.

TASK 2a: Download and review the Titanic Data.csv.

Task 2b: Read the Titanic data set into R. Create a dataframe called “Titanic”.

Titanic.df <- read.csv(paste("Titanic Data.csv", sep=""))

Task 2b: View the dataframe which was created.

View(Titanic.df)

TASK 3a: Use R to count the total number of passengers on board the Titanic.

Total number of Passengers onbord : 889

MyTitanicTable<-xtabs( ~ Survived, data=Titanic.df)
addmargins(MyTitanicTable)
## Survived
##   0   1 Sum 
## 549 340 889

TASK 3b:Use R to count the number of passengers who survived the sinking of the Titanic.

Survived (1): 340

MyTitanicTable<-xtabs( ~ Survived, data=Titanic.df)
MyTitanicTable
## Survived
##   0   1 
## 549 340

TASK 3c:Use R to measure the percentage of passengers who survived the sinking of the Titanic.

Percentage of Survived (1): 38.24%

MyTitanicTable<-xtabs( ~ Survived, data=Titanic.df)
prop.table(MyTitanicTable)*100
## Survived
##        0        1 
## 61.75478 38.24522

TASK 3d:Use R to count the number of first-class passengers who survived the sinking of the Titanic.

First Class Passengers who Survived: 134

MyTitanicTable<-xtabs( ~ Pclass + Survived, data=Titanic.df)
ftable(MyTitanicTable)
##        Survived   0   1
## Pclass                 
## 1                80 134
## 2                97  87
## 3               372 119

TASK 3e: Use R to measure the percentage of first-class passengers who survived the sinking of the Titanic.

Percentage of First class passengers who survived is: 15.07%

MyTitanicTable<-xtabs( ~ Pclass + Survived, data=Titanic.df)
prop.table(ftable(MyTitanicTable))*100
##        Survived         0         1
## Pclass                             
## 1                8.998875 15.073116
## 2               10.911136  9.786277
## 3               41.844769 13.385827

Persentage of First Class people survied out of 214 First class passengers is: 62.61%

MyTitanicTable<-xtabs( ~ Pclass + Survived, data=Titanic.df)
prop.table(ftable(MyTitanicTable),1)*100
##        Survived        0        1
## Pclass                           
## 1               37.38318 62.61682
## 2               52.71739 47.28261
## 3               75.76375 24.23625

TASK 3f: Use R to count the number of females from First-Class who survived the sinking of the

Number of First Class Females who were servived are: 89

MyTitanicTable<-xtabs( ~ Pclass + Sex + Survived, data=Titanic.df)
ftable(MyTitanicTable)
##               Survived   0   1
## Pclass Sex                    
## 1      female            3  89
##        male             77  45
## 2      female            6  70
##        male             91  17
## 3      female           72  72
##        male            300  47

TASK 3g: Use R to measure the percentage of survivors who were female

The Number of female survivours were: 67.94%

MyTitanicTable<-xtabs(~ Survived + Sex, data=Titanic.df)
prop.table(ftable(MyTitanicTable),1)*100
##          Sex   female     male
## Survived                      
## 0            14.75410 85.24590
## 1            67.94118 32.05882

TASK 3h: Use R to measure the percentage of females on board the Titanic who survived

Total number of Female who Survived: 74.03%

MyTitanicTable<-xtabs(~ Survived + Sex, data=Titanic.df)
prop.table(ftable(MyTitanicTable),2)*100
##          Sex   female     male
## Survived                      
## 0            25.96154 81.10919
## 1            74.03846 18.89081

TASK 3i: Run a Pearson’s Chi-squared test to test the hypothesis.

Since the p value is very very less we assume that our hypothesis is correct.

MyTitanicTable<-xtabs(~Sex + Survived, data=Titanic.df)
chisq.test(MyTitanicTable)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  MyTitanicTable
## X-squared = 258.43, df = 1, p-value < 2.2e-16