library(readr) library(AER) Titanic_2 <- read_csv("https://stanford.io/2O9RUCF")[,-3] colnames(Titanic_2) = c("Survived", "Class", "Sex", "Age", "Siblings", "Parents", "Fare") # estimate both densities and save the outcomes to `dens_age_surv` and `dens_age_died` # plot both densites together # estimate both densities and save the outcomes to `dens_age_surv` and `dens_age_died` dens_age_surv <- density(Titanic_2$Age[Titanic_2$Survived==1]) dens_age_died <- density(Titanic_2$Age[Titanic_2$Survived==0]) # plot both densites together plot(dens_age_surv, ylim = c(0, 0.035), col = "darkgreen", lwd = 1.5, main = "Density Estimates of \'Age\'") lines(dens_age_died, col = "darkred", lwd = 1.5) legend(legend = c("Survived", "Died"), x ="topright", col = c("darkgreen", "darkred"), lwd = 1.5) test_predefined_objects("Titanic_2") test_object("dens_age_surv") test_object("dens_age_died") test_function("plot", args = "x") test_function("lines", args = "x") success_msg("Nice! Notice that although both distribution seem to be quite similar, a difference is that a larger proportion of the surivors were children. Thus the passengers evidently made an attempt to save children by giving them a place on the life rafts.")