R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

View(tit.df)

Number of passengers on board =889

dim(tit.df)
## [1] 889   8
mytable <- with(tit.df, table(Survived))
mytable 
## Survived
##   0   1 
## 549 340

The number of passengers who survived the sinking of the Titanic =340

prop.table(mytable)
## Survived
##         0         1 
## 0.6175478 0.3824522

The percentage of passengers who survived the sinking of the Titanic = .3824522

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

The number of first-class passengers who survived the sinking of the Titanic = 134

prop.table(mytable1, 2)
##         Pclass
## Survived         1         2         3
##        0 0.3738318 0.5271739 0.7576375
##        1 0.6261682 0.4728261 0.2423625

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

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

The number of females from First-Class who survived the sinking of the Titanic =89

mytable3<-margin.table(mytable2, c(1,3))
mytable3
##         Sex
## Survived female male
##        0     81  468
##        1    231  109
prop.table(mytable3, 1)*100
##         Sex
## Survived   female     male
##        0 14.75410 85.24590
##        1 67.94118 32.05882

The percentage of survivors who were female= 67.94118 %

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

The percentage of females on board the Titanic who survived= 74.03%

chisq.test(mytable3)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  mytable3
## X-squared = 258.43, df = 1, p-value < 2.2e-16

The p-values are the probability of obtaining the sampled results, assuming independence of the row and colum variables in the population. Since the probability is small (p <.05), we reject the Null hypothesis that sex and survival are independent.