BIO 206: Demonstration of central limit theorem

The Bernoulli distribution, which is apparently not normal, is taken as an example for the central limit theorem.

One example of the Bernoulli distribution is a distribution of 0 or 1 when 1 has a certain probability of appearance. A single toss of a coin is a typical example of this.

Define a function for simulation

f.clt <- function(n, size, prob) {
    dat <- data.frame(value = rbinom(n = n, size = size, prob = prob)/size)
    ggplot(dat) + geom_bar(aes(x = factor(value), y = (..count..)/sum(..count..))) + 
        scale_y_continuous(name = "percentage") + scale_x_discrete(name = "")
}

n = 100, Ber(0.25)
You tossed an unfair coin. Everytime you got heads you scored 1. You did it 100 times.

f.clt(100, 1, 0.25)

plot of chunk unnamed-chunk-2

n = 1000, Ber(0.25)
You tossed an unfair coin. Everytime you got heads you scored 1. You did it 1000 times.

f.clt(1000, 1, 0.25)

plot of chunk unnamed-chunk-3

n = 1000, Average of 3, Ber(0.25)
You tossed an unfair coin 3 times. Everytime you did it you summed the number of heads (0 - 3), then divided it with 3 (average of 3). You did it 1000 times.

f.clt(1000, 3, 0.25)

plot of chunk unnamed-chunk-4

n = 1000, Average of 10, Ber(0.25)
You tossed an unfair coin 10 times. Everytime you did it you summed the number of heads (0 - 10), then divided it with 10 (average of 10). You did it 1000 times.

f.clt(1000, 10, 0.25)

plot of chunk unnamed-chunk-5

n = 1000, Average of 20, Ber(0.25)
You tossed an unfair coin 20 times. Everytime you did it you summed the number of heads (0 - 20), then divided it with 20 (average of 20). You did it 1000 times.

f.clt(1000, 20, 0.25)

plot of chunk unnamed-chunk-6

n = 1000, Average of 100, Ber(0.25)
You tossed an unfair coin 100 times. Everytime you did it you summed the number of heads (0 - 100), then divided it with 100 (average of 100). You did it 1000 times.

f.clt(1000, 100, 0.25)

plot of chunk unnamed-chunk-7