# The population is the numbers 1,2,...,1000
Population <- 1:1000
# Let's print the population to check it
print(Population)
# Let's see the histogram of the population
# Notice it's definitely not mound-shaped
hist(Population)
# We can compute the mean and standard deviation of the population
# Mu is 500.5 and the sigma is approx 289
print(mean(Population))
print(sd(Population))
# Let's take a sample of 100 measurements from the population
MySample <- sample(Population, 100)
print(MySample)
# Calculate the sample mean
print(mean(MySample))
# Randomly choose 1,000 samples and calculate each sample mean
# SampleMeans is a vector that stores the sample mean for the 1,000 samples
NumberOfSamples <- 1000
SampleMeans<- rep(0, NumberOfSamples)
for(index in 1: NumberOfSamples){
SampleMeans[index]<- mean(sample(Population, 100))
}
#Let's print the sample means
print(SampleMeans)
# Let's see the histogram of the sample means
# Notice that it's mound-shaped even though the population was NOT
hist(SampleMeans)
# Calculate the mean of the sample means
# Notice it's approx mu
print(paste("The mean of the sample means is", mean(SampleMeans)))
# Calculate the standard deviation of the sample means
# Notice it's a lot smaller than the population standard deviation
print(paste("The SD of the sample means is", sd(SampleMeans)))