STA 032

STA 032 Winter 2019
R Report II - Due Tuesday, March 5th by 5:00pm.
R Report II
FORMAT

  • Use complete sentences and proper grammar to answer all questions.
  • Use R Markdown to create an html document.
  • Code should not be in the body of the text, so be sure to add echo = FALSE in the preface to your R chunks. All code
    should be included at the end of the homework, as an appendix.
    I. Simulate a binomial random variable. Consider a class with 60 students, and the probability that a student does not
    turn in a homework is 0.10 (a “success”). Assume all students are independent of all other students, and the probability
    does not change.
    (a) Use sample to simulate drawing 60 students who either do, or do not, turn in their homework, and then find the
    total (out of 60) who did not turn in their homework. You should return one number, X = total # of students out
    of 60 who did not turn in their homework.
    (b) Repeat (a) 1000000 times (you should have 1000000 values for “number of successes”,or X), plot a histogram of your
    result (do not print out the 1000000 values!!). For this particular binomial distribution, is the distribution
    symmetric? Explain.
    (c) Find the average of the number of successes in 60 trials and the standard deviation based on your simulation from
    part (b).
    (d) Estimate the probability that all students turned in their homework based on your simulation from (b).
    (e) Estimate the probability that at least four students did not turn in their homework based on your simulation from
    part (b).
    (f) What is the median number of students who will forget their homework based on your simulation from (b)?
    II. Simulate a Negative Binomial random variable. Consider that 40% of people wear glasses for near-sightedness.
    (a) Use R to simulate selecting random people until 5 are selected wear glasses. Return one the number of people it
    took until 5 wore glasses.
    (b) Repeat (a) 20000 times, so that you should have 20000 values of how many people were were selected until 5 wore
    glasses. Do not print out these values!!! Plot a histogram of these values.
    (c) Find the median of the vector from (b).
    (d) Find the mean and standard deviation of your vector from (b).
    (e) Find the probability we had to sample more than 10 people before we found 5 that needed glasses.
    (f) Find the probability that if it takes more than 10 people, it will an additional 5 to find 5 that wore glasses.
    1
    III. Consider the function rnorm, which simulates a normal random variable. For example, the following code will generate
  • normal random variables with mean 100, standard deviation 15:
    X = rnorm(2000, mean = 100, sd = 15)
    (a) Generate 10000 values of a normal random variable with mean 2, standard deviation 1, and call this vector X.
    Generate 10000 values of a normal random variable with mean -2, standard deviation 5, and call this vector Y .
    Report back the mean and standard deviation of both vectors (using the functions in R).
    (b) Create a vector W by adding the two vectors from (a) together, and find the mean and standard deviation W (using
    R).
    (c) Find the probability that W is larger than 3.
    (d) We know what the answers to (b), (c) should be exactly. Calculate the error for all the values found. (Take the
    answer in R and subtract what we know it should be.)

你可能感兴趣的