Can anyone Briefly describe what the following piece of R code is doing/showing?
n.fake = 1000
x = seq (1,5); n = length (x)
cover.68 = rep(NA, n.fake)
cover.95 = rep(NA, n.fake)
a = 5; b = 1;
for (i in 1 : n.fake)
{
#Fit regression model
y= a + b*x + rnorm(n,0,0.9);
m= lm(y~x)
b.hat = coef (m) [2]
#Calculate CI
sse = sum((y-fitted.values(m))^2)
s_2 = sse/(length(x)-2)
sxx = sum(x^2-mean(x)^2)
bse = sqrt(s_2/sxx )
cover.68[i] = abs (b-b.hat)< qt(0.84, n-2)*bse
cover.95[i] = abs (b-b.hat)< qt(0.975, n-2)*bse
}
mean(cover.68)
mean(cover.95)