Titanic

Survival statistics

Up to now we have illustrated toy examples, in this section we will analyze a more substantial dataframe to show differences in survivals rates in the sinking of the ocean liner “Titanic”.

Create the titanic dataframe from the CVS file titanic.csv.

make "titanic (csv.read "titanic.csv [num char char char])

The variable “survived” is coded: “1” if survived, “0” if not; class – passengers class or crew – is coded “First”, “Second”, “Third” and “Crew”; sex “F” or “M”; age “Child” or “Adult”.

We consider in this analysis only adults – there where no children in the ship’s crew – dropping from the dataframe 109 cases.

make "Adult df.select.rows :titanic "age "Adult

Show its structure:

df.struct :Adult 
dataframe: 2092 observations, 4 variables
survived (num): 1 1 1 1 1 1 1 1 1 1 ...
age (char): "Adult" "Adult" "Adult" "Adult" "Adult" "Adult" "Adult" "Adult" "Adult" "Adult" ...
sex (char): "M" "M" "M" "M" "M" "M" "M" "M" "M" "M" ...
class (char): "First" "First" "First" "First" "First" "First" "First" "First" "First" "First" ...

74,35% of the female adults survived compared to 20,28% of the males.

df.print (df.delete.variables (df.map (df.select.variables (st.summary :Adult  "survived [sex] [char]) [sex mean]) [product ? 100] [mean] "%) [mean])
% survival by sex
         sex            %
      <char>        <num>
           F        74.35
           M        20.28

This sizable difference persists qualitatively when one considers survival percentages by sex and class.

df.print df.sort (df.delete.variables (df.map (df.select.variables (st.summary :Adult  "survived [sex class] [char char]) [sex class mean]) [product ? 100] [mean] "%) [mean]) [class sex]
% survival by sex and class
         sex        class            %
     <char>       <char>        <num>
           F         Crew        86.96
           M         Crew        22.27
           F        First        97.22
           M        First        32.57
           F       Second        86.02
           M       Second         8.33
           F        Third        46.06
           M        Third        16.23