Created
October 30, 2016 19:39
-
-
Save cdriveraus/24d288230918c9117229e6a04e6ac23a to your computer and use it in GitHub Desktop.
Does a 95% confidence interval contain the true parameter 95% of the time?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b=.8 | |
n=100 | |
nruns=10000 | |
out<-rep(NA,nruns) | |
for(i in 1:nruns){ | |
x=rnorm(n,3,2) | |
y=b*x + rnorm(n, 0, 3) | |
fit=lm(y~x) | |
summ=summary(fit) | |
upper=summ$coefficients[2,1]+2*summ$coefficients[2,2] | |
lower=summ$coefficients[2,1]-2*summ$coefficients[2,2] | |
out[i]<- b < upper & b > lower | |
} | |
sum(out)/nruns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment