Search code examples
rbinomial-coefficients

How to find R approximation for CLT


The distribution for the number of faulty lightbulbs is the binomial distribution. i.e. the number of faulty lightbulbs is:

enter image description here

Use R to produce a graphical representation that compares the true pmf for the number of faulty lightbulbs found and its approximation using the central limit theorem.

So I've produced a graph for the pmf in r as using the code below. However I'm having an issue with the CLT part of the question. We haven't covered that part of the syllabus yet.

n <- 100
p <- 0.015
# pmf
x <- (0:n)
px <- dbinom(x,n,p) 
# Plot pmf
plot(x,px,type="h",ylab="p(x)" ,main=paste("Binomial(",n,",",p,")",sep=""))

enter image description here


Solution

  • I am not sure if this is what you want for the CLT plot:

    xclt <- seq(0,n,by = 0.001)
    clt <- dnorm(xclt,mean = n*p,sd = sqrt(n*p*(1-p)))
    lines(xclt,clt,col="red",lty= 2)
    legend(80,0.3,legend = c("bin","clt"),col = c("black","red"),lty = c(1,2))
    

    such that enter image description here