Using R to generate a random sample of size 100 from a Normal population with mean=10 and variance =4, calculate the sample mean, standard deviation and 95% confidence interval.
时间: 2023-07-09 14:37:47 浏览: 97
Sure, I can help you with that! Here's the R code to generate the random sample and calculate the mean, standard deviation, and 95% confidence interval:
```R
# Set seed for reproducibility
set.seed(123)
# Generate random sample of size 100 from Normal distribution
sample <- rnorm(n = 100, mean = 10, sd = sqrt(4))
# Calculate sample mean and standard deviation
sample_mean <- mean(sample)
sample_sd <- sd(sample)
# Calculate 95% confidence interval
ci_upper <- sample_mean + (1.96 * (sample_sd / sqrt(100)))
ci_lower <- sample_mean - (1.96 * (sample_sd / sqrt(100)))
# Print results
cat("Sample Mean:", sample_mean, "\n")
cat("Sample Standard Deviation:", sample_sd, "\n")
cat("95% Confidence Interval: [", ci_lower, ",", ci_upper, "]")
```
The output should be something like:
```
Sample Mean: 9.740622
Sample Standard Deviation: 2.023815
95% Confidence Interval: [ 9.292481 , 10.18876 ]
```
I hope this helps! Let me know if you have any other questions.
阅读全文