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:

3a

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

3b

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

3c

prop.table(table(titanic.df$Survived))
## 
##         0         1 
## 0.6175478 0.3824522

3d

xtabs(Survived~ Pclass, data = titanic.df)
## Pclass
##   1   2   3 
## 134  87 119

3e

prop.table(xtabs(Survived~ Pclass, data = titanic.df))
## Pclass
##         1         2         3 
## 0.3941176 0.2558824 0.3500000

3f

xtabs(Survived~ Pclass+Sex, data = titanic.df)
##       Sex
## Pclass female male
##      1     89   45
##      2     70   17
##      3     72   47

3g

prop.table(xtabs(Survived~ Sex, data = titanic.df))
## Sex
##    female      male 
## 0.6794118 0.3205882

3h

 mytable <- xtabs(~ Survived+Sex, data = titanic.df)
 prop.table(addmargins(mytable),2)
##         Sex
## Survived     female       male        Sum
##      0   0.12980769 0.40554593 0.30877390
##      1   0.37019231 0.09445407 0.19122610
##      Sum 0.50000000 0.50000000 0.50000000

3i null hypotheis is proportion of female who survived is higher than the proportion of male who survived

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

since p< 0.01 we reject the null hypothesis that no. of people who are female and survived are independent.