Last active
February 12, 2017 16:56
-
-
Save cdriveraus/8cc5272480151d8f24f5c1ab3afa5277 to your computer and use it in GitHub Desktop.
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
n=10000 | |
beta=.4 | |
#no effect | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
sm=s+rnorm(30,0,1) #with measurement error | |
x=rnorm(30,0,1) | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r1=length(c(p[p<.025],p[p>.975])) | |
n=10000 | |
beta=.4 | |
#no effect | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
sm=s+rnorm(30,0,1) #with measurement error | |
x=rnorm(30,0,1) | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r1=length(c(p[p<.05])) | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
sm=s #+rnorm(30,0,1) #without measurement error | |
x=rnorm(30,0,1) | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r2=length(c(p[p<.05])) | |
#some effect | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
x=rnorm(30,0,1) | |
sm=s+beta*x+rnorm(30,0,1) #with measurement error | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r3=length(c(p[p<.05])) | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
x=rnorm(30,0,1) | |
sm=s+beta*x #+rnorm(30,0,1) #without measurement error | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r4=length(c(p[p<.05])) | |
#proportion of sig results that are true when no measurement error: | |
r4/(r2+r4) | |
#proportion of sig results that are true when measurement error: | |
r3/(r1+r3) | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
sm=s #+rnorm(30,0,1) #without measurement error | |
x=rnorm(30,0,1) | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r2=length(c(p[p<.025],p[p>.975])) | |
#some effect | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
x=rnorm(30,0,1) | |
sm=s+beta*x+rnorm(30,0,1) #with measurement error | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r3=length(c(p[p<.025],p[p>.975])) | |
p=c() | |
for(i in 1:n){ | |
s=rnorm(30,0,1) | |
x=rnorm(30,0,1) | |
sm=s+beta*x #+rnorm(30,0,1) #without measurement error | |
p=c(p,summary(lm(sm~x))$coefficients[2,4]) | |
} | |
r4=length(c(p[p<.025],p[p>.975])) | |
#proportion of sig results that are true when no measurement error: | |
r4/(r2+r4) | |
#proportion of sig results that are true when measurement error: | |
r3/(r1+r3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment