Assignment 2 (10%)

[Gopal Narasimhaiah]

[DPO & 040703878]


Instructions

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. Review this website for more details on using R Markdown http://rmarkdown.rstudio.com.

Use RStudio for this assignment. Complete the assignment by inserting your R code wherever you see the string “#INSERT YOUR ANSWER HERE”.

When you click the Knit button, a document (PDF, Word, or HTML format) will be generated that includes both the assignment content as well as the output of any embedded R code chunks.

Submit both the rmd and generated output files. Failing to submit both files will be subject to mark deduction.

Sample Question and Solution

Use seq() to create the vector \((1,2,3,\ldots,20)\).

seq(1,20)
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

Question 1

The Titanic Passenger Survival Data Set provides information on the fate of passengers on the fatal maiden voyage of the ocean liner “Titanic.” The dataset is available from the Department of Biostatistics at the Vanderbilt University School of Medicine (https://biostat.app.vumc.org/wiki/pub/Main/DataSets/titanic3.csv)in several formats. store the Titanic Data Set titanic_train using the following commands.

#INSERT YOUR ANSWER HERE

titanicDataset <- read.csv(file = "https://biostat.app.vumc.org/wiki/pub/Main/DataSets/titanic3.csv", stringsAsFactors = F)
summary(titanicDataset)
##      pclass         survived         name               sex           
##  Min.   :1.000   Min.   :0.000   Length:1309        Length:1309       
##  1st Qu.:2.000   1st Qu.:0.000   Class :character   Class :character  
##  Median :3.000   Median :0.000   Mode  :character   Mode  :character  
##  Mean   :2.295   Mean   :0.382                                        
##  3rd Qu.:3.000   3rd Qu.:1.000                                        
##  Max.   :3.000   Max.   :1.000                                        
##                                                                       
##       age            sibsp            parch          ticket         
##  Min.   : 0.17   Min.   :0.0000   Min.   :0.000   Length:1309       
##  1st Qu.:21.00   1st Qu.:0.0000   1st Qu.:0.000   Class :character  
##  Median :28.00   Median :0.0000   Median :0.000   Mode  :character  
##  Mean   :29.88   Mean   :0.4989   Mean   :0.385                     
##  3rd Qu.:39.00   3rd Qu.:1.0000   3rd Qu.:0.000                     
##  Max.   :80.00   Max.   :8.0000   Max.   :9.000                     
##  NA's   :263                                                        
##       fare            cabin             embarked             boat          
##  Min.   :  0.000   Length:1309        Length:1309        Length:1309       
##  1st Qu.:  7.896   Class :character   Class :character   Class :character  
##  Median : 14.454   Mode  :character   Mode  :character   Mode  :character  
##  Mean   : 33.295                                                           
##  3rd Qu.: 31.275                                                           
##  Max.   :512.329                                                           
##  NA's   :1                                                                 
##       body        home.dest        
##  Min.   :  1.0   Length:1309       
##  1st Qu.: 72.0   Class :character  
##  Median :155.0   Mode  :character  
##  Mean   :160.8                     
##  3rd Qu.:256.0                     
##  Max.   :328.0                     
##  NA's   :1188
  1. Extract the columns sex, age, cabin and survived into a new data frame of the name ‘titanicSubset’.
#INSERT YOUR ANSWER HERE
titanicSubset <- titanicDataset[,c('sex','age','cabin' ,'survived')]
  1. Use the aggregate() function to display the total number of survivors grouped by sex
#INSERT YOUR ANSWER HERE
aggregate(titanicSubset$survived, by = list(titanicSubset$sex),FUN = sum)
##   Group.1   x
## 1  female 339
## 2    male 161
  1. Use the count() function in dplyr package to display the total number of passengers within each Ticket Class Pclass.
#INSERT YOUR ANSWER HERE

#count(titanicDataset,pclass)
  1. Answer the following graphically (using visualization):
  1. What was the survival rates for females and males?
  2. What was the age distribution on the Titanic?

Hint: You can use ggplot2

#INSERT YOUR ANSWER HERE

#D1
Male <- subset(titanicSubset,sex=="male")
Female <-subset(titanicSubset,sex=="female")
Slices <- c(sum(Male$survived),sum(Female$survived))
labels <- c("Male","Female")
pie(Slices, labels)

#D2
#Titanic <- ggplot(titanicSubset, aes(x=age)) + geom_density(alpha=.5)

e)Use the for loop and if control statements to list the women’s names, age 34 or more that emabrked from S (Southampton), on the Titanic.

#INSERT YOUR ANSWER HERE
for (i in 1:(length(titanicDataset$sex))){
  if (titanicDataset$age[i]>=34 & !
      is.na(titanicDataset$age[i])){print(titanicDataset$name[i])}
}
## [1] "Anderson, Mr. Harry"
## [1] "Andrews, Miss. Kornelia Theodosia"
## [1] "Andrews, Mr. Thomas Jr"
## [1] "Appleton, Mrs. Edward Dale (Charlotte Lamson)"
## [1] "Artagaveytia, Mr. Ramon"
## [1] "Astor, Col. John Jacob"
## [1] "Barkworth, Mr. Algernon Henry Wilson"
## [1] "Baxter, Mrs. James (Helene DeLaudeniere Chaput)"
## [1] "Beattie, Mr. Thomson"
## [1] "Beckwith, Mr. Richard Leonard"
## [1] "Beckwith, Mrs. Richard Leonard (Sallie Monypeny)"
## [1] "Bidois, Miss. Rosalie"
## [1] "Bissette, Miss. Amelia"
## [1] "Blackwell, Mr. Stephen Weart"
## [1] "Blank, Mr. Henry"
## [1] "Bonnell, Miss. Elizabeth"
## [1] "Borebank, Mr. John James"
## [1] "Bowen, Miss. Grace Scott"
## [1] "Brady, Mr. John Bertram"
## [1] "Brandeis, Mr. Emil"
## [1] "Brown, Mrs. James Joseph (Margaret Tobin)"
## [1] "Brown, Mrs. John Murray (Caroline Lane Lamson)"
## [1] "Bucknell, Mrs. William Robert (Emma Eliza Ward)"
## [1] "Burns, Miss. Elizabeth Margaret"
## [1] "Butt, Major. Archibald Willingham"
## [1] "Calderhead, Mr. Edward Pennington"
## [1] "Candee, Mrs. Edward (Helen Churchill Hungerford)"
## [1] "Cardeza, Mr. Thomas Drake Martinez"
## [1] "Cardeza, Mrs. James Warburton Martinez (Charlotte Wardle Drake)"
## [1] "Carter, Mr. William Ernest"
## [1] "Carter, Mrs. William Ernest (Lucile Polk)"
## [1] "Case, Mr. Howard Brown"
## [1] "Cavendish, Mr. Tyrell William"
## [1] "Cavendish, Mrs. Tyrell William (Julia Florence Siegel)"
## [1] "Chaffee, Mr. Herbert Fuller"
## [1] "Chaffee, Mrs. Herbert Fuller (Carrie Constance Toogood)"
## [1] "Chaudanson, Miss. Victorine"
## [1] "Chevre, Mr. Paul Romaine"
## [1] "Colley, Mr. Edward Pomeroy"
## [1] "Compton, Miss. Sara Rebecca"
## [1] "Compton, Mr. Alexander Taylor Jr"
## [1] "Compton, Mrs. Alexander Taylor (Mary Eliza Ingersoll)"
## [1] "Cornell, Mrs. Robert Clifford (Malvina Helen Lamson)"
## [1] "Crosby, Capt. Edward Gifford"
## [1] "Crosby, Miss. Harriet R"
## [1] "Crosby, Mrs. Edward Gifford (Catherine Elizabeth Halstead)"
## [1] "Cumings, Mr. John Bradley"
## [1] "Cumings, Mrs. John Bradley (Florence Briggs Thayer)"
## [1] "Daly, Mr. Peter Denis "
## [1] "Dodge, Dr. Washington"
## [1] "Dodge, Mrs. Washington (Ruth Vidaver)"
## [1] "Douglas, Mr. Walter Donald"
## [1] "Douglas, Mrs. Walter Donald (Mahala Dutton)"
## [1] "Duff Gordon, Lady. (Lucille Christiana Sutherland) (\"Mrs Morgan\")"
## [1] "Duff Gordon, Sir. Cosmo Edmund (\"Mr Morgan\")"
## [1] "Dulles, Mr. William Crothers"
## [1] "Endres, Miss. Caroline Louise"
## [1] "Eustis, Miss. Elizabeth Mussey"
## [1] "Evans, Miss. Edith Corse"
## [1] "Flynn, Mr. John Irwin (\"Irving\")"
## [1] "Fortune, Mr. Mark"
## [1] "Fortune, Mrs. Mark (Mary McDougald)"
## [1] "Frauenthal, Dr. Henry William"
## [1] "Frauenthal, Mr. Isaac Gerald"
## [1] "Frolicher-Stehli, Mr. Maxmillian"
## [1] "Frolicher-Stehli, Mrs. Maxmillian (Margaretha Emerentia Stehli)"
## [1] "Futrelle, Mr. Jacques Heath"
## [1] "Futrelle, Mrs. Jacques Heath (Lily May Peel)"
## [1] "Gee, Mr. Arthur H"
## [1] "Geiger, Miss. Amalie"
## [1] "Gibson, Mrs. Leonard (Pauline C Boeson)"
## [1] "Goldenberg, Mr. Samuel L"
## [1] "Goldschmidt, Mr. George B"
## [1] "Gracie, Col. Archibald IV"
## [1] "Graham, Mr. George Edward"
## [1] "Graham, Mrs. William Thompson (Edith Junkins)"
## [1] "Greenfield, Mrs. Leo David (Blanche Strouse)"
## [1] "Guggenheim, Mr. Benjamin"
## [1] "Harper, Mr. Henry Sleeper"
## [1] "Harper, Mrs. Henry Sleeper (Myna Haxtun)"
## [1] "Harris, Mr. Henry Birkhardt"
## [1] "Harris, Mrs. Henry Birkhardt (Irene Wallach)"
## [1] "Harrison, Mr. William"
## [1] "Hays, Mr. Charles Melville"
## [1] "Hays, Mrs. Charles Melville (Clara Jennings Gregg)"
## [1] "Head, Mr. Christopher"
## [1] "Hipkins, Mr. William Edward"
## [1] "Hippach, Mrs. Louis Albert (Ida Sophia Fischer)"
## [1] "Hogeboom, Mrs. John C (Anna Andrews)"
## [1] "Holverson, Mr. Alexander Oskar"
## [1] "Holverson, Mrs. Alexander Oskar (Mary Aline Towner)"
## [1] "Homer, Mr. Harry (\"Mr E Haven\")"
## [1] "Hoyt, Mr. Frederick Maxfield"
## [1] "Hoyt, Mrs. Frederick Maxfield (Jane Anne Forby)"
## [1] "Icard, Miss. Amelie"
## [1] "Isham, Miss. Ann Elizabeth"
## [1] "Ismay, Mr. Joseph Bruce"
## [1] "Jones, Mr. Charles Cresson"
## [1] "Julian, Mr. Henry Forbes"
## [1] "Kent, Mr. Edward Austin"
## [1] "Kenyon, Mr. Frederick R"
## [1] "Kimball, Mr. Edwin Nelson Jr"
## [1] "Kimball, Mrs. Edwin Nelson Jr (Gertrude Parsons)"
## [1] "Kreuchen, Miss. Emilie"
## [1] "Leader, Dr. Alice (Farnham)"
## [1] "Lesurer, Mr. Gustave J"
## [1] "Lindeberg-Lind, Mr. Erik Gustaf (\"Mr Edward Lingrey\")"
## [1] "Lindstrom, Mrs. Carl Johan (Sigrid Posse)"
## [1] "Lines, Mrs. Ernest H (Elizabeth Lindsey James)"
## [1] "Lurette, Miss. Elise"
## [1] "McCaffry, Mr. Thomas Francis"
## [1] "McCarthy, Mr. Timothy J"
## [1] "McGough, Mr. James Robert"
## [1] "Millet, Mr. Francis Davis"
## [1] "Minahan, Dr. William Edward"
## [1] "Minahan, Mrs. William Edward (Lillian E Thorpe)"
## [1] "Molson, Mr. Harry Markland"
## [1] "Moore, Mr. Clarence Bloomfield"
## [1] "Natsch, Mr. Charles H"
## [1] "Newell, Mr. Arthur Webster"
## [1] "Nicholson, Mr. Arthur Ernest"
## [1] "Oliva y Ocana, Dona. Fermina"
## [1] "Ostby, Mr. Engelhart Cornelius"
## [1] "Partner, Mr. Austen"
## [1] "Peuchen, Major. Arthur Godfrey"
## [1] "Porter, Mr. Walter Chamberlain"
## [1] "Potter, Mrs. Thomas Jr (Lily Alexenia Wilson)"
## [1] "Reuchlin, Jonkheer. John George"
## [1] "Robert, Mrs. Edward Scott (Elisabeth Walton McMillan)"
## [1] "Romaine, Mr. Charles Hallace (\"Mr C Rolmane\")"
## [1] "Rosenshine, Mr. George (\"Mr George Thorne\")"
## [1] "Ross, Mr. John Hugo"
## [1] "Rothschild, Mr. Martin"
## [1] "Rothschild, Mrs. Martin (Elizabeth L. Barrett)"
## [1] "Ryerson, Mr. Arthur Larned"
## [1] "Ryerson, Mrs. Arthur Larned (Emily Maria Borie)"
## [1] "Schabert, Mrs. Paul (Emma Mock)"
## [1] "Seward, Mr. Frederic Kimber"
## [1] "Shutes, Miss. Elizabeth W"
## [1] "Silverthorne, Mr. Spencer Victor"
## [1] "Silvey, Mr. William Baird"
## [1] "Silvey, Mrs. William Baird (Alice Munger)"
## [1] "Simonius-Blumer, Col. Oberst Alfons"
## [1] "Smart, Mr. John Montgomery"
## [1] "Smith, Mr. James Clinch"
## [1] "Spedden, Mr. Frederic Oakley"
## [1] "Spedden, Mrs. Frederic Oakley (Margaretta Corning Stone)"
## [1] "Spencer, Mr. William Augustus"
## [1] "Stead, Mr. William Thomas"
## [1] "Stengel, Mr. Charles Emil Henry"
## [1] "Stengel, Mrs. Charles Emil Henry (Annie May Morris)"
## [1] "Stephenson, Mrs. Walter Bertram (Martha Eustis)"
## [1] "Stone, Mrs. George Nelson (Martha Evelyn)"
## [1] "Straus, Mr. Isidor"
## [1] "Straus, Mrs. Isidor (Rosalie Ida Blun)"
## [1] "Sutton, Mr. Frederick"
## [1] "Swift, Mrs. Frederick Joel (Margaret Welles Barron)"
## [1] "Taussig, Mr. Emil"
## [1] "Taussig, Mrs. Emil (Tillie Mandelbaum)"
## [1] "Taylor, Mr. Elmer Zebley"
## [1] "Thayer, Mr. John Borland"
## [1] "Thayer, Mrs. John Borland (Marian Longstreth Morris)"
## [1] "Uruchurtu, Don. Manuel E"
## [1] "Van der hoef, Mr. Wyckoff"
## [1] "Walker, Mr. William Anderson"
## [1] "Ward, Miss. Anna"
## [1] "Warren, Mr. Frank Manley"
## [1] "Warren, Mrs. Frank Manley (Anna Sophia Atkinson)"
## [1] "Weir, Col. John"
## [1] "White, Mr. Percival Wayland"
## [1] "White, Mrs. John Stuart (Ella Holmes)"
## [1] "Wick, Mr. George Dennick"
## [1] "Wick, Mrs. George Dennick (Mary Hitchcock)"
## [1] "Widener, Mr. George Dunton"
## [1] "Widener, Mrs. George Dunton (Eleanor Elkins)"
## [1] "Williams, Mr. Charles Duane"
## [1] "Wright, Mr. George"
## [1] "Young, Miss. Marie Grice"
## [1] "Angle, Mr. William A"
## [1] "Angle, Mrs. William A (Florence \"Mary\" Agnes Hughes)"
## [1] "Ashby, Mr. John"
## [1] "Ball, Mrs. (Ada E Hall)"
## [1] "Bateman, Rev. Robert James"
## [1] "Becker, Mrs. Allen Oliver (Nellie E Baumgardner)"
## [1] "Beesley, Mr. Lawrence"
## [1] "Bowenur, Mr. Solomon"
## [1] "Brown, Mr. Thomas William Solomon"
## [1] "Brown, Mrs. Thomas William Solomon (Elizabeth Catherine Ford)"
## [1] "Buss, Miss. Kate"
## [1] "Byles, Rev. Thomas Roussel Davids"
## [1] "Bystrom, Mrs. (Karolina)"
## [1] "Cameron, Miss. Clear Annie"
## [1] "Carter, Mrs. Ernest Courtenay (Lilian Hughes)"
## [1] "Carter, Rev. Ernest Courtenay"
## [1] "Chapman, Mr. Charles Henry"
## [1] "Chapman, Mr. John Henry"
## [1] "Christy, Mrs. (Alice Frances)"
## [1] "Davies, Mrs. John Morgan (Elizabeth Agnes Mary White) "
## [1] "Doling, Mrs. John T (Ada Julia Bone)"
## [1] "Downton, Mr. William James"
## [1] "Drew, Mr. James Vivian"
## [1] "Drew, Mrs. James Vivian (Lulu Thorne Christian)"
## [1] "Faunthorpe, Mr. Harry"
## [1] "Fox, Mr. Stanley Hubert"
## [1] "Funk, Miss. Annie Clemmer"
## [1] "Fynney, Mr. Joseph J"
## [1] "Gale, Mr. Harry"
## [1] "Gale, Mr. Shadrach"
## [1] "Garside, Miss. Ethel"
## [1] "Gilbert, Mr. William"
## [1] "Gillespie, Mr. William Henry"
## [1] "Greenberg, Mr. Samuel"
## [1] "Harbeck, Mr. William H"
## [1] "Harris, Mr. George"
## [1] "Hart, Mr. Benjamin"
## [1] "Hart, Mrs. Benjamin (Esther Ada Bloomfield)"
## [1] "Herman, Mr. Samuel"
## [1] "Herman, Mrs. Samuel (Jane Laver)"
## [1] "Hewlett, Mrs. (Mary D Kingcome) "
## [1] "Hocking, Mr. Samuel James Metcalfe"
## [1] "Hocking, Mrs. Elizabeth (Eliza Needs)"
## [1] "Hodges, Mr. Henry Price"
## [1] "Hold, Mr. Stephen"
## [1] "Hosono, Mr. Masabumi"
## [1] "Howard, Mr. Benjamin"
## [1] "Howard, Mrs. Benjamin (Ellen Truelove Arman)"
## [1] "Jacobsohn, Mr. Sidney Samuel"
## [1] "Jarvis, Mr. John Denzil"
## [1] "Kantor, Mr. Sinai"
## [1] "Keane, Mr. Daniel"
## [1] "Kelly, Mrs. Florence \"Fannie\""
## [1] "Kirkland, Rev. Charles Leonard"
## [1] "Lemore, Mrs. (Amelia Milley)"
## [1] "Levy, Mr. Rene Jacques"
## [1] "Lingane, Mr. John"
## [1] "Louch, Mr. Charles Alexander"
## [1] "Louch, Mrs. Charles Alexander (Alice Adelaide Slow)"
## [1] "Mack, Mrs. (Mary)"
## [1] "Maybery, Mr. Frank Hubert"
## [1] "McKane, Mr. Peter David"
## [1] "Mellinger, Mrs. (Elizabeth Anne Maidment)"
## [1] "Meyer, Mr. August"
## [1] "Milling, Mr. Jacob Christian"
## [1] "Mitchell, Mr. Henry Michael"
## [1] "Moraweck, Dr. Ernest"
## [1] "Morley, Mr. Henry Samuel (\"Mr Henry Marshall\")"
## [1] "Myles, Mr. Thomas Francis"
## [1] "Navratil, Mr. Michel (\"Louis M Hoffman\")"
## [1] "Otter, Mr. Richard"
## [1] "Parrish, Mrs. (Lutie Davis)"
## [1] "Peruschitz, Rev. Joseph Maria"
## [1] "Phillips, Mr. Escott Robert"
## [1] "Ponesell, Mr. Martin"
## [1] "Reeves, Mr. David"
## [1] "Renouf, Mr. Peter Henry"
## [1] "Ridsdale, Miss. Lucy"
## [1] "Sjostedt, Mr. Ernst Adolf"
## [1] "Slemen, Mr. Richard James"
## [1] "Smith, Miss. Marion Elsie"
## [1] "Stanton, Mr. Samuel Ward"
## [1] "Toomey, Miss. Ellen"
## [1] "Veal, Mr. James"
## [1] "Watt, Mrs. James (Elizabeth \"Bessie\" Inglis Milne)"
## [1] "West, Mr. Edwy Arthur"
## [1] "Wheadon, Mr. Edward H"
## [1] "Abbing, Mr. Anthony"
## [1] "Abbott, Mrs. Stanton (Rosa Hunt)"
## [1] "Ahlin, Mrs. Johan (Johanna Persdotter Larsson)"
## [1] "Allen, Mr. William Henry"
## [1] "Andersson, Miss. Ida Augusta Margareta"
## [1] "Andersson, Mr. Anders Johan"
## [1] "Andersson, Mrs. Anders Johan (Alfrida Konstantia Brogren)"
## [1] "Asim, Mr. Adola"
## [1] "Asplund, Mr. Carl Oscar Vilhelm Gustafsson"
## [1] "Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)"
## [1] "Assaf Khalil, Mrs. Mariana (\"Miriam\")"
## [1] "Badt, Mr. Mohamed"
## [1] "Barbara, Mrs. (Catherine David)"
## [1] "Bourke, Mr. John"
## [1] "Brocklebank, Mr. William Alfred"
## [1] "Cacic, Mr. Luka"
## [1] "Carr, Miss. Jeannie"
## [1] "Coleff, Mr. Peju"
## [1] "Connors, Mr. Patrick"
## [1] "Cook, Mr. Jacob"
## [1] "Cor, Mr. Bartol"
## [1] "Coutts, Mrs. William (Winnie \"Minnie\" Treanor)"
## [1] "Coxon, Mr. Daniel"
## [1] "Cribb, Mr. John Hatfield"
## [1] "Dahl, Mr. Karl Edwart"
## [1] "Danbom, Mr. Ernst Gilbert"
## [1] "de Messemaeker, Mr. Guillaume Joseph"
## [1] "de Messemaeker, Mrs. Guillaume Joseph (Emma)"
## [1] "Dennis, Mr. William"
## [1] "Dimic, Mr. Jovan"
## [1] "Dintcheff, Mr. Valtcho"
## [1] "Duane, Mr. Frank"
## [1] "Ekstrom, Mr. Johan"
## [1] "Elias, Mr. Joseph"
## [1] "Elsbury, Mr. William James"
## [1] "Everett, Mr. Thomas James"
## [1] "Farrell, Mr. James"
## [1] "Ford, Mrs. Edward (Margaret Ann Watson)"
## [1] "Goldsmith, Mr. Nathan"
## [1] "Goncalves, Mr. Manuel Estanslas"
## [1] "Goodwin, Mr. Charles Frederick"
## [1] "Goodwin, Mrs. Frederick (Augusta Tyler)"
## [1] "Green, Mr. George Henry"
## [1] "Gustafsson, Mr. Anders Vilhelm"
## [1] "Hansen, Mr. Claus Peter"
## [1] "Hansen, Mrs. Claus Peter (Jennie L Howard)"
## [1] "Holm, Mr. John Fredrik Alexander"
## [1] "Humblen, Mr. Adolf Mathias Nicolai Olsen"
## [1] "Jensen, Mr. Niels Peder"
## [1] "Johanson, Mr. Jakob Alfred"
## [1] "Johnson, Mr. Alfred"
## [1] "Karun, Mr. Franz"
## [1] "Kelly, Mr. James"
## [1] "Kelly, Mr. James"
## [1] "Klasen, Mrs. (Hulda Kristina Eugenia Lofqvist)"
## [1] "Laitinen, Miss. Kristina Sofia"
## [1] "Lemberopolous, Mr. Peter L"
## [1] "Leonard, Mr. Lionel"
## [1] "Lester, Mr. James"
## [1] "Lindblom, Miss. Augusta Charlotta"
## [1] "Lindell, Mr. Edvard Bengtsson"
## [1] "Lundahl, Mr. Johan Svensson"
## [1] "Markoff, Mr. Marin"
## [1] "McGowan, Miss. Katherine"
## [1] "Meo, Mr. Alfonzo"
## [1] "Morley, Mr. William"
## [1] "Nirva, Mr. Iisakki Antino Aijo"
## [1] "Niskanen, Mr. Juha"
## [1] "Nysveen, Mr. Johan Hansen"
## [1] "Olsen, Mr. Karl Siegwart Andreas"
## [1] "Panula, Mrs. Juha (Maria Emilia Ojala)"
## [1] "Rekic, Mr. Tido"
## [1] "Rice, Mrs. William (Margaret Norton)"
## [1] "Rintamaki, Mr. Matti"
## [1] "Robins, Mr. Alexander A"
## [1] "Robins, Mrs. Alexander A (Grace Charity Laury)"
## [1] "Rosblom, Mrs. Viktor (Helena Wilhelmina)"
## [1] "Rouse, Mr. Richard Henry"
## [1] "Saether, Mr. Simon Sivertsen"
## [1] "Salonen, Mr. Johan Werner"
## [1] "Sivic, Mr. Husein"
## [1] "Skoog, Mr. Wilhelm"
## [1] "Skoog, Mrs. William (Anna Bernhardina Karlsson)"
## [1] "Storey, Mr. Thomas"
## [1] "Sundman, Mr. Johan Julian"
## [1] "Svensson, Mr. Johan"
## [1] "Theobald, Mr. Thomas Leonard"
## [1] "Torber, Mr. Ernst William"
## [1] "Turcin, Mr. Stjepan"
## [1] "Turkula, Mrs. (Hedwig)"
## [1] "van Billiard, Mr. Austin Blyler"
## [1] "Van Impe, Mr. Jean Baptiste"
## [1] "Vander Cruyssen, Mr. Victor"
## [1] "Whabee, Mrs. George Joseph (Shawneene Abi-Saab)"
## [1] "Widegren, Mr. Carl/Charles Peter"
## [1] "Wilkes, Mrs. James (Ellen Needs)"
## [1] "Wittevrongel, Mr. Camille"
## [1] "Youseff, Mr. Gerious"

Question 2

A study was conducted on GRE test takers to evaluate the success conditions. The success rate is 25%. A sample of 30 test takers is selected for the study. Use the binomial distribution to calculate the followings:

  1. The probability that 10 test takers fail the GRE test:
#INSERT YOUR ANSWER HERE
dbinom(10,30,0.75)
## [1] 1.538811e-06
  1. The probability of getting at least five test takers succeed in the test
#INSERT YOUR ANSWER HERE
dbinom(5,30,0.25)
## [1] 0.1047285
  1. The probability of 25 or less fail the test
#INSERT YOUR ANSWER HERE
dbinom(25,30,0.75)
## [1] 0.1047285

Question 3

In a shipment of 20 engines, history shows that the probability of any one engine proving unsatisfactory is 0.1

  1. Use the Binomial approximation to calculate the probability that more than 10 engines are defective?
#INSERT YOUR ANSWER HERE
dbinom(10,20,0.1)
## [1] 6.442043e-06
  1. Use the Poisson approximation to calculate the probability that at most three engines are defective?
#INSERT YOUR ANSWER HERE
ppois(3,20)
## [1] 3.20372e-06
  1. Use the binomial approximation to calculate the probability that at most three engines are defective?
#INSERT YOUR ANSWER HERE
dbinom(3,20,0.1)
## [1] 0.1901199
  1. Compare the results of parts a and b, then illustrate on how well the Poisson probability distribution approximates the Binomial probability distribution.
#INSERT YOUR ANSWER HERE
x <-0:10
y1<-ppois(x,2,lower.tail=FALSE)
y2<-pbinom(x,20,0.1,lower.tail=FALSE)

Question 4

Write a script in R to compute the following probabilities of a normal random variable with mean 16 and variance 9

  1. lies between 14.4 and 20.3 (inclusive)
#INSERT YOUR ANSWER HERE
pnorm(20.3,16,3)- pnorm(14.4,16,3)
## [1] 0.6272173
  1. is greater than 21.8
#INSERT YOUR ANSWER HERE
1-pnorm(21.8, 16,3)
## [1] 0.02659757
  1. is less or equal to 10.5
#INSERT YOUR ANSWER HERE
pnorm(10.5,16,3)
## [1] 0.03337651
  1. is less than 13 or greater than 19
#INSERT YOUR ANSWER HERE
pnorm(13,16,3)+ 1-pnorm(19,16,3)
## [1] 0.3173105

END of Assignment #2.