Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What this R code does? (Hint: Review the concepts associated with this distribut

ID: 2921238 • Letter: W

Question

What this R code does? (Hint: Review the concepts associated with this distribution)

> rx = replicate(10,mean(rexp(20, rate=0.05))) > mean(rx)

Answer (circle please): (a) calculates the mean of a set of random numbers (b) calculates the mean of means of random numbers (c) shows that the sample mean is an unbiased parameter estimator

Does the command below confirm your answer above? YES NO

> rrx = sapply(1:10, function(i) mean(rexp(20, rate=0.05))) > mean(rrx)

In addition, write the R code to plot the means generated above.

Explanation / Answer

We shall proceed step-by-step to understand this chunk of R code.

>rexp(20, rate=0.05) # This generates 20 random numbers from an exponential distribution with mean equaling inverse of the given 'rate' (here, rate=0.05) .

>mean(rexp(20, rate=0.05)) # This calculates the mean of 20 random numbers generated from an exponential distribution with rate = 0.05

>rx = replicate(10,mean(rexp(20, rate=0.05))) # This, therefore, does the same work as described in the previous code-line independently for 10 times, and stores the 10 means obtained from the 10 instances in a vector 'rx' .

>mean(rx) # This calculates the mean of the 10 numerical entries of the vector 'rx' .

Therefore, we see that option(b) is the correct one.

The next code:

> rrx = sapply(1:10, function(i) mean(rexp(20, rate=0.05)))

calculates the output value a function which calculates ' >mean(rexp(20, rate=0.05)) ' (this code is explained before) ; and does this for 10 instances (by using sapply() function ) ; and stores the 10 outputs in the vector 'rrx'.

' >mean(rrx) ' calculates the mean of 'rrx' .

So YES, this command does confirm the same answer for the first question.

The R code for plotting the means is:

>plot(rx)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote