setwd("C:/Users/Jaswanth/Downloads")
titanic.df<-read.csv(paste("Titanic Data.csv",sep = ""))
View(titanic.df)
dim(titanic.df)
## [1] 889 8
889
sum(titanic.df$Survived[titanic.df$Survived==1])
## [1] 340
titanictable<-table(titanic.df$Survived)
titanictable
##
## 0 1
## 549 340
prop.table(titanictable)*100
##
## 0 1
## 61.75478 38.24522
firstclass<-xtabs(~Survived+Pclass,data=titanic.df)
firstclass
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
prop.table(firstclass,2)*100
## Pclass
## Survived 1 2 3
## 0 37.38318 52.71739 75.76375
## 1 62.61682 47.28261 24.23625
femfirstclass<-xtabs(~Survived+Sex+Pclass,data=titanic.df)
femfirstclass
## , , Pclass = 1
##
## Sex
## Survived female male
## 0 3 77
## 1 89 45
##
## , , Pclass = 2
##
## Sex
## Survived female male
## 0 6 91
## 1 70 17
##
## , , Pclass = 3
##
## Sex
## Survived female male
## 0 72 300
## 1 72 47
female<-xtabs(~Survived+Sex,data=titanic.df)
female
## Sex
## Survived female male
## 0 81 468
## 1 231 109
prop.table(female,1)*100
## Sex
## Survived female male
## 0 14.75410 85.24590
## 1 67.94118 32.05882
female
## Sex
## Survived female male
## 0 81 468
## 1 231 109
prop.table(female,2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
ptable<-xtabs(~Survived+Sex,data=titanic.df)
ptable
## Sex
## Survived female male
## 0 81 468
## 1 231 109
chisq.test(ptable)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: ptable
## X-squared = 258.43, df = 1, p-value < 2.2e-16
p value is lesser so hence dependent