1 de julho de 2020

Introduction

In probability theory, the central limit theorem (CLT) establishes that, in some situations, when independent random variables are added, their properly normalized sum tends toward a normal distribution (informally a bell curve) even if the original variables themselves are not normally distributed. The theorem is a key concept in probability theory because it implies that probabilistic and statistical methods that work for normal distributions can be applicable to many problems involving other types of distributions.

The Example

  • In the App, we explore the CLT for independent uniform distributed random variables in the (0,1) interval
  • We generate a sample of values with size equal to the size chosen by the user and calculate the their mean
  • We repeat the last step 10,000 times
  • We plot the empirical distribution

The code

`x <- rep(0,10000)
 for (i in 1:10000) {
   x[i] <- mean(runif(n = input$sample_size,min = 0, max = 1))
 }
 
 mean_norm <- 0.5
 sd_norm <- sqrt(1/(12*input$sample_size))
 y <- dnorm(x = seq(from=0,to=1,length.out= 10000),
            mean = mean_norm,sd = sd_norm)
 
 myData <- data.frame(n=seq(from=0,to=1,length.out= 10000),
                      x=x,y=y)
 
 ggplot(myData) +
   geom_density(aes(x=x),size=1) +
   geom_line(aes(x=n,y=y),col="red",size=2, alpha=0.3) +
   ggtitle("Empirical Uniform(0,1) vs Normal Distribution")`