User Tools

Site Tools


sampling

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
sampling [2018/03/13 16:48] – [Sample statistics] hkimscilsampling [2018/03/13 16:49] – [Sample statistics] hkimscil
Line 66: Line 66:
  
 var_ <- new.env() var_ <- new.env()
-n<-20            ## Sample n individuals at a time +n<-20        ## Sample n individuals at a time 
-p_mean<-0        ## Population mean +p_mean<-0    ## Population mean 
-p_sd<-1            ## Population standard deviation +p_sd<-1      ## Population standard deviation 
-N<-500            ## Number of times the experiment (sampling) is replicated+N<-500       ## Number of times the experiment (sampling) is replicated
  
 pdf('SE.pdf') pdf('SE.pdf')
  
-for(i in 1:N)                                ## do the experiment N times+for(i in 1:N)     ## do the experiment N times
 { {
-smp<-rnorm(n,p_mean,p_sd)                 ## sample n data points from the population+smp<-rnorm(n,p_mean,p_sd)    ## sample n data points from the population
  
-var_$x_bar<-c(var_$x_bar,mean(smp))         ## keep track of the mean (x_bar) from each sample+var_$x_bar<-c(var_$x_bar,mean(smp))     ## keep track of the mean (x_bar) from each sample 
 + 
 +hist(var_$x_bar,probability=TRUE,col="red",xlim=c(-4,4),xlab="x / x_bar",main="",ylim=c(0,2.2))   
 +# Plot a histogram of x_bar values
  
-hist(var_$x_bar,probability=TRUE,col="red",xlim=c(-4,4),xlab="x / x_bar",main="",ylim=c(0,2.2))  # Plot a histogram of x_bar values 
 points(mean(smp),0,pch=19,cex=1.5,col='black') points(mean(smp),0,pch=19,cex=1.5,col='black')
 curve(dnorm(x,p_mean,p_sd/sqrt(n)),lwd=3,add=TRUE) curve(dnorm(x,p_mean,p_sd/sqrt(n)),lwd=3,add=TRUE)
Line 86: Line 88:
 text(2.5,1.5,labels=paste('standard deviation of\nsample means = ',round(sd(var_$x_bar),2),sep='') ) text(2.5,1.5,labels=paste('standard deviation of\nsample means = ',round(sd(var_$x_bar),2),sep='') )
  
-curve(dnorm(x,p_mean,p_sd),main="",ylab="",xlim=c(-4,4),xlab="X",col="blue",lwd=3,add=TRUE) ## Plot the sample+curve(dnorm(x,p_mean,p_sd),main="",ylab="",xlim=c(-4,4),xlab="X",col="blue",lwd=3,add=TRUE)  
 +## Plot the sample
  
 text(2.5,0.5,labels=paste('# of means drawn = ',i,sep='')) text(2.5,0.5,labels=paste('# of means drawn = ',i,sep=''))
Line 100: Line 103:
 dev.off() dev.off()
 </code> </code>
- +{{SE.pdf}} 
  
   * Variation See, [[:Variance]]: 225.0584138 (15^2)   * Variation See, [[:Variance]]: 225.0584138 (15^2)
sampling.txt · Last modified: 2020/12/04 22:37 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki