Demonstration of Sampling

Distributions

Background

Sampling distributions can be a difficult concept to understand. The goal of this application is to allow someone to adjust a population distribution, as well as the size of the sample, and see the resulting sampling distribution.

Population Distribution

The user is able to set the mean and standard deviation of a hypothetical normally-distributed random variable. The probability density of this distribution is plotted.

mu <- 0
sig <- 1
x <- seq(-4*sig+mu,4*sig+mu,length=500)
y <- 1/(sig * sqrt(2*pi))*exp(-(x-mu)^2/(2*sig^2))
plot(x,y,type="l",lwd=2,col='blue',ylab="Probability Density",
     xlab="",main="Population Distribution")

plot of chunk unnamed-chunk-1

Sample Size

The user is able to choose a sample size and draw 1000 samples of that size from the population. A histogram of the means of all 1000 samples is plotted. It can be demonstrated that larger sample sizes produce tighter distributions of the sample means.

ss <- c(10,100)
sampmeans <- matrix(0,nrow=1000,ncol=2)
for (i in 1:1000){
    sampmeans[i,1] <- mean(rnorm(ss[1],mean=mu,sd=sig))
    sampmeans[i,2] <- mean(rnorm(ss[2],mean=mu,sd=sig))
}
par(mfrow=c(1,2))
hist(sampmeans[,1],xlim=c(-4,4),main="Sample Size 15",xlab="Sample Means")
hist(sampmeans[,2],xlim=c(-4,4),main="Sample Size 100",xlab="Sample Means")

plot of chunk unnamed-chunk-2

Standard Error of the Mean

The standard deviation of these sample means (SE(\(\bar{x}\))) is calculated and compared to the value predicted by the Central Limit Theorem, the standard deviation of the population divided by the square root of the sample size ($ \sqrt{\sigma}/n $).