There are 10 questions and each question is worth 10 points each. When completed, knit the file to a .HTML and save the file as Test#1_LastName and submit the .HTML file to the Test #1 assignment link on Moodle.

Due Date: Sunday December 20th, 2019 by 11:55p.m. EST.

  1. Run the code below and notice there is a data frame entitled SpaceShuttle. Using the R help, read about the details of this data frame. That is, familiarize yourself with the context and understand the meaning of the different rows.
library(vcd)
## Loading required package: grid
library(vcdExtra)
## Loading required package: gnm
ds <- datasets(package = c("vcd", "vcdExtra"))
str(ds)
## 'data.frame':    76 obs. of  5 variables:
##  $ Package: chr  "vcd" "vcd" "vcd" "vcd" ...
##  $ Item   : chr  "Arthritis" "Baseball" "BrokenMarriage" "Bundesliga" ...
##  $ class  : chr  "data.frame" "data.frame" "data.frame" "data.frame" ...
##  $ dim    : chr  "84x5" "322x25" "20x4" "14018x7" ...
##  $ Title  : chr  "Arthritis Treatment Data" "Baseball Data" "Broken Marriage Data" "Ergebnisse der Fussball-Bundesliga" ...
View(ds)
  1. Using the structable() function, create a “flat” table that has the Damage Index on the columns and whether the O-ring failed and how many failures on the rows.
structable (Damage~Fail + nFailures, data = SpaceShuttle)
##                Damage  0  2  4 11
## Fail nFailures                   
## no   0                15  0  1  0
##      1                 0  0  0  0
##      2                 0  0  0  0
## yes  0                 0  0  0  0
##      1                 0  1  4  0
##      2                 0  0  1  1
  1. Construct the same formatted table that you did in part a, but now use the xtabs() and ftable() functions.
xtabs(Damage~Fail + nFailures, data = SpaceShuttle)
##      nFailures
## Fail   0  1  2
##   no   4  0  0
##   yes  0 18 15
ftable(Damage~Fail + nFailures, data = SpaceShuttle)
##                Damage  0  2  4 11
## Fail nFailures                   
## no   0                15  0  1  0
##      1                 0  0  0  0
##      2                 0  0  0  0
## yes  0                 0  0  0  0
##      1                 0  1  4  0
##      2                 0  0  1  1
  1. This problem uses the same data as #1. Examine the structure of the SpaceShuttle data frame. Re-order the levls of Fail so that “yes” is first followed by “no”. Use the str() function to verify you have re-ordered the levels properly.
SpaceShuttle$Fail <- relevel(SpaceShuttle$Fail, "yes")
structable(Damage~Fail+nFailures, data = SpaceShuttle)
##                Damage  0  2  4 11
## Fail nFailures                   
## yes  0                 0  0  0  0
##      1                 0  1  4  0
##      2                 0  0  1  1
## no   0                15  0  1  0
##      1                 0  0  0  0
##      2                 0  0  0  0
  1. Describe a binomial experiment that would generate binomail data. That is, explain what the experiement is and make a case for how the experiment meets the three criteria for binomial data. Do not use an example from the book or one discussed in class. Come up with your own example! Think about some process/experiment that you deal with on a daily basis (work or personal). Place your response below.

Reminder: Three criteria for Binomial experiment (from our class notes): 1. n independent trials (state n and explain why trial are independent) 2. only one of two outcomes; “success” and “failure” (specify what is a “success” and what is a “failure”) 3. the probability of “success” stays the same from trial to trial (state p and why the probability stays the same from trial to trial) ## Answer: We could take example of Comedy MOvie data from TidyTuesday. It contains information about Comedy Movies released since 2018, and the question is whether comedy movis are more likly be releases at the 13th each month or do the audience like it more than other days?In this data there are 2782 movies associated with a release data, so the expected release per day is 92(2782/32),, the values of probability is about 0.975.##

  1. You are going to be working with a researcher assisting him in designing a survey for 100 subjects. One of the questions is ‘Were you vaccinated for the flu this year?’

Is this a binomial experiment? State Yes or No. If Yes, describe the three criteria that make this experiment Binomial. If No, state why this is not a Binomial experiment. ##Ansewer: Yes, this is binomial experiement. Becuase the trial is 100, and the possible outcome is either ‘Yes’ or ‘No’ , and the probability is 50% for each of the result.Therefore,the success rate will yield similar percentage from each tria.##

  1. A student answers 10 quiz questions completely at random; the first five are true/false, the second five are multiple choice, with four options each.

Is this a binomial experiment? State Yes or No. If Yes, describe the three criteria that make this experiment Binomial. If No, state why this is not a Binomial experiment. ## Answer: No. Because the probability of success went from 0.5 to 0.25. According to Binomial criteria, each trial shoud be independent and the average rate of event should be constant. Therefore, above experienment violates Binomial criteria.##

  1. Use the appropriate R function (must be one we discussed from class) and find the probability of 4 successes from a Bin(10,1/4) distribution.
dbinom(4,10, 0.25)
## [1] 0.145998
  1. Use the appropriate R function (must be one we discussed in class) and find the probability of 6 or less successes from a Bin(10,1/4) distribution.
pbinom(6,10,0.25)
## [1] 0.9964943
  1. You are a healthcare analyst working for a hospital. You are interested in the number of patient discharges every day. X=# patients discharged in one day. You know the mean number of patients discharged in 5.0.
  1. What is the probability that more than 8 patients will be discharged in one day?

Use the appropriate R function (must be one we discussed in class) to find the probability.

meanOfdischarge= 5.0
#P(X>8)
ppois(8,meanOfdischarge,lower.tail = FALSE)
## [1] 0.06809363
  1. What is the probability that 8 or more patients will be discharged in one day?

Use the appropriate R function (must be one we discussed in class) to find the probability.

ppois(7,meanOfdischarge,lower.tail = FALSE)
## [1] 0.1333717
  1. Using the same scenario in #8, find the probability that exactly 8 patients are discharged in a day.

Use the appropriate R function (must be one we discussed in class) to find the probability.

dpois(8,meanOfdischarge)
## [1] 0.06527804
  1. Use the data for the London Cycling Deaths (introduced in Example 3.6 on p.p. 71-72) and create a hanging rootgram. What is this graph telling you?
data("CyclingDeaths", package = "vcdExtra")
CyclingDeaths.tab <- table(CyclingDeaths$deaths)
CyclingDeaths.tab
## 
##   0   1   2   3 
## 114  75  14   5

Type interpretation of this graph below (what is this graph telling you?):