Assignment of analysing data of Sinking of the RMS Titanic.

titanic <- read.csv(paste("Titanic Data.csv", sep=""))
View(titanic)
head(titanic)
##   Survived Pclass    Sex  Age SibSp Parch    Fare Embarked
## 1        0      3   male 22.0     1     0  7.2500        S
## 2        1      1 female 38.0     1     0 71.2833        C
## 3        1      3 female 26.0     0     0  7.9250        S
## 4        1      1 female 35.0     1     0 53.1000        S
## 5        0      3   male 35.0     0     0  8.0500        S
## 6        0      3   male 29.7     0     0  8.4583        Q
summary(titanic)
##     Survived          Pclass          Sex           Age       
##  Min.   :0.0000   Min.   :1.000   female:312   Min.   : 0.40  
##  1st Qu.:0.0000   1st Qu.:2.000   male  :577   1st Qu.:22.00  
##  Median :0.0000   Median :3.000                Median :29.70  
##  Mean   :0.3825   Mean   :2.312                Mean   :29.65  
##  3rd Qu.:1.0000   3rd Qu.:3.000                3rd Qu.:35.00  
##  Max.   :1.0000   Max.   :3.000                Max.   :80.00  
##      SibSp            Parch             Fare         Embarked
##  Min.   :0.0000   Min.   :0.0000   Min.   :  0.000   C:168   
##  1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:  7.896   Q: 77   
##  Median :0.0000   Median :0.0000   Median : 14.454   S:644   
##  Mean   :0.5242   Mean   :0.3825   Mean   : 32.097           
##  3rd Qu.:1.0000   3rd Qu.:0.0000   3rd Qu.: 31.000           
##  Max.   :8.0000   Max.   :6.0000   Max.   :512.329
  1. Use R to count the total number of passengers on board the Titanic.
dim(titanic)
## [1] 889   8

Here, we see that there are 889 total entries which includes details of all the onboard passangers. Hence, total number of passangers onboard = 889.

  1. Use R to count the number of passengers who survived the sinking of the Titanic.
ttable <- with(titanic, table(titanic$Survived))
ttable
## 
##   0   1 
## 549 340

Here, 1= survived and 0= not servived. Hence there were 340 passangers who survived sinking of Titanic.

  1. Use R to measure the percentage of passengers who survived the sinking of the Titanic.
cent_ser <-prop.table(ttable)*100
cent_ser
## 
##        0        1 
## 61.75478 38.24522

Here, there were 38.24% passangers survived sinking of Titanic.

  1. Use R to count the number of first-class passengers who survived the sinking of the Titanic.
ttable2 <- xtabs(~ titanic$Survived+titanic$Pclass, data=titanic)
ttable2
##                 titanic$Pclass
## titanic$Survived   1   2   3
##                0  80  97 372
##                1 134  87 119
ttable2[2]
## [1] 134

Number of First class passangers survived are 134.

  1. Use R to measure the percentage of first-class passengers who survived the sinking of the Titanic.
first_cent_ser <-prop.table(ttable2)*100
first_cent_ser
##                 titanic$Pclass
## titanic$Survived         1         2         3
##                0  8.998875 10.911136 41.844769
##                1 15.073116  9.786277 13.385827

Out of total passangers, 15.07% first class passangers were survived. This is highest survival rate among all the classes.

  1. Use R to count the number of females from First-Class who survived the sinking of the Titanic
ttable3 <- xtabs(~ titanic$Survived+titanic$Pclass+titanic$Sex, data=titanic)
ftable(ttable3)
##                                 titanic$Sex female male
## titanic$Survived titanic$Pclass                        
## 0                1                               3   77
##                  2                               6   91
##                  3                              72  300
## 1                1                              89   45
##                  2                              70   17
##                  3                              72   47

89 were female first class surivers.

  1. Use R to measure the percentage of survivors who were female
ttable4 <- xtabs(~ titanic$Survived + titanic$Sex,data=titanic)
ttable4
##                 titanic$Sex
## titanic$Survived female male
##                0     81  468
##                1    231  109

Totla 231 females survived.

  1. Use R to measure the percentage of females on board the Titanic who survived
prop.table(ttable4,2)*100
##                 titanic$Sex
## titanic$Survived   female     male
##                0 25.96154 81.10919
##                1 74.03846 18.89081

74.03% of females who boarded Titanic survived.

  1. 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(ttable4)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  ttable4
## X-squared = 258.43, df = 1, p-value < 2.2e-16

This test suggests that wather passanger will survive or not it will depend upon the gender of the survivor. P value is less than the acceptable P(<0.05), hence, this relationship is significant.