->reading the file

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

->viewing the dataframe

View(titanic.df)

->the column survived indicates two variables (0 and 1) implying 0= not suvived , 1= survived

3a) total number of passengers on board the titanic

mytable <- with (data=titanic.df,table(Survived)) 
addmargins(mytable)
## Survived
##   0   1 Sum 
## 549 340 889

3b) number of passengers who survived

table(titanic.df$Survived)
## 
##   0   1 
## 549 340

3c) percentage of passengers who survived

prop.table(mytable)*100
## Survived
##        0        1 
## 61.75478 38.24522

3d) number of first class passengers who survived

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

3e) percentage of first class passengers who survived

prop.table(mytable,1)*100
##       Survived
## Pclass        0        1
##      1 37.38318 62.61682
##      2 52.71739 47.28261
##      3 75.76375 24.23625

3f) number of females from first class who survived

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

3g)percentage of survivors who wre females

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

3h) percentageof females who survived

prop.table(mytable,1)*100
##         Survived
## Sex             0        1
##   female 25.96154 74.03846
##   male   81.10919 18.89081

3i)chi-squared test

mytable <- xtabs(~Sex +Survived , data=titanic.df)
addmargins(mytable)
##         Survived
## Sex        0   1 Sum
##   female  81 231 312
##   male   468 109 577
##   Sum    549 340 889
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

-> from the chi-squared test it is clear that the p valve (p<0.05) is less indicating that the null hypothesis is being rejected -> concluding at there is a proportinate difference between the females on board who survived and the males on board who survived

prop.table(mytable,1) 
##         Survived
## Sex              0         1
##   female 0.2596154 0.7403846
##   male   0.8110919 0.1889081

->proportion of females who survived is higher than proportion of males who survived