P(\(\bar{X} < 1325\)):
mu = 1350
sigma = 163
n = 100
se = sigma / sqrt(n)
ans = pnorm(1325, mean = mu, sd = se)
ans
## [1] 0.06254653
P(\(1325 < \bar{X} < 1375\)):
mu = 1350
sigma = 163
n = 100
se = sigma / sqrt(n)
ans = pnorm(1375, mean = mu, sd = se) - pnorm(1325, mean = mu, sd = se)
ans
## [1] 0.8749069
P(\(\sum X_i < 1900\)):
n = 50
mu = 40
sigma = 20
mean_total = n * mu
sd_total = sqrt(n) * sigma
ans = pnorm(1900, mean = mean_total, sd = sd_total)
ans
## [1] 0.2397501
P(\(\sum X_i > 2200\)):
n = 50
mu = 40
sigma = 20
mean_total = n * mu
sd_total = sqrt(n) * sigma
ans = pnorm(2200, mean = mean_total, sd = sd_total, lower.tail = FALSE)
ans
## [1] 0.0786496
P(\(X_1 + X_2 > 100\)):
lambda = 1/80
n_sim = 1000
laser1_lifetimes = rexp(n_sim, lambda)
laser2_lifetimes = rexp(n_sim, lambda)
sum_lifetimes = laser1_lifetimes + laser2_lifetimes
prob = mean(sum_lifetimes > 100)
prob
## [1] 0.628
P(\(X_1 < 50\) and \(X_2 < 50\)):
lambda = 1/80
n_sim = 1000
laser1_lifetimes = rexp(n_sim, lambda)
laser2_lifetimes = rexp(n_sim, lambda)
prob = mean((laser1_lifetimes < 50) & (laser2_lifetimes < 50))
prob
## [1] 0.239
num_samples = 500
n1 = 5
n2 = 50
samples_uniform_n5 = replicate(num_samples, runif(n1, min = 0, max = 5))
samples_uniform_n50 = replicate(num_samples, runif(n2, min = 0, max = 5))
sample_means_uniform_n5 = colMeans(samples_uniform_n5)
sample_means_uniform_n50 = colMeans(samples_uniform_n50)
avg_sample_means_uniform_n5 = mean(sample_means_uniform_n5)
avg_sample_means_uniform_n50 = mean(sample_means_uniform_n50)
theoretical_mean_uniform = (0 + 5) / 2
cat("Uniform Distribution:\n")
## Uniform Distribution:
cat("(a) Average of sample means (n=5):", avg_sample_means_uniform_n5, "\n")
## (a) Average of sample means (n=5): 2.515572
cat("(a) Average of sample means (n=50):", avg_sample_means_uniform_n50, "\n")
## (a) Average of sample means (n=50): 2.512252
cat("(a) Theoretical expected value:", theoretical_mean_uniform, "\n\n")
## (a) Theoretical expected value: 2.5
var_sample_means_uniform_n5 = var(sample_means_uniform_n5)
var_sample_means_uniform_n50 = var(sample_means_uniform_n50)
theoretical_var_uniform = (5 - 0)^2 / 12
theoretical_var_sample_means_uniform_n5 = theoretical_var_uniform / n1
theoretical_var_sample_means_uniform_n50 = theoretical_var_uniform / n2
cat("(b) Variance of sample means (n=5):", var_sample_means_uniform_n5, "\n")
## (b) Variance of sample means (n=5): 0.426051
cat("(b) Variance of sample means (n=50):", var_sample_means_uniform_n50, "\n")
## (b) Variance of sample means (n=50): 0.04378969
cat("(b) Theoretical variance of sample means (n=5):", theoretical_var_sample_means_uniform_n5, "\n")
## (b) Theoretical variance of sample means (n=5): 0.4166667
cat("(b) Theoretical variance of sample means (n=50):", theoretical_var_sample_means_uniform_n50, "\n\n")
## (b) Theoretical variance of sample means (n=50): 0.04166667
hist(sample_means_uniform_n5, main = "Histogram of Sample Means (Uniform, n=5)", xlab = "Sample Mean")
hist(sample_means_uniform_n50, main = "Histogram of Sample Means (Uniform, n=50)", xlab = "Sample Mean")
### (d)
qqnorm(sample_means_uniform_n5, main = "Normal Q-Q Plot (Uniform, n=5)")
qqline(sample_means_uniform_n5)
qqnorm(sample_means_uniform_n50, main = "Normal Q-Q Plot (Uniform, n=50)")
qqline(sample_means_uniform_n50)
### (e)
cat("(e) For the uniform distribution, the averages of the sample means for both n=5 and n=50 are very close to the theoretical expected value of 2.5. The variances of the sample means decrease as the sample size increases, approaching the theoretical values (population variance divided by n).\n\n")
## (e) For the uniform distribution, the averages of the sample means for both n=5 and n=50 are very close to the theoretical expected value of 2.5. The variances of the sample means decrease as the sample size increases, approaching the theoretical values (population variance divided by n).
cat("The histograms show that as the sample size increases from n=5 to n=50, the distribution of the sample means becomes more bell-shaped and centered around the theoretical mean. The normal Q-Q plots indicate that the distribution of sample means for n=50 is much closer to a normal distribution than for n=5.\n\n")
## The histograms show that as the sample size increases from n=5 to n=50, the distribution of the sample means becomes more bell-shaped and centered around the theoretical mean. The normal Q-Q plots indicate that the distribution of sample means for n=50 is much closer to a normal distribution than for n=5.
cat("This illustrates the Central Limit Theorem. Even though the original uniform distribution is not normal, the distribution of the sample means approaches a normal distribution as the sample size grows. The variability of these sample means also decreases with larger sample sizes.\n\n")
## This illustrates the Central Limit Theorem. Even though the original uniform distribution is not normal, the distribution of the sample means approaches a normal distribution as the sample size grows. The variability of these sample means also decreases with larger sample sizes.
n_binom = 15
p_binom = 0.3
samples_binom_n5 = replicate(num_samples, rbinom(n1, size = n_binom, prob = p_binom))
samples_binom_n50 = replicate(num_samples, rbinom(n2, size = n_binom, prob = p_binom))
sample_means_binom_n5 = colMeans(samples_binom_n5)
sample_means_binom_n50 = colMeans(samples_binom_n50)
avg_sample_means_binom_n5 = mean(sample_means_binom_n5)
avg_sample_means_binom_n50 = mean(sample_means_binom_n50)
theoretical_mean_binom = n_binom * p_binom
cat("Binomial Distribution (n=15, p=0.3):\n")
## Binomial Distribution (n=15, p=0.3):
cat("(a) Average of sample means (n=5):", avg_sample_means_binom_n5, "\n")
## (a) Average of sample means (n=5): 4.4812
cat("(a) Average of sample means (n=50):", avg_sample_means_binom_n50, "\n")
## (a) Average of sample means (n=50): 4.49192
cat("(a) Theoretical expected value:", theoretical_mean_binom, "\n\n")
## (a) Theoretical expected value: 4.5
var_sample_means_binom_n5 = var(sample_means_binom_n5)
var_sample_means_binom_n50 = var(sample_means_binom_n50)
theoretical_var_binom = n_binom * p_binom * (1 - p_binom)
theoretical_var_sample_means_binom_n5 = theoretical_var_binom / n1
theoretical_var_sample_means_binom_n50 = theoretical_var_binom / n2
cat("(b) Variance of sample means (n=5):", var_sample_means_binom_n5, "\n")
## (b) Variance of sample means (n=5): 0.5889044
cat("(b) Variance of sample means (n=50):", var_sample_means_binom_n50, "\n")
## (b) Variance of sample means (n=50): 0.05906885
cat("(b) Theoretical variance of sample means (n=5):", theoretical_var_sample_means_binom_n5, "\n")
## (b) Theoretical variance of sample means (n=5): 0.63
cat("(b) Theoretical variance of sample means (n=50):", theoretical_var_sample_means_binom_n50, "\n\n")
## (b) Theoretical variance of sample means (n=50): 0.063
hist(sample_means_binom_n5, main = "Histogram of Sample Means (Binomial, n=5)", xlab = "Sample Mean")
hist(sample_means_binom_n50, main = "Histogram of Sample Means (Binomial, n=50)", xlab = "Sample Mean")
### (d)
qqnorm(sample_means_binom_n5, main = "Normal Q-Q Plot (Binomial, n=5)")
qqline(sample_means_binom_n5)
qqnorm(sample_means_binom_n50, main = "Normal Q-Q Plot (Binomial, n=50)")
qqline(sample_means_binom_n50)
### (e)
cat("(e) For the binomial distribution, the averages of the sample means are close to the theoretical expected value of 4.5. The variances of the sample means decrease with the larger sample size, consistent with theory.\n\n")
## (e) For the binomial distribution, the averages of the sample means are close to the theoretical expected value of 4.5. The variances of the sample means decrease with the larger sample size, consistent with theory.
cat("The histograms show a trend towards a more symmetric, bell-shaped distribution as the sample size increases. The normal Q-Q plot for n=50 shows points lying closer to the straight line than for n=5, indicating a better approximation to a normal distribution.\n\n")
## The histograms show a trend towards a more symmetric, bell-shaped distribution as the sample size increases. The normal Q-Q plot for n=50 shows points lying closer to the straight line than for n=5, indicating a better approximation to a normal distribution.
cat("The Central Limit Theorem applies here as well. Even though the binomial distribution is discrete, the distribution of its sample means becomes approximately normal for larger sample sizes.\n\n")
## The Central Limit Theorem applies here as well. Even though the binomial distribution is discrete, the distribution of its sample means becomes approximately normal for larger sample sizes.
lambda_exp = 5
samples_exp_n5 = replicate(num_samples, rexp(n1, rate = lambda_exp))
samples_exp_n50 = replicate(num_samples, rexp(n2, rate = lambda_exp))
sample_means_exp_n5 = colMeans(samples_exp_n5)
sample_means_exp_n50 = colMeans(samples_exp_n50)
avg_sample_means_exp_n5 = mean(sample_means_exp_n5)
avg_sample_means_exp_n50 = mean(sample_means_exp_n50)
theoretical_mean_exp = 1 / lambda_exp
cat("Exponential Distribution (λ = 5):\n")
## Exponential Distribution (λ = 5):
cat("(a) Average of sample means (n=5):", avg_sample_means_exp_n5, "\n")
## (a) Average of sample means (n=5): 0.195069
cat("(a) Average of sample means (n=50):", avg_sample_means_exp_n50, "\n")
## (a) Average of sample means (n=50): 0.2008036
cat("(a) Theoretical expected value:", theoretical_mean_exp, "\n\n")
## (a) Theoretical expected value: 0.2
var_sample_means_exp_n5 = var(sample_means_exp_n5)
var_sample_means_exp_n50 = var(sample_means_exp_n50)
theoretical_var_exp = 1 / lambda_exp^2
theoretical_var_sample_means_exp_n5 = theoretical_var_exp / n1
theoretical_var_sample_means_exp_n50 = theoretical_var_exp / n2
cat("(b) Variance of sample means (n=5):", var_sample_means_exp_n5, "\n")
## (b) Variance of sample means (n=5): 0.008409833
cat("(b) Variance of sample means (n=50):", var_sample_means_exp_n50, "\n")
## (b) Variance of sample means (n=50): 0.0007785209
cat("(b) Theoretical variance of sample means (n=5):", theoretical_var_sample_means_exp_n5, "\n")
## (b) Theoretical variance of sample means (n=5): 0.008
cat("(b) Theoretical variance of sample means (n=50):", theoretical_var_sample_means_exp_n50, "\n\n")
## (b) Theoretical variance of sample means (n=50): 8e-04
hist(sample_means_exp_n5, main = "Histogram of Sample Means (Exponential, n=5)", xlab = "Sample Mean")
hist(sample_means_exp_n50, main = "Histogram of Sample Means (Exponential, n=50)", xlab = "Sample Mean")
### (d)
qqnorm(sample_means_exp_n5, main = "Normal Q-Q Plot (Exponential, n=5)")
qqline(sample_means_exp_n5)
qqnorm(sample_means_exp_n50, main = "Normal Q-Q Plot (Exponential, n=50)")
qqline(sample_means_exp_n50)
### (e)
cat("(e) For the exponential distribution, even though the original distribution is heavily skewed, the averages of the sample means are close to the theoretical expected value of 0.2. The variances of the sample means decrease significantly with the larger sample size.\n\n")
## (e) For the exponential distribution, even though the original distribution is heavily skewed, the averages of the sample means are close to the theoretical expected value of 0.2. The variances of the sample means decrease significantly with the larger sample size.
cat("The histograms clearly show the transformation from a skewed distribution (for n=5) to a more symmetric, bell-shaped distribution (for n=50). The normal Q-Q plot for n=50 is much closer to a straight line than for n=5, indicating a better approximation to a normal distribution.\n\n")
## The histograms clearly show the transformation from a skewed distribution (for n=5) to a more symmetric, bell-shaped distribution (for n=50). The normal Q-Q plot for n=50 is much closer to a straight line than for n=5, indicating a better approximation to a normal distribution.
cat("The Central Limit Theorem is powerfully demonstrated here. It shows that even with a non-symmetric original distribution, the distribution of the sample mean tends towards normality as the sample size grows.\n\n")
## The Central Limit Theorem is powerfully demonstrated here. It shows that even with a non-symmetric original distribution, the distribution of the sample mean tends towards normality as the sample size grows.
mu_poisson = 2
samples_poisson_n5 = replicate(num_samples, rpois(n1, lambda = mu_poisson))
samples_poisson_n50 = replicate(num_samples, rpois(n2, lambda = mu_poisson))
sample_means_poisson_n5 = colMeans(samples_poisson_n5)
sample_means_poisson_n50 = colMeans(samples_poisson_n50)
avg_sample_means_poisson_n5 = mean(sample_means_poisson_n5)
avg_sample_means_poisson_n50 = mean(sample_means_poisson_n50)
theoretical_mean_poisson = mu_poisson
cat("Poisson Distribution (μ = 2):\n")
## Poisson Distribution (μ = 2):
cat("(a) Average of sample means (n=5):", avg_sample_means_poisson_n5, "\n")
## (a) Average of sample means (n=5): 2.052
cat("(a) Average of sample means (n=50):", avg_sample_means_poisson_n50, "\n")
## (a) Average of sample means (n=50): 1.99484
cat("(a) Theoretical expected value:", theoretical_mean_poisson, "\n\n")
## (a) Theoretical expected value: 2
var_sample_means_poisson_n5 = var(sample_means_poisson_n5)
var_sample_means_poisson_n50 = var(sample_means_poisson_n50)
theoretical_var_poisson = mu_poisson
theoretical_var_sample_means_poisson_n5 = theoretical_var_poisson / n1
theoretical_var_sample_means_poisson_n50 = theoretical_var_poisson / n2
cat("(b) Variance of sample means (n=5):", var_sample_means_poisson_n5, "\n")
## (b) Variance of sample means (n=5): 0.3987335
cat("(b) Variance of sample means (n=50):", var_sample_means_poisson_n50, "\n")
## (b) Variance of sample means (n=50): 0.04157573
cat("(b) Theoretical variance of sample means (n=5):", theoretical_var_sample_means_poisson_n5, "\n")
## (b) Theoretical variance of sample means (n=5): 0.4
cat("(b) Theoretical variance of sample means (n=50):", theoretical_var_sample_means_poisson_n50, "\n\n")
## (b) Theoretical variance of sample means (n=50): 0.04
hist(sample_means_poisson_n5, main = "Histogram of Sample Means (Poisson, n=5)", xlab = "Sample Mean")
hist(sample_means_poisson_n50, main = "Histogram of Sample Means (Poisson, n=50)", xlab = "Sample Mean")
### (d)
qqnorm(sample_means_poisson_n5, main = "Normal Q-Q Plot (Poisson, n=5)")
qqline(sample_means_poisson_n5)
qqnorm(sample_means_poisson_n50, main = "Normal Q-Q Plot (Poisson, n=50)")
qqline(sample_means_poisson_n50)
### (e)
cat("(e) For the Poisson distribution, the averages of the sample means for both sample sizes are very close to the theoretical mean of 2. The variances of the sample means decrease significantly from n=5 to n=50.\n\n")
## (e) For the Poisson distribution, the averages of the sample means for both sample sizes are very close to the theoretical mean of 2. The variances of the sample means decrease significantly from n=5 to n=50.
cat("The histograms show a clear progression from a slightly skewed discrete distribution (for n=5) towards a more continuous and symmetric bell shape (for n=50). The normal Q-Q plot for n=50 shows a much better fit to the normal line compared to n=5.\n\n")
## The histograms show a clear progression from a slightly skewed discrete distribution (for n=5) towards a more continuous and symmetric bell shape (for n=50). The normal Q-Q plot for n=50 shows a much better fit to the normal line compared to n=5.
cat("The Central Limit Theorem again explains these observations. As the sample size increases, the distribution of the sample means of a Poisson distribution approximates a normal distribution, and the spread of these means decreases.\n")
## The Central Limit Theorem again explains these observations. As the sample size increases, the distribution of the sample means of a Poisson distribution approximates a normal distribution, and the spread of these means decreases.