This is an analysis of titanic Data:
#Task 2b
setwd("C:/Users/Dixit/iim_internship")
Titanic <- read.csv("Titanic_Data.csv")
View(Titanic)
#Task 3a
nrow(Titanic)
## [1] 889
#Task 3b
length(Titanic$Survived[Titanic$Survived == "1"])
## [1] 340
#Task 3c
surivivedpercentage=length(Titanic$Survived[Titanic$Survived == "1"])*100/nrow(Titanic)
surivivedpercentage
## [1] 38.24522
#Task 3d
firstClassPassengers = xtabs(~Pclass + Survived,Titanic)
firstClassPassengers[1,2]
## [1] 134
#Task 3e
percentagesurivivedsinking = prop.table(firstClassPassengers)
percentagesurivivedsinking[1,2]*100
## [1] 15.07312
#Task 3f
firstClassSurvivedFemalePassengers = xtabs(~Pclass + Survived + Sex,Titanic)
firstClassSurvivedFemalePassengers[1,2,1]
## [1] 89
#Task 3g
survivedfemalepassengers= xtabs(~Survived + Sex, Titanic)
survivedfemalepassengers[2,1]/length(Titanic$Survived[Titanic$Survived == "1"])*100
## [1] 67.94118
#Task 3h
prop.table(survivedfemalepassengers,2)
## Sex
## Survived female male
## 0 0.2596154 0.8110919
## 1 0.7403846 0.1889081
val = prop.table(survivedfemalepassengers,2)
val[2,1]*100
## [1] 74.03846
#Task 3i
Chisquarehypothesis = table(Titanic$Survived, Titanic$Sex)
chisq.test(Chisquarehypothesis)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: Chisquarehypothesis
## X-squared = 258.43, df = 1, p-value < 2.2e-16