Question

Using R,

Exercise 4 (CLT Simulation) For this exercise we will simulate from the exponential distribution. If a random variable X has an exponential distribution with rate parameter A, the pdf of X can be written for z 2 0 Also recall, (a) This exercise relies heavily on generating random observations. To make this reproducible we will set a seed for the randomization. Alter the following code to make birthday store your birthday in the format yyyymmdd. For example, William Gosset, better known as Student, was born on June 13, 1876, so he would ise: birthday18760613 set.seed(birthday) (b) Simulate 10000 samples of size 5 from an exponential distribution with λ-2. Store the mean of each sample in a vector. Plot a histogram of these sample means. (Be sure to give it a title, and label the axes appropriately.) Based on the histogram, do you think the central limit theorem applies here? (c) Simulate 10000 samples of size 100 from an exponential distribution with λ-2. Store the mean of each sample in a vector. Plot a histogram of these sample means. (Be sure to give it a title, and label the axes appropriately.) Based on the histogram, do you think the central limit theorem applies here? (d) We just repeated ourselves, so that means we probably should be writing a function. Write a function called sim xbars_exp which takes three inputs: The number of samples to simulate. .The sample size The rate parameter of an exponential distribution. The function should output a vector of sample means which are the result of sampling from an exponential distribution as specified by the inputs. Use your function to simulate 25000 samples of size 50 from an exponential distribution with λ-3. Store the mean of each sample in a vector. Plot a histogram of these sample means. (Be sure to give it a title, and label the axes appropriately.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a)

We will use birthdate as 20010610 as shown in below code.

birthday = 20010610
set.seed(birthday)

(b)

Below code simulate 10,000 samples of size 5 from an exponential distribution with lambda = 2. The shape of the histogram is not symmetrical, as it is skewed to the right. Based on histogram, the central limit theorem does not applies.

birthday = 20010610
set.seed(birthday)
x = numeric()
for (i in 1:10000) {
samples = rexp(5, rate = 2)
x = c(x, mean(samples))
}
hist(x, xlab = "Sample mean of size 5", main = "Histogram of sample means of size 5")

Histogram of sample means of size 5 0.0 0.5 1.0 1.5 Sample mean of size 5

(c)

Below code simulate 10,000 samples of size 100 from an exponential distribution with lambda = 2. The histogram shape is symmetrical. Thus, based on histogram, the central limit theorem applies.

birthday = 20010610
set.seed(birthday)
x = numeric()
for (i in 1:10000) {
samples = rexp(100, rate = 2)
x = c(x, mean(samples))
}
hist(x, xlab = "Sample mean of size 100", main = "Histogram of sample means of size 100")

Histogram of sample means of size 100 0.3 0.4 0.5 0.6 0.7 0.8 Sample mean of size 100

(d)

Below is the function sim_xbars_exp which will take the simulation size, sample size and rate parameter to generate sample means of the exponential distribution.

sim_xbars_exp = function(simulation_size, sample_size, lambda) {
birthday = 20010610
set.seed(birthday)
x = numeric()
for (i in 1:simulation_size) {
samples = rexp(sample_size, rate = lambda)
x = c(x, mean(samples))
}
return(x)
}

Calling the function and storing the mean vector in y and then plotting the histogram.

y = sim_xbars_exp(25000, 50, 3)
hist(y, xlab = "Sample mean of size 50", main = "Histogram of sample means of size 50")

Histogram of sample means of size 50 0.2 0.3 0.4 0.5 0.6 Sample mean of size 50

Add a comment
Know the answer?
Add Answer to:
Using R, Exercise 4 (CLT Simulation) For this exercise we will simulate from the exponential distribution....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please complete using R. Show all code needed to complete exercise. Will Thumbs up if done...

    Please complete using R. Show all code needed to complete exercise. Will Thumbs up if done neatly and correctly. Exercise 5 (More Simulation) Let X follow an exponential distribution with rate parameter λx = 2. Let Y follow a Poisson distribution with rate parameter λ 3. We write sd(X) for the true standard deviation of X and m(Y) for the true median of Y Let s be the sample standard median which is an estimate of m(Y) Suppose we take...

  • Please use html format! II. The goal of this problem is to simulate the distribution of the sample mean. We will...

    Please use html format! II. The goal of this problem is to simulate the distribution of the sample mean. We will use the buit load the dataset and avoid some problems, copy and paste the following command in dataset 1ynx. To lynx as.numeric(lynx) Assume this vector represents the population. Le, the mean of this vector is our "true mean" (a) Draw a histogram of the population, find the "true" mean, and the true" variance. Does this data look normally distributed?...

  • Draw 20 samples from a Exponential distribution with parameter rate = 4 one thousand times. Fix...

    Draw 20 samples from a Exponential distribution with parameter rate = 4 one thousand times. Fix the range of horizontal line of the histogram to be [0, 0.5] and the vertical line of the histogram to be [0, 13]. Plot the histogram, together with a density of color blue. How does it look like? Increase the sample size to be 50. Draw the density on the previous plot with a different color. How does the density function change?

  • Generate a population of size N= 10000 from an exponential distribution with mean θ= 10. a....

    Generate a population of size N= 10000 from an exponential distribution with mean θ= 10. a. Generate 1000 samples of sizen= 200 from the population and plot the density of the sample means. b. Generate a single sample of sizen= 200. Resample with sizen= 200 with replacement fromthis single sample 1000 times. Plot the density of the resample means. c. Comment on the two densities you have plotted

  • In the notes there is a Central Limit Theorem example in which a sampling distribution of means i...

    R Programming codes for the above questions? In the notes there is a Central Limit Theorem example in which a sampling distribution of means is created using a for loop, and then this distribution is plotted. This distribution should look approximately like a normal distribution. However, not all statistics have normal sampling distributions. For this problem, you'll create a sampling distribution of standard deviations rather than means. 3. Using a for loop, draw 10,000 samples of size n-30 from a...

  • Python 3.7 please help please use central limit theory In this problem you will verify the...

    Python 3.7 please help please use central limit theory In this problem you will verify the Central Limit Theorem (CLT) which states that averages, from repeated random samples of any distribution, follow a normal distribution 1. (5 points) Draw a random sample of 5,000 random numbers from a uniform distribution X ~U (20,80] and store them into a vector called xy and plot a histogram of these 5,000 numbers 2. (5 points) Draw a random sample of 5,000 random numbers...

  • Independent random samples X1, X2, . . . , Xn are from exponential distribution with pdfs...

    Independent random samples X1, X2, . . . , Xn are from exponential distribution with pdfs , xi > 0, where λ is fixed but unknown. Let . Here we have a relative large sample size n = 100. (ii) Notice that the population mean here is µ = E(X1) = 1/λ , population variance σ^2 = Var(X1) = 1/λ^2 is unknown. Assume the sample standard deviation s = 10, sample average = 5, construct a 95% large-sample approximate confidence...

  • R codeing simulation For n = 20, simulate a random sample of size n from N(µ, 2 2 ), where µ = 1....

    R codeing simulation For n = 20, simulate a random sample of size n from N(µ, 2 2 ), where µ = 1. Note that we just use µ = 1 to generate the random sample. In the problem below, µ is an unknown parameter. Plot in different figures: (a) the likelihood function of µ, (b) the log likelihood function of µ. Mark in both plots the maximum likelihood estimate of µ from the generated random sample (2) For n-20,...

  • Using R programming language, supply the code for: Generate a random sample of size 10, 000...

    Using R programming language, supply the code for: Generate a random sample of size 10, 000 from gamma distribution with scale parameter equal to 1 and shape parameter equal to 2, and form it into a 1000 x 10 matrix. Use the apply() function on this matrix to compute the means of the 1000 rows. Note that the resulting vector comprises the mean of 1000 random samples of size 10 from the above distribution. Examine the distribution of the sample...

  • [25 points] Problem 4 - CDF Inversion Sampling ers coming from the U(0, 1) distribution into...

    [25 points] Problem 4 - CDF Inversion Sampling ers coming from the U(0, 1) distribution into In notebook 12, we looked at one method many pieces of statistical software use to turn pseudorandom those with a normal distribution. In this problem we examine another such method. a) Simulating an Exponential i) The exponential distribution has pdf f(x) = le-ix for x > 0. Use the following markdown cell to compute by hand the cdf of the exponential. ii) The cdf...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT