联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Algorithm 算法作业Algorithm 算法作业

日期:2019-03-05 09:04

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

2000 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.)


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp