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:

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

## 3a

mytable <- xtabs(~ SibSp+Parch, data=titanic)
mytable 
##      Parch
## SibSp   0   1   2   3   4   5   6
##     0 535  38  29   1   1   2   0
##     1 123  57  19   3   3   3   1
##     2  16   7   4   1   0   0   0
##     3   2   7   7   0   0   0   0
##     4   0   9   9   0   0   0   0
##     5   0   0   5   0   0   0   0
##     8   0   0   7   0   0   0   0
margin.table(mytable) 
## [1] 889
## 3b

mytable <- with(titanic, table(Survived))
mytable  
## Survived
##   0   1 
## 549 340
## 3c

prop.table(mytable) 
## Survived
##         0         1 
## 0.6175478 0.3824522
prop.table(mytable)*100 
## Survived
##        0        1 
## 61.75478 38.24522
## 3d

mytable <- xtabs(~ Pclass+Survived, data=titanic)
mytable 
##       Survived
## Pclass   0   1
##      1  80 134
##      2  97  87
##      3 372 119
margin.table(mytable)
## [1] 889
## 3e

prop.table(mytable, 1) 
##       Survived
## Pclass         0         1
##      1 0.3738318 0.6261682
##      2 0.5271739 0.4728261
##      3 0.7576375 0.2423625
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

mytable <- xtabs(~ Survived+Pclass+Sex, data=titanic)
mytable
## , , 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
## 3g

mytable <- xtabs(~ Sex+Survived, data=titanic)
mytable 
##         Survived
## Sex        0   1
##   female  81 231
##   male   468 109
margin.table(mytable) 
## [1] 889
prop.table(mytable, 1) 
##         Survived
## Sex              0         1
##   female 0.2596154 0.7403846
##   male   0.8110919 0.1889081
prop.table(mytable, 1)*100
##         Survived
## Sex             0        1
##   female 25.96154 74.03846
##   male   81.10919 18.89081
## 3i

mytable <- xtabs(~Survived+Sex, data=titanic)
addmargins(mytable)
##         Sex
## Survived female male Sum
##      0       81  468 549
##      1      231  109 340
##      Sum    312  577 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
## P-value is less than 0.5 Hence hypothesis checked.