0

For a value n=3, (lets consider generation seed at 100, generate 1280 samples from a population, X, with continuous uniform distribution in the interval [11,15])

How do i calculate the mean of the sample thus obtaining values from the mean distribution Xn?

How can i make the relative frequency histogram associated with the values obtained from the distribution of the mean Xn and superimpose a curve with the normal distribution with expected value E(X) and variance Var(X)/n?

CC-IDMC
  • 1
  • 1

2 Answers2

0

You can try the following:

set.seed(100)
rn <- runif(1280, 11, 15)
h<-hist(rn)

xfit <- seq(min(rn), max(rn), length = 40) 
yfit <- dnorm(xfit, mean = mean(rn), sd = var(rn)) 
yfit <- yfit * diff(h$mids[1:2]) * length(rn) 

lines(xfit, yfit, col = "black", lwd = 2)

R uses the sample mean and sample variance (when we have 1/(n-1) rather than 1/n).

Additional information can be found from Overlay normal curve to histogram in R

Stackcans
  • 351
  • 1
  • 9
  • I don't think this is quite what's asked, I believe the question is wanting a illustration of the CLT; So 1) take a sample of size 3 from U(11, 15), 2) calculate the mean of this sample, 3) repeat 1280 times. Then use the distribution of the means to plot the hist, and find the mean and variance (which'll hopefully be near (1/12 * (15 - 11)^2 )/n) – user20650 Jun 06 '22 at 01:04
0

You have to generate 1280 sample of size 3 (see runif) and then calculate mean (see mean) and plot it (see hist). Result should have normal distribution of expected properties.

set.seed(100)

mat <- matrix(runif(1280*3, 11, 16), nrow = 1280, ncol = 3)
means <- apply(mat, 1, mean)
hist(means)
jyr
  • 690
  • 6
  • 20