Created
October 14, 2013 22:09
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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