Last active
January 20, 2016 00:42
-
-
Save benwhalley/ad26e9d44bffd1c7d71c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# effect on total variance | |
library(dplyr) | |
N=10000 | |
prob <- .25 | |
e_var = 1 | |
u_var = .25*e_var # see http://www.wolframalpha.com/input/?i=.1%3Db%2F%28a%2Bb%29 | |
icc = u_var/(u_var+e_var) | |
icc | |
e_sd = sqrt(e_var) | |
u_sd = sqrt(u_var) | |
df <- data.frame( | |
e = rnorm(N, sd=e_sd), | |
u = rnorm(N, sd=u_sd) | |
) | |
dat <- df %>% mutate( | |
ue= e + u, | |
itt = u>qnorm(prob, sd=sd(.$u)), | |
uerct = ifelse(itt, ue, NA) | |
) | |
var(dat$uerct, na.rm=T)/var(dat$ue) | |
# And the effect on tx estimate of underestimating true variance in | |
# one cell | |
library(reshape2) | |
rct <- data.frame( | |
a=rnorm(200000, mean=0, sd=1), | |
b=rnorm(200000, mean=.5, sd=1) | |
) %>% melt() | |
# t value halves when sd(b) is set to 2 | |
summary(lm(value~factor(variable), data=rct)) | |
rct <- data.frame( | |
a=rnorm(200000, mean=0, sd=1), | |
b=rnorm(200000, mean=.5, sd=2) | |
) %>% melt() | |
# F value halves when sd(b) is set to 2 | |
summary(lm(value~factor(variable), data=rct)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment