rep20

rep <- 25
ci.left <- numeric(rep)
ci.right <- numeric(rep)

for(i in 1:rep){
  x <-rnorm(15, mean=100, sd=10)
  ci <- t.test(x)$conf.int
  ci.left[i] <- ci[1]
  ci.right[i] <- ci[2]
}

does.not.cover <- (ci.left>100) | (ci.right<100)

#limits for the x-axis
a <- min(ci.left)
b <- max(ci.right)

# Draw the axes
plot(0, 0, type='n', ylim=c(a,b), xlim=c(0,rep), ann=FALSE)

# Draw line segments; let vector does.not.cover select the color.
segments(y0=ci.left, x0=1:rep, y1=ci.right, x1=1:rep, col=ifelse(does.not.cover, 'red', 'black'))

# Finally, draw a vertical line to show the population parameter
abline(h=100)

plot of chunk unnamed-chunk-1

rep 100

rep <- 100
ci.left <- numeric(rep)
ci.right <- numeric(rep)

for(i in 1:rep){
  x <-rnorm(15, mean=100, sd=10)
  ci <- t.test(x)$conf.int
  ci.left[i] <- ci[1]
  ci.right[i] <- ci[2]
}

does.not.cover <- (ci.left>100) | (ci.right<100)

#limits for the x-axis
a <- min(ci.left)
b <- max(ci.right)

# Draw the axes
plot(0, 0, type='n', ylim=c(a,b), xlim=c(0,rep), ann=FALSE)

# Draw line segments; let vector does.not.cover select the color.
segments(y0=ci.left, x0=1:rep, y1=ci.right, x1=1:rep, col=ifelse(does.not.cover, 'red', 'black'))

# Finally, draw a vertical line to show the population parameter
abline(h=100)

plot of chunk unnamed-chunk-2