Home > front end >  Histogram curve E(X) and variance Var(X)/n?
Histogram curve E(X) and variance Var(X)/n?

Time:06-06

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?

CodePudding user response:

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

CodePudding user response:

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)
  • Related