Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Matlab: part of table showing below, how to answer question c, d ? row.names pclass 1 1st 2 1st 3 1st 4 1st 5 1st
Matlab: part of table showing below, how to answer question c, d ?
row.names pclass 1 1st 2 1st 3 1st 4 1st 5 1st 6 1st 7 1st 8 1st 9 1st 10 1st 11 1st 12 1st 13 1st 14 1st 15 1st 16 1st 17 1st 18 1st 19 1st 20 1st 21 1st 22 1st 23 1st 24 1st 25 1st 26 1st 27 1st 28 1st 29 1st 30 1st 31 1st 32 1st 33 1st 34 1st 35 1st 36 1st survived name age embarked home.dest room ticket boat sex 1 Allen, Miss 29 Southamp St Louis, MB-5 24160 L22 2 fema O Allison, Mis 2 Southamp Montreal, IC26 fema O Allison, Mr 30 Southamp Montreal, IC26 - 135 male O Allison, Mr 25 Southamp Montreal, IC26 fema 1 Allison, Ma 0.9167 Southamp Montreal, iC22 11 male 1 Anderson, 47 Southamp New York, E-12 3 male 1 Andrews, 63 Southamp Hudson, ND-7 13502 L77 10 fema 0 Andrews, 39 Southamp Belfast, NI A-36 male 1 Appleton, 58 Southamp Bayside, QC-101 2 fema 0 Artagaveyt 71 Cherbourg Montevideo, Uruguay -22 male 0 Astor, Colc 47 Cherbourg New York, NY 17754 L22 - 124 male 1 Astor, Mrs 19 Cherbourg New York, NY 17754 L22 4 fema 1 Aubert, Mr NA Cherbourg Paris, Fran B-35 17477 169 9 fema 1 Barkworth, NA Southamp Hessle, YoIA-23 male O Baumann, NA Southamp New York, NY male 1 Baxter, Mrs 50 Cherbourg Montreal, IB-58/60 6 fema O Baxter, Mr 24 Cherbourg Montreal, IB-58/60 male O Beattie, Mr 36 Cherbourg Winnipeg, C-6 male 1 Beckwith, 37 Southamp New York, D-35 5 male 1 Beckwith, 47 Southamp New York, D-35 5 fema 1 Behr, Mr K 26 Cherbourg New York, C-148 5 male O Birnbaum, 25 Cherbourg San Francisco, CA - 148 male 1 Bishop, Mr 25 Cherbourg Dowagiac, B-49 7 male 1 Bishop, Mr 19 Cherbourg Dowagiac, B-49 7 fema 1 Bjornstrm- 28 Southamp Stockholm, Sweden / D male O Blackwell, I 45 Southamp Trenton, NJ -241 male 1 Blank, Mr 39 Cherbourg Glen Ridge A-31 1 Bonnell, M 30 Southamp Youngstov C-7 8 fema 1 Bonnell, M 58 Southamp Birkdale, Ei C-103 8 fema O Borebank, NA Southamp London / \D-21/2 male 1 Bowen, Mi 45 Cherbourg Cooperstown, NY 4 fema 1 Bowerman 22 Southamp St Leonards-on-Sea, England O 6 fema 1 Bradley, MNA Southamp Los Angeles, CA 15 male O Brady, Mr. 41 Southamp Pomeroy, WA male O Brandeis, 48 Cherbour Omaha, NE 17591 L50 -208 male O Brewe, Dr NA Cherbourg Philadelphia, PA male 7 male Exercise 2 The file "titanic.csv" records information about the passengers that travelled on the Titanic the day it sank. The variable name pclass is the class of the room booked on the boat (first class is the most expensive and luxurious, third class is the least). The variable embarked is the city the passenger embarked. The other variable names of this dataset are self-explanatory. You will organize your program with a pipeline/workflow style. a) Write a function import_data() that imports the CSV file named "titanic.csv" as a table and converts its variables to the appropriate type. Although it is categorical, set the variable survived to a double because this will be more convenient for the next questions. b) Is there any missing data in the whole dataset? What is the number and proportion of missing data in the age variable? In the embarked variable? c) Identify outliers, if any. d) Write a function survival (dat) that returns a table that calculates the proportion of passengers that survived by sex and class (use unstack()). e) Write a function plot survival that plots a bar chart that illustrates your result from the previous section. Generate this plot (your figure should be similar to Figure 1). f) The CSV file "is-canada.csv" identifies with a binary variable (0/1) if the home_dest variable mentions any Canadian city (either as home or destination). Join this information to the main data set, such that you add an 11th variable to the titanic table, named country, that will take either the value "Canada" if the the passenger's home_dest variable is related to Canada, or "other" else. g) Plot the survival bar chart by sex and class (using plot survival()) only for the passengers that have been identified being related to Canada (as per their home_dest value). row.names pclass 1 1st 2 1st 3 1st 4 1st 5 1st 6 1st 7 1st 8 1st 9 1st 10 1st 11 1st 12 1st 13 1st 14 1st 15 1st 16 1st 17 1st 18 1st 19 1st 20 1st 21 1st 22 1st 23 1st 24 1st 25 1st 26 1st 27 1st 28 1st 29 1st 30 1st 31 1st 32 1st 33 1st 34 1st 35 1st 36 1st survived name age embarked home.dest room ticket boat sex 1 Allen, Miss 29 Southamp St Louis, MB-5 24160 L22 2 fema O Allison, Mis 2 Southamp Montreal, IC26 fema O Allison, Mr 30 Southamp Montreal, IC26 - 135 male O Allison, Mr 25 Southamp Montreal, IC26 fema 1 Allison, Ma 0.9167 Southamp Montreal, iC22 11 male 1 Anderson, 47 Southamp New York, E-12 3 male 1 Andrews, 63 Southamp Hudson, ND-7 13502 L77 10 fema 0 Andrews, 39 Southamp Belfast, NI A-36 male 1 Appleton, 58 Southamp Bayside, QC-101 2 fema 0 Artagaveyt 71 Cherbourg Montevideo, Uruguay -22 male 0 Astor, Colc 47 Cherbourg New York, NY 17754 L22 - 124 male 1 Astor, Mrs 19 Cherbourg New York, NY 17754 L22 4 fema 1 Aubert, Mr NA Cherbourg Paris, Fran B-35 17477 169 9 fema 1 Barkworth, NA Southamp Hessle, YoIA-23 male O Baumann, NA Southamp New York, NY male 1 Baxter, Mrs 50 Cherbourg Montreal, IB-58/60 6 fema O Baxter, Mr 24 Cherbourg Montreal, IB-58/60 male O Beattie, Mr 36 Cherbourg Winnipeg, C-6 male 1 Beckwith, 37 Southamp New York, D-35 5 male 1 Beckwith, 47 Southamp New York, D-35 5 fema 1 Behr, Mr K 26 Cherbourg New York, C-148 5 male O Birnbaum, 25 Cherbourg San Francisco, CA - 148 male 1 Bishop, Mr 25 Cherbourg Dowagiac, B-49 7 male 1 Bishop, Mr 19 Cherbourg Dowagiac, B-49 7 fema 1 Bjornstrm- 28 Southamp Stockholm, Sweden / D male O Blackwell, I 45 Southamp Trenton, NJ -241 male 1 Blank, Mr 39 Cherbourg Glen Ridge A-31 1 Bonnell, M 30 Southamp Youngstov C-7 8 fema 1 Bonnell, M 58 Southamp Birkdale, Ei C-103 8 fema O Borebank, NA Southamp London / \D-21/2 male 1 Bowen, Mi 45 Cherbourg Cooperstown, NY 4 fema 1 Bowerman 22 Southamp St Leonards-on-Sea, England O 6 fema 1 Bradley, MNA Southamp Los Angeles, CA 15 male O Brady, Mr. 41 Southamp Pomeroy, WA male O Brandeis, 48 Cherbour Omaha, NE 17591 L50 -208 male O Brewe, Dr NA Cherbourg Philadelphia, PA male 7 male Exercise 2 The file "titanic.csv" records information about the passengers that travelled on the Titanic the day it sank. The variable name pclass is the class of the room booked on the boat (first class is the most expensive and luxurious, third class is the least). The variable embarked is the city the passenger embarked. The other variable names of this dataset are self-explanatory. You will organize your program with a pipeline/workflow style. a) Write a function import_data() that imports the CSV file named "titanic.csv" as a table and converts its variables to the appropriate type. Although it is categorical, set the variable survived to a double because this will be more convenient for the next questions. b) Is there any missing data in the whole dataset? What is the number and proportion of missing data in the age variable? In the embarked variable? c) Identify outliers, if any. d) Write a function survival (dat) that returns a table that calculates the proportion of passengers that survived by sex and class (use unstack()). e) Write a function plot survival that plots a bar chart that illustrates your result from the previous section. Generate this plot (your figure should be similar to Figure 1). f) The CSV file "is-canada.csv" identifies with a binary variable (0/1) if the home_dest variable mentions any Canadian city (either as home or destination). Join this information to the main data set, such that you add an 11th variable to the titanic table, named country, that will take either the value "Canada" if the the passenger's home_dest variable is related to Canada, or "other" else. g) Plot the survival bar chart by sex and class (using plot survival()) only for the passengers that have been identified being related to Canada (as per their home_dest value)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started