Skip to content

Instantly share code, notes, and snippets.

@vasishth
Created August 27, 2015 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasishth/d85f06640346d1033a8e to your computer and use it in GitHub Desktop.
Save vasishth/d85f06640346d1033a8e to your computer and use it in GitHub Desktop.
Simulating Type S and Type M errors
## probable effect size derived from past studies:
D<-15
## SE from the study of interest:
se<-46
stddev<-se*sqrt(37)
nsim<-10000
drep<-rep(NA,nsim)
for(i in 1:nsim){
drep[i]<-mean(rnorm(37,mean=D,sd=stddev))
}
## which cells in drep are significant at alpha=0.05?
signif<-which(abs(drep/se)>2)
## Type S error rate | signif:
types_sig<-mean(drep[signif]<0)
## Type S error rate | non-signif:
types_nonsig<-mean(drep[-signif]<0)
## Type M error rate | signif:
typem_sig<-mean(abs(drep[signif])/D)
## Type M error rate | not-signif:
typem_nonsig<-mean(abs(drep[-signif])/D)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment