This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: mean(z) #display the mean of the "population" zsamp=sample(z,16) #takes a sample of 16 of the values zsamp #display the sample mean(zsamp) #mean of the sample zmeans=NULL #intialize vector to store results from repeated sampling for(i in 1:100){ #run the sampling 100 times and save the results zmeans=c(zmeans,mean(sample(z,16))) } mean(zmeans) sd(zmeans) x11() hist(zmeans) # Notice that the sd for the sample means is about 2.5 = 10/4 # This illustrates the square root rule, that increasing the sample size # by a factor of n decreases the sd of the sample mean by a factor of sqrt(n) ####################### sample from a list based on id numbers # create some fake data testdata = data.frame(id=seq(12), vals=c(83,22,87,55,60,97,81,79,100,83,94,43)) testdata Sheet1 Page 2 attach(testdata) # sample 3 observations based on the id numbers idsamp=sample(id,3) idsamp #corresponding values vals[idsamp] # display sampled data testdata[idsamp,]...
View
Full
Document
This note was uploaded on 09/11/2011 for the course STAT 200 taught by Professor Agniel during the Spring '09 term at University of Illinois at Urbana–Champaign.
 Spring '09
 Agniel

Click to edit the document details