In: Statistics and Probability
Using built in R functions to calculate mean and standard deviation. Simulate the X vector with a length of 50 from a normal distribution with mean 2 and variance 1. Using a for() loop, create 100 different confidence intervals and also create a variable that keeps a count of how many of these confidence intervals contain the true mean 2. Hint: Use If/else statement to keep track of whether the confidence interval contains the true mean or not within the loop. Use set.seed(i) (i.e., i in 1:100) to make sure that other people can reproduce your results and also you have different results for different replications. Print (count/100) at the end. If your solution is less than 95%, what actions can you do to improve the results? Demonstrate it using R.