Load data
mydata <- read.csv("C:/Users/ajste/Downloads/train.csv")
Count missing observations
colSums(mydata == "" | is.na(mydata))
## PassengerId Survived Pclass Name Sex Age
## 0 0 0 0 0 177
## SibSp Parch Ticket Fare Cabin Embarked
## 0 0 0 0 687 2
Impute missing observations
mydata$Age[is.na(mydata$Age)] <- median(mydata$Age, na.rm=TRUE)
mydata$SibSp[is.na(mydata$SibSp)] <- median(mydata$SibSp, na.rm=TRUE)
mydata$Parch[is.na(mydata$Parch)] <- median(mydata$Parch, na.rm=TRUE)
Install and invoke psych package
installed.packages("psych")
## Package LibPath Version Priority Depends Imports LinkingTo Suggests
## Enhances License License_is_FOSS License_restricts_use OS_type Archs
## MD5sum NeedsCompilation Built Published
library(psych)
Summary of statistics
describe(mydata$Age)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 891 29.36 13.02 28 28.83 8.9 0.42 80 79.58 0.51 0.97 0.44
describe(mydata$SibSp)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 891 0.52 1.1 0 0.27 0 0 8 8 3.68 17.73 0.04
describe(mydata$Parch)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 891 0.38 0.81 0 0.18 0 0 6 6 2.74 9.69 0.03
Create table of survival by sex and boxplot of survival by age
table(mydata$Survived, mydata$Sex)
##
## female male
## 0 81 468
## 1 233 109
boxplot(mydata$Age~mydata$Survived, notch=TRUE, horizontal=T)
Question 1a: What are the types of variable and levels of measurement for PassengerId and Age?
PassengerId, despite being a number, is a qualitative variable as it is solely used to identify the passenger and does not represent a numerical quantity. Its level of measurement is nominal as it has no implied ordering. Age, unlike PassengerId, represents a numerical value and is therefore a quantitative variable. Specifically, it is classified as a ratio variable because it is being collected as exact values on a continuous scale and can be compared using division.
Question 1b: Which variable has the most missing observations?
The variable that has the most missing observations is the cabin number at 687 NA values, with age and port of embarkation trailing behind at 177 and 2 NA values respectively.
Question 3: Please comment on what you observe from the summary statistics.
There is a wide range of ages amongst the passengers with the youngest passenger being just 0.42 years of age and the most elderly being 80 years old. The large standard deviation of 13.02 shows that there is a significant dispersion of ages among the passengers and that there is not a large concentration of passengers around the median age with a few outliers. The opposite is true for the number of siblings, spouses, parents, and children. The majority of passengers traveled with 0 family members with the data highly skewed to the right by a few larger families.
Question 4: What do you notice in the cross-tabulation of Survived and Sex?
Despite male passengers outnumbering female passengers 577 to 314, the majority of survivors were female (233 female survivors to 109 male survivors). About 74.2% of female passengers survived compared to only around 18.9% of male passengers.
Question 5: What do you notice about the notched boxplots for Survived and Age?
The median age for those that survived and those that did not is nearly identical however the quartiles and whiskers are significantly narrower for the non-surviving group, most notably the younger quartile of the surviving group. There are also more outliers amongst those who did not survive, likely due to the increased vulnerability of the very young and very old to the extreme conditions during the disaster. These results, as well as the ones from the table comparing sex and survivorship, align with the concept of “women and children first” during emergency evacuations.