Skip to content

Instantly share code, notes, and snippets.

@natbusa
Created October 14, 2013 22:09
Show Gist options
  • Save natbusa/6983059 to your computer and use it in GitHub Desktop.
Save natbusa/6983059 to your computer and use it in GitHub Desktop.
mean statistics from 4 samples out of a population normally distributed N(0,1) behaves as N(0,0.5)
library("ggplot2")
# calculate a 1000 iterations for a selection of four sample from
# a normal population N(0,1)
mean.statistics= sapply(1:1000, function(x) {sum(rnorm(4,0,1))/4})
#base plot, but no functions
p = ggplot(data.frame(mean.statistics), aes(mean.statistics)) + xlim(-2,2)
# The statistics of the sample mean (four samples), behaves as N(0,0.5)
p + geom_histogram(aes(y=..density..), binwidth=0.125, colour='darkgreen') +
geom_density(colour='red', aes(mean.statistics)) +
stat_function(fun=function(x) {dnorm(x,0,0.5)}, colour='yellow')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment