When prompted with the CLT questions from Unit 1, ChatGPT retuned the following code:

# Set seed for reproducibility
set.seed(123)

# Generate a population of 10,000,000 from a chi-square distribution with 2 degrees of freedom
population <- rchisq(10000000, df = 2)

# View the first few elements of the population
head(population)
## [1] 0.3644342 3.3915023 3.2417604 4.8961921 1.7580558 5.3346372
# Plot a histogram of the population
hist(population, breaks = 100, main = "Histogram of Population", xlab = "Value", ylab = "Frequency", col = "lightblue")

# Calculate the mean of the population
population_mean <- mean(population)

# Calculate the standard deviation of the population
population_sd <- sd(population)

# Display the results
population_mean
## [1] 2.000466
population_sd
## [1] 2.00042
# Sample size
n <- 50

# Expected mean of the sampling distribution (should equal population mean)
sampling_distribution_mean <- population_mean

# Standard error of the sampling distribution
sampling_distribution_se <- population_sd / sqrt(n)

# Display the results
sampling_distribution_mean
## [1] 2.000466
sampling_distribution_se
## [1] 0.2829022
# Number of samples
num_samples <- 10000

# Initialize a vector to store the sample means
sample_means <- numeric(num_samples)

# Draw 10,000 samples of size 50 and calculate their means
for (i in 1:num_samples) {
  sample_means[i] <- mean(sample(population, n))
}

# Plot a histogram of the sample means
hist(sample_means, breaks = 100, main = "Histogram of Sample Means", xlab = "Sample Mean", ylab = "Frequency", col = "lightgreen")

# Calculate the mean of the sample means
sample_means_mean <- mean(sample_means)

# Calculate the standard deviation of the sample means
sample_means_sd <- sd(sample_means)

# Display the results
sample_means_mean
## [1] 1.99713
sample_means_sd
## [1] 0.280973