Coursera Assignment Pitch: Titanic

Kirsty

Introduction

The data used in the application is from the “Titanic” dataset in R: it is pre-loaded, containing the following:

, , Age = Child, Survived = No

      Sex
Class  Male Female
  1st     0      0
  2nd     0      0
  3rd    35     17
  Crew    0      0

, , Age = Adult, Survived = No

      Sex
Class  Male Female
  1st   118      4
  2nd   154     13
  3rd   387     89
  Crew  670      3

, , Age = Child, Survived = Yes

      Sex
Class  Male Female
  1st     5      1
  2nd    11     13
  3rd    13     14
  Crew    0      0

, , Age = Adult, Survived = Yes

      Sex
Class  Male Female
  1st    57    140
  2nd    14     80
  3rd    75     76
  Crew  192     20

Explanation

The app requires an age, gender and class that the person was traveling.It then does the following:

  • Generates a random probability (number between 0 and 1)

  • Compares this against the survival rate for the filtered inputs

  • Generates a outcome on survival or otherwise.

The app also includes a basic plot of the relationship between survival and sex, along with class traveled, giving an indication of what the likely outcome will be based on the input data.

Analysis

Below is the brief comparison taking place in the app, using some generated data for a male crew member:

titanic <- as_tibble(Titanic)
titanic$Survived <- factor(titanic$Survived)
rand_prob <- runif(1, min = 0, max = 1)
survive_prob <- filter(titanic, Class == "Crew" , Sex == "Male", Age == "Adult") %>%
    group_by(Survived) %>%  # use Survived first
    summarise(sum_n = sum(n)) %>%  # make helper to aggregate group n's
    mutate(ratio_survived_each_class = sum_n/sum(sum_n)) %>% 
    subset(Survived == "Yes") %>% pull(ratio_survived_each_class)

if(rand_prob > survive_prob) {"You're dead"} else {"You made it!"}
[1] "You're dead"

Improvements

Potential improvements to the app would be:

  1. improving the plot to be dynamic

  2. include some graphics/imagery with the output