sampling

# Differences

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

 sampling [2018/03/13 16:48]hkimscil [Sample statistics] sampling [2018/03/13 16:49] (current)hkimscil [Sample statistics] Both sides previous revision Previous revision 2018/03/13 16:49 hkimscil [Sample statistics] 2018/03/13 16:48 hkimscil [Sample statistics] 2017/03/22 09:16 hkimscil [Probability sampling] 2017/03/16 08:24 hkimscil 2017/03/16 08:24 hkimscil 2017/03/16 08:21 hkimscil 2017/03/16 08:21 hkimscil 2017/03/16 08:18 hkimscil 2016/03/14 02:28 hkimscil 2016/03/14 02:27 hkimscil 2016/03/14 02:26 hkimscil 2016/03/06 14:20 hkimscil 2016/03/06 14:14 hkimscil 2016/03/06 13:59 hkimscil 2016/03/06 13:32 hkimscil 2016/03/06 13:27 hkimscil 2016/03/06 13:26 hkimscil created 2018/03/13 16:49 hkimscil [Sample statistics] 2018/03/13 16:48 hkimscil [Sample statistics] 2017/03/22 09:16 hkimscil [Probability sampling] 2017/03/16 08:24 hkimscil 2017/03/16 08:24 hkimscil 2017/03/16 08:21 hkimscil 2017/03/16 08:21 hkimscil 2017/03/16 08:18 hkimscil 2016/03/14 02:28 hkimscil 2016/03/14 02:27 hkimscil 2016/03/14 02:26 hkimscil 2016/03/06 14:20 hkimscil 2016/03/06 14:14 hkimscil 2016/03/06 13:59 hkimscil 2016/03/06 13:32 hkimscil 2016/03/06 13:27 hkimscil 2016/03/06 13:26 hkimscil created 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() ​ - + {{SE.pdf}} ​ * Variation See, [[:​Variance]]:​ 225.0584138 (15^2) * Variation See, [[:​Variance]]:​ 225.0584138 (15^2)