setwd(“C:/Office”) Titanic.df<- read.csv(paste(“Titanic Data.csv”, sep=“”)) table(Titanic.df$Survived)
0 1 549 340 > prop.table(table(Titanic.df$Survived))
0 1
0.6175478 0.3824522 > xtabs(~Survived+Pclass, data=Titanic.df) Pclass Survived 1 2 3 0 80 97 372 1 134 87 119 > prop.table(table(Titanic.df$Pclass))
1 2 3
0.2407199 0.2069741 0.5523060 > prop.table(xtabs(~Survived+Pclass, data=Titanic.df)) Pclass Survived 1 2 3 0 0.08998875 0.10911136 0.41844769 1 0.15073116 0.09786277 0.13385827 > prop.table(xtabs(~Survived+Pclass+Sex, data=Titanic.df)) , , Sex = female
Pclass
Survived 1 2 3 0 0.003374578 0.006749156 0.080989876 1 0.100112486 0.078740157 0.080989876
, , Sex = male
Pclass
Survived 1 2 3 0 0.086614173 0.102362205 0.337457818 1 0.050618673 0.019122610 0.052868391
xtabs(~Survived+Pclass+Sex, data=Titanic.df) , , 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
xtabs(~Survived+Sex, data=Titanic.df) Sex Survived female male 0 81 468 1 231 109 prop.table(xtabs(~Survived+Sex, data=Titanic.df)) Sex Survived female male 0 0.09111361 0.52643420 1 0.25984252 0.12260967 addmargins(prop.table(xtabs(~Survived+Sex, data=Titanic.df))) Sex Survived female male Sum 0 0.09111361 0.52643420 0.61754781 1 0.25984252 0.12260967 0.38245219 Sum 0.35095613 0.64904387 1.00000000 chisq.test(prop.table(xtabs(~Survived+Sex, data=Titanic.df)))
Pearson's Chi-squared test with Yates' continuity correction
data: prop.table(xtabs(~Survived + Sex, data = Titanic.df)) X-squared = 5.7395e-33, df = 1, p-value = 1
Warning message: In chisq.test(prop.table(xtabs(~Survived + Sex, data = Titanic.df))) : Chi-squared approximation may be incorrect