read.csv('Titanic Data.csv')
getwd()
## [1] "C:/Users/Vimal/Desktop/Vimal/Dr. Sameer Mathur/Assignment"
titanicdata.df<-read.csv('Titanic Data.csv')
View(titanicdata.df)
dim(titanicdata.df)
## [1] 889 8
No. of passengers: 889
sum(titanicdata.df$Survived==1)
## [1] 340
No.of passengers survived= 340
table=with(titanicdata.df,table(Survived))
prop.table(table)*100
## Survived
## 0 1
## 61.75478 38.24522
% of survived = 38.24522
xyz <- xtabs(~ Survived+Pclass, data=titanicdata.df)
xyz
## Pclass
## Survived 1 2 3
## 0 80 97 372
## 1 134 87 119
134 first class survived
prop.table(xyz,2)*100
## Pclass
## Survived 1 2 3
## 0 37.38318 52.71739 75.76375
## 1 62.61682 47.28261 24.23625
62.61682% of first class people survived
xy <- xtabs(~ Survived+Pclass+Sex, data=titanicdata.df)
xy
## , , 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
prop.table(xy,1)*100
## , , Sex = female
##
## Pclass
## Survived 1 2 3
## 0 0.5464481 1.0928962 13.1147541
## 1 26.1764706 20.5882353 21.1764706
##
## , , Sex = male
##
## Pclass
## Survived 1 2 3
## 0 14.0255009 16.5755920 54.6448087
## 1 13.2352941 5.0000000 13.8235294
a <- xtabs(~ Survived+Sex, data=titanicdata.df)
prop.table(a,2)*100
## Sex
## Survived female male
## 0 25.96154 81.10919
## 1 74.03846 18.89081
b <- xtabs(~Survived+Sex, data=titanicdata.df)
b
## Sex
## Survived female male
## 0 81 468
## 1 231 109
chisq.test(b)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: b
## X-squared = 258.43, df = 1, p-value < 2.2e-16