set.seed(1)
n_population <- 1e6
xx_population <- runif(n_population)
param <- 0.5
yy_population <- 2+param*xx_population+rnorm(n_population,0,0.5)
n_analyses <- 100
n_sample <- 30
CIs <- matrix(NA,nrow=n_analyses,ncol=3)
for ( ii in 1:n_analyses ) {
index <- sample(1:n_population,n_sample)
model <- lm(yy_population[index]~xx_population[index])
CIs[ii,] <- c(confint(model)[2,1],coef(model)[2],confint(model)[2,2])
}
opar <- par(mai=c(.5,.1,.1,.1))
ii <- 1
plot(range(CIs),c(ii,ii),type="n",xlab="",ylab="",yaxt="n")
lines(CIs[ii,c(1,3)],rep(ii,2),col=2-(CIs[ii,1]<param¶m<CIs[ii,3]))
points(CIs[ii,2],ii,pch=19,col=2-(CIs[ii,1]<0.5&0.5<CIs[ii,3]))
abline(v=param,lty=2,lwd=2)
plot(range(CIs),c(1,n_analyses),type="n",xlab="",ylab="",yaxt="n")
sapply(1:n_analyses,function(ii)lines(CIs[ii,c(1,3)],rep(ii,2),col=2-(CIs[ii,1]<param¶m<CIs[ii,3])))
points(CIs[,2],1:n_analyses,pch=19,col=2-(CIs[,1]<0.5&0.5<CIs[,3]))
abline(v=param,lty=2,lwd=2)
set.seed(1)
n_population <- 1e6
xx_population <- runif(n_population)
param <- 0.5
yy_population <- 2+param*xx_population + rnorm(n_population, 0, 0.5)
n_analyses <- 100
n_sample <- 30
CIs <- matrix(NA, nrow=n_analyses, ncol=3)
for ( ii in 1:n_analyses ) {
index <- sample(1:n_population,n_sample)
model <- lm(yy_population[index]~xx_population[index])
CIs[ii,] <- c(confint(model)[2,1],coef(model)[2],confint(model)[2,2])
}
opar <- par(mai=c(.5,.1,.1,.1))
ii <- 1
plot(range(CIs), c(ii,ii), type="n", xlab="", ylab="", yaxt="n")
lines(CIs[ii,c(1,3)], rep(ii,2),
col=2-(CIs[ii,1] < param¶m < CIs[ii,3]))
points(CIs[ii,2], ii, pch=19, col=2-(CIs[ii,1]<0.5&0.5<CIs[ii,3]))
abline(v=param,lty=2,lwd=2)
plot(range(CIs),c(1,n_analyses),type="n",xlab="",ylab="",yaxt="n")
sapply(1:n_analyses,function(ii)lines(CIs[ii,c(1,3)],rep(ii,2),
col=2-(CIs[ii,1]<param¶m<CIs[ii,3])))
points(CIs[,2],1:n_analyses,pch=19,col=2-(CIs[,1]<0.5&0.5<CIs[,3]))
abline(v=param,lty=2,lwd=2)