Skip to content

Instantly share code, notes, and snippets.

@bwengals
Last active January 19, 2017 23:27
Show Gist options
  • Save bwengals/a7c27edfb951f8a712fe31a420fb6d39 to your computer and use it in GitHub Desktop.
Save bwengals/a7c27edfb951f8a712fe31a420fb6d39 to your computer and use it in GitHub Desktop.
R code for Gelman & Carlin --- Beyond Power Calculations
retrodesign <- function(A, s, alpha=.05, df=Inf, n.sims=10000){
z <- qt(1-alpha/2, df)
p.hi <- 1 - pt(z-A/s, df)
p.lo <- pt(-z-A/s, df)
power <- p.hi + p.lo
typeS <- p.lo/power
estimate <- A + s*rt(n.sims,df)
significant <- abs(estimate) > s*z
exaggeration <- mean(abs(estimate)[significant])/A
return(list(power=power, typeS=typeS, exaggeration=exaggeration))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment