Created
October 17, 2017 08:44
-
-
Save richarddmorey/1b408eaa608943379e01204fc4333bd5 to your computer and use it in GitHub Desktop.
Inverse function of Bayes factor for t test
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
## Given a (scaled Cauchy) Bayes factor for the null against the | |
## alternative (Rouder et al 2009), yields the t statistic | |
## that would yield it. The ... arguments are passed to | |
## the ttest.tstat function. | |
bf.inv = Vectorize(function(b10, ...){ | |
fn = Vectorize(function(t,...){ | |
BayesFactor::ttest.tstat(t,...)[["bf"]] | |
}, "t") | |
t0 = optimize(function(t0, ...){ | |
t = sqrt(t0 / (1 - t0)) | |
b = fn(t, ...) | |
(b10 - exp(b))^2 | |
}, c(0,1), ...)$minimum | |
sqrt(t0 / (1 - t0)) | |
},"b10") | |
q = bf.inv(1/3, n1 = 20, rscale = sqrt(2)/2) | |
## Test it (should be 1/3) | |
BayesFactor::ttest.tstat(q, n1 = 20, rscale = sqrt(2)/2, simple = TRUE) | |
## Make a plot | |
b = seq(.05,20, len = 50) | |
plot(b, bf.inv(b, n1 = 20), ty = 'l', ylab = "t statistic",xlab = "Bayes factor", log = "x") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment