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("Titanic Data.csv")
View(titanic)

Including Plots

You can also embed plots, for example:

## [1] 889
sum(titanic$Survived)
## [1] 340
mean(titanic$Survived)
## [1] 0.3824522
mytable <- xtabs(~Survived+Pclass,data = titanic)
ftable(mytable)
##          Pclass   1   2   3
## Survived                   
## 0                80  97 372
## 1               134  87 119
ftable(mytable)[2]
## [1] 134
prop.table(mytable,2)
##         Pclass
## Survived         1         2         3
##        0 0.3738318 0.5271739 0.7576375
##        1 0.6261682 0.4728261 0.2423625
prop.table(mytable,2)[1]
## [1] 0.3738318
mytable2 <- xtabs(~Survived+Sex+Pclass,data = titanic)
ftable(mytable2)
##                 Pclass   1   2   3
## Survived Sex                      
## 0        female          3   6  72
##          male           77  91 300
## 1        female         89  70  72
##          male           45  17  47
ftable(mytable2)[3]#no of females in firstclass who survived
## [1] 89
mytable3 <- xtabs(~Survived+Sex,data = titanic)
ftable(mytable3)
##          Sex female male
## Survived                
## 0                81  468
## 1               231  109
prop.table(mytable3,1)
##         Sex
## Survived    female      male
##        0 0.1475410 0.8524590
##        1 0.6794118 0.3205882
prop.table(mytable3,1)[2]*100#percentage of survivors who were female
## [1] 67.94118
prop.table(mytable,2)
##         Pclass
## Survived         1         2         3
##        0 0.3738318 0.5271739 0.7576375
##        1 0.6261682 0.4728261 0.2423625
prop.table(mytable3,2)[2]*100#percentage of females who were survivors
## [1] 74.03846
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

Note that the p value << 0.05.so we reject the null hypotesis which we assume to take that Survived and sex are independent.so no of females survived is greater than the number of males survived that is the hypotesis is correct.