Here is a little R code that illustrates the basic properties and theorems about so-called "sampling distributions" that begin with the assumption that we have a random sample from a Normal Distribution with mean mu and standard deviation sigma.
Before running the code, study each section of code and figure out what it is doing? That is, predict the results. After we discuss your answers, we will run the code to see how we did. What will the vectors x.bar , s.2 , zz , and tt look like when you make histograms? Can you predict their means and SDs?
data <- matrix(rnorm(40000,mean=300,sd=3),ncol=4) x.bar <- apply(data,1,mean) s.2 <- apply(data,1,var) s <- sqrt(s.2) zz <- (x.bar - 300)/(3/sqrt(4)) tt <- (x.bar - 300)/(s/sqrt(4))
The following give the R code to make histograms. You can then
par(mfrow=c(2,2)) hist(x.bar,prob=T) hist(s.2,prob=T) hist(zz,prob=T) hist(tt,prob=T) par(mfrow=c(1,1)) # end of codeYou can click here to obtain
Predict the results of the following and verify by running the R code.
mean(s.2/3) var(s.2/3)
Re-dimension the graphics window:
par(mfrow=c(1,1))
Now let's look at the plot of x.bar by s. Explain (before running the R code) what the plot should look like and why?
plot(x.bar, s)
Compute the sample correlation between the two:
cor(x.bar, s)
Here's an additional experiment for an exponential sample:
data2 <- matrix(rexp(4000),ncol=4) x.bar.e <- apply(data2,1,mean) s.e <- apply(data2,1,sd) plot(x.bar.e, s.e) cor(x.bar.e, s.e)