Coverage - Illustration of coverage of intervals. See Chapter 4 in Regression and Other Stories.


Simulate

n_rep <- 100
est <- rep(NA, n_rep)
conf <- array(NA, c(n_rep, 4))
mu <- 6
sigma <- 4
for (i in 1:n_rep){
  y <- rnorm(1, mu, sigma)
  est[i] <- y
  conf[i,] <- y + c(-2, -.67, .67, 2) * sigma
}

Plot

par(mar=c(3,3,0,0), mgp=c(1.5,.5,0), tck=-.01)
plot(c(-2, n_rep+2), range(conf), bty="l", xlab="Simulation", ylab="Estimate, 50%, and 95% confidence interval", xaxs="i", yaxt="n", type="n")
axis(2, seq(-10,20,10))
points(1:n_rep, est, pch=20)
abline(mu, 0, col="gray")
for (i in 1:n_rep){
  lines(c(i,i), conf[i,c(1,4)], lwd=.8)
  lines(c(i,i), conf[i,c(2,3)], lwd=2)
}

LS0tCnRpdGxlOiAiUmVncmVzc2lvbiBhbmQgT3RoZXIgU3RvcmllczogQ292ZXJhZ2UiCmF1dGhvcjogIkFuZHJldyBHZWxtYW4sIEplbm5pZmVyIEhpbGwsIEFraSBWZWh0YXJpIgpkYXRlOiAiYHIgZm9ybWF0KFN5cy5EYXRlKCkpYCIKb3V0cHV0OgogIGh0bWxfZG9jdW1lbnQ6CiAgICB0aGVtZTogcmVhZGFibGUKICAgIHRvYzogdHJ1ZQogICAgdG9jX2RlcHRoOiAyCiAgICB0b2NfZmxvYXQ6IHRydWUKICAgIGNvZGVfZG93bmxvYWQ6IHRydWUKLS0tCkNvdmVyYWdlIC0gSWxsdXN0cmF0aW9uIG9mIGNvdmVyYWdlIG9mIGludGVydmFscy4gU2VlIENoYXB0ZXIgNCBpbgpSZWdyZXNzaW9uIGFuZCBPdGhlciBTdG9yaWVzLgoKLS0tLS0tLS0tLS0tLQoKCmBgYHtyIHNldHVwLCBpbmNsdWRlPUZBTFNFfQprbml0cjo6b3B0c19jaHVuayRzZXQobWVzc2FnZT1GQUxTRSwgZXJyb3I9RkFMU0UsIHdhcm5pbmc9RkFMU0UsIGNvbW1lbnQ9T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