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

What is the code in Rstudio or R? (a) Generate 200 random samples of size n = 10

ID: 3352342 • Letter: W

Question

What is the code in Rstudio or R?

(a) Generate 200 random samples of size n = 10 from a Poisson distribution with mean = 12.

i. Calculate sample means for each sample. Report the first 10 sample means.

ii. Draw a histogram of the sample means (where the y-axis is the density) and fit a density estimate (default density estimator is ok).

iii. What is your finding about the sampling distribution of the sample mean, based on your histogram. Be sure to give the distribution name along with its parameter estimates.

(b) Generate 200 random samples of size n = 50 from a Poisson distribution with mean = 12.

i. What distribution is the new set of sample means? State the exact distribution expected from theory (including parameter values), and state the distribution obtained from your samples (including estimated parameter values).

ii. Based on this distribution, construct a 95% confidence interval for the mean . Assume is known.

(c) Generate 200 random samples of size n = 20 from a Chi-Square distribution with degrees of freedom df = 6.

i. Find the first quantile Q1 from each sample (note: qchisq() gives the quantile from the exact distribution, NOT the sample). Report the first 10 quantiles.

ii. Draw a histogram of the sample Q1’s (where the y-axis is the density) and fit a density estimate (default density estimator is ok).

(d) Generate 200 random samples of size n = 100 from a Chi-Square distribution with degrees of freedom df = 6.

i. Draw a histogram of the sample first quantiles (where the y-axis is the density) and fit a density estimate (default density estimator is ok).

ii. Are there any differences between the distribution from Problem 2(a)ii and 2(b)i? Describe any differences you may see.

Explanation / Answer

(a)
n=10                         # sample size
lambda=12                    # true value of a parameter
sim=200                      # Set the number of simulations
mx=c()                       # Empty vector
for (i in 1:sim){            # simulation loop
x=rpois(n,lambda)            # generate poisson random number
mx[i]=mean(x)
}
rmx=mx[1:10]
rmx

[1] 11.8 11.1 11.2 11.7 13.8 11.9 10.8 12.0 12.7 11.4

hist(mx, freq=FALSE,main="Density estimate of data")
lines(density(mx))

Form histogram, the distribution is normal with

> mean(mx)
[1] 11.932
> var(mx)
[1] 1.171232

b.


n=50                         # sample size
lambda=12                    # true value of a parameter
sim=200                      # Set the number of simulations
mx=c()                       # Empty vector
for (i in 1:sim){            # simulation loop
x=rpois(n,lambda)            # generate poisson random number
mx[i]=mean(x)
}
rmx=mx[1:10]
rmx
hist(mx, freq=FALSE,main="Density estimate of data")
lines(density(mx))

It is also normal distribution with mean 12 and variance 0.25

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