################################################################## ## Create a function with calling parameters # # sample.size - sets size of sample # num.samples - number of samples to draw # descript.stat - chooses the kind of descriptive statistic compare.efficiency<-function(sample.size, num.samples, descript.stat){ # Set the seed so that results can be reproduced set.seed(5304) # Generate data from normal distribution x.data<-rnorm(sample.size * num.samples, 0, 1) cat('Random numbers from normal distribtuion as one vector\n') print(x.data) cat('Put vector of normal random numbers into a matrix where each\n') cat('row represents a sample and each column are the values for the sample\n') x.samples<-matrix(x.data, ncol=sample.size, nrow=num.samples) cat('view the matrix\n') print(x.samples) cat('summarize the observations across columns to get means\n') x.stat<-apply(x.samples, 1, descript.stat) cat('Descriptives on the statistic\n') print(x.stat) print(summary(x.stat)) cat('standard deviation of descritive statistic\n') print(sd(x.stat)) } compare.efficiency(sample.size=5, num.samples=10, descript.stat=mean) compare.efficiency(sample.size=15, num.samples=10, descript.stat=mean) compare.efficiency(sample.size=25, num.samples=10, descript.stat=mean) compare.efficiency(sample.size=35, num.samples=10, descript.stat=mean) sd.points<-c(.488,.222,.148,.115) mean.points<-c(.005,.019,.072,.003) par(mfrow=c(2,2)) plot(1:4, mean.points) lines(1:4, mean.points) plot(1:4, sd.points) lines(1:4, sd.points)