What does the following R code accomplish? How does it relate to the relevance of the t distribution?
x <- rnorm(60000,mean=355,sd=2) data <- matrix(x,ncol=6) xbar <- apply(data,1,mean) s <- apply(data,1,sd) z.ratio <- (xbar-355)/(2 / sqrt(6)) t.ratio <- (xbar-355)/(s/sqrt(6))
Now graph z.ratio and t.ratio using histograms with superimposed standard normal curves.
par(mfrow=c(2,1)) x <- seq(-4,4,len=201) y <- dnorm(x) hist(z.ratio,prob=T,xlim=c(-4,4),ylim=c(0,.4)) lines(x,y,type='l') hist(t.ratio,prob=T,xlim=c(-4,4),ylim=c(0,.4)) lines(x,y,type='l') par(mfrow=c(1,1))
R note: A better "goodness of normal fit" graphic than superimposing a normal onto a histogram is to use the qqnorm and its companion qqline functions. The closer to straight the plot, the more normal the data. Here is the syntax:
par(mfrow=c(2,1)) qqnorm(z.ratio) # Is it straight? qqline(z.ratio) # Adding a line helps us decide. qqnorm(t.ratio) qqline(t.ratio) par(mfrow=c(1,1)) # End of code