I am trying to write a confidence interval simulation in R. The idea is to simulate several samples from a known distribution, calculate the mean and 95% CI for the mean, and then plot all confidence intervals in such a way that every confidence interval catching the "unknown parameter" will be in one color and others in different color. I also wish to calculate the percentage of CI's "catching" the parameter.

I have stared doing it:

Code:

```
n = 30
numOfSamples = 10
mu = 0
std = 2
d = data.frame()
for (sampleID in 1:numOfSamples)
{
x = rnorm(n,mu,std)
s = rep(sampleID,n)
temp = cbind(x,s)
d = rbind(d,temp)
}
for (sampleID in 1:numOfSamples)
{
d_temp = subset(d,s==sampleID)
avg = mean(d_temp$x)
ci = t.test(d_temp$x, data = d_temp)$conf.int
}
```

1. Saving the means and CI's of each sample in a dataset.

2. Creating the plot, which should look like this:

Plot

or something similar. I prefer ggplot2 for it to be nicer, but any plot will do....

I believe that my code is nearly ready, just saving and plotting...

Thank you in advance !