#--------- central.limit --------------- # #The input parameters are: # n - size of each sample # m - number of samples of size n to select # qq - TRUE means show the Q-Q plots # df1, df2 - the df of the F() distribution from which samples are drawn # xlow, xhigh - x-axis limits for plots central.limit = function(n=15,m=1000,qq=FALSE,df1=6,df2=200,xlow=0,xhigh=2.5) { means = vector() # I hereby declare that "means" is a vector for (i in 1:m) { # get m samples from a skewed distribution data= rf(n,df1,df2) # the F() distribution is nice and skewed means[i] = mean(data) # means is our array of means } if (qq) { # call with TRUE and it makes the q-q plots x=qqnorm(means)$x qqline(means) caption = paste("n =",n,", Correlation = ",signif(cor(means,x),3)) mtext(caption) } else { # the default behavior title = paste("Sample size = ",n) hist(means, xlim = c(xlow,xhigh),main=title,freq=F) plot(function(x)dnorm(x,mean=mean(means), sd=sd(means)),xlow,xhigh,add=T) plot(function(x)df(x,df1,df2),xlow,xhigh,add=T) caption = paste("Standard error = ",signif(sd(means),3)) mtext(caption) } }