Lab exercise your r prowess try graphing variance against


Lab: Exercise your R prowess!

Start the R software package. Select File/New script, and in the script box paste the following code:

clt<-function(sampleSize,samples=10000){

means<-numeric(samples)

for(j in 1:samples) {

means[j]<-mean(runif(sampleSize,0,1))

}

hist(means,xlab="Mean",

main=paste("Central Limit theorem demonstration\nVariance = ",round(sd(means)^2,8)),

xlim=c(0,1),ylim=c(0,4000),breaks=seq(0,1,0.05),

angle=60,density=25,col="dark green",border="black")

}

Highlight the code and press CTRL-r (hold down the control key and press "r"). This code creates a function that instructs R to collect means of 10000 samples of a given size and then print a frequency histogram of the 10000 means. Samples are chosen from a random number generator that selects numbers between 0 and 1. You can run the function for a sample size of 1 by clicking on the R console and then typing:

clt(1)

and pressing the enter key. Satisfy yourself that the underlying distribution is uniform.

Try running it for a range of sample sizes between 2 and 50 (for samples of size 5 the command is "clt(5)". In a paragraph comment on what happens to the frequency distributions. These distributions are known as "sampling distributions".

Note that the code also prints out the variance of the sample means. Run the code for samples of sizes 1, 5, 10, 20, 30, 40 and 50. Calculate the variance of the sampling distribution for each run and then graph variance against sample size. The R code for plotting y against x is:

plot(xVector, yVector, xlab="Label for the x-axis", ylab="Label for the y-axis")

where a vector is defined as a list of numbers separated by commas within the parentheses of "c( )". Try graphing variance against the inverse of sample size. Are the graphs you've encountered and created in this exercise consistent with the central limit theorem? What does the last one say about the utility of standard errors?

Attachment:- Assignment File.rar

Request for Solution File

Ask an Expert for Answer!!
Applied Statistics: Lab exercise your r prowess try graphing variance against
Reference No:- TGS02684165

Expected delivery within 24 Hours