I used this code for parts a-d: x=runif(1e6,1,5) mean(x) var(x) hist(x,main="Histogram of x",xlab="x",ylab="f(x)",border="blue",col="green",freq=F) Write R code that does the following: Let...

70.2K

Verified Solution

Question

Basic Math

I used this code for parts a-d:

x=runif(1e6,1,5)
mean(x)
var(x)
hist(x,main="Histogram ofx",xlab="x",ylab="f(x)",border="blue",col="green",freq=F)

Write R code that does the following: Let Xi be a randomvariable uniformly distributed between 1 and 5. (a) Find E[Xi ] andVar(Xi).

(b) Generate 1000000 samples from a random variable X that has auniform density on [1,5]. x=runif(1e6,1,5)

(c) Create a histogram of the distribution. hist(x,freq=F)Explain the shape of histogram. Is it consistent with the uniformlydistributied rv between 1 and 5? See how to add details such ascolors and labels in Homeworks 3, 5.

d) Now we will withdraw n samples out of distribution and takethe average. We will repeat the process 1e6 times! and make ahistogram of the sampling distribution.

I used this R code for part e through f:Sample_Avg <-function(t){mean(runif(t,1,5))}
avg(30) > 3

rep(avg(30),1e6)

e) In a script file create a function Sample_Avg that willwithdraw n samples and take the average. Sample Avg <-function(t){ mean(runif(t,1,5) } Run Sample Ave(30) This will bethe average of 30 samples

f) Use replicate command to create 1000000 of these sampleaverages and save results in Xavg. Be patient it will take about amin.

g) Create a histogram of Xavg. Wow! it looks different comparedto the original distribution. Why is that? What is the shape ofthis sampling distribution? What are the parameters.

h) Overlay the distribution function from g) onto the histogramof Xave. See Homeworks 3,5 for commands for overlaying function ontop of a histogram.

i) Compute the theoretical probability P(X30 >3.5) .In R how would you find the percentage of Xavg that isgreater than 3.5?? Execute the code and compare it to thetheoretical calculation.

Please answer g, h and i. Thank you

Answer & Explanation Solved by verified expert
4.1 Ratings (633 Votes)
eCreated the function SampleAvg with the given script SampleAvg    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students