#Q1. Central Limit theorem
##The Central Limit Theorem (CLT) is a fundamental concept in statistics that explains the behavior of the sample mean of a population. It states that when independent and identically distributed random variables are added, their sum tends toward a normal distribution regardless of the distribution of the original variables, provided the sample size is large enough. In other words, the CLT implies that the distribution of sample means tends to be normal, even if the distribution of the original population is not normal. This theorem is critical because it allows us to make statistical inferences about a population by examining a sample

#To Prove the Central Limit Theorem


xsamp <- 1                              # Sample size
xsim  <- 10000                           # Number of simulations

xrep <- rep( 0, xsim )                 # Repitions from 0 to 5000
for(i in 1:xsim)
{     x1       <- rgamma(xsamp, 15, 1) # Drawing from the population with a mean of 15
xrep[i] <- mean(x1)
}
# Creating a histogram
hist(xrep, xlim = c(0,15),             # Limits for the x-axis      
     col  = 'lightblue',                
     xlab = 'xmean',
     main = 'Histogram')

# Sample Size 6

xsamp <- 6                             # Sample size
xsim  <- 10000                           # Number of simulations

xrep <- rep( 0, xsim )                 # Repitions from 0 to 5000
for(i in 1:xsim)
{     x1       <- rgamma(xsamp, 15, 1) # Drawing from the population with a mean of 15
xrep[i] <- mean(x1)
}
# Creating a histogram
hist(xrep, xlim = c(0,15),             # Limits for the x-axis      
     col  = 'lightblue',                
     xlab = 'xmean',
     main = 'Histogram')

#Sample Size 36

xsamp <- 36                        # Sample size
xsim  <- 10000                           # Number of simulations


xrep <- rep( 0, xsim )                 # Repitions from 0 to 5000
for(i in 1:xsim)
{     x1       <- rgamma(xsamp, 15, 1) # Drawing from the population with a mean of 15
xrep[i] <- mean(x1)
}

# Creating a histogram 
hist(xrep, xlim = c(0,15),             # Limits for the x-axis      
     col  = 'lightblue',                
     xlab = 'xmean',
     main = 'Histogram')

xsamp <- 1200                       # Sample size
xsim  <- 10000                           # Number of simulations


xrep <- rep( 0, xsim )                 # Repitions from 0 to 5000
for(i in 1:xsim)
{     x1       <- rgamma(xsamp, 15, 1) # Drawing from the population with a mean of 15
xrep[i] <- mean(x1)
}

# Creating a histogram 
hist(xrep, xlim = c(0,15),             # Limits for the x-axis      
     col  = 'lightblue',                
     xlab = 'xmean',
     main = 'Histogram')