Skip to content

Instantly share code, notes, and snippets.

@fdabl
Last active July 30, 2018 14:24
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 fdabl/2144c01c0e8aec83e844c68e832a460f to your computer and use it in GitHub Desktop.
Save fdabl/2144c01c0e8aec83e844c68e832a460f to your computer and use it in GitHub Desktop.
bfx <- function(x, tstat, n, mu, gamma, k, v = n - 2) {
num <- integrate(function(delta) {
dt(tstat, df = v, ncp = sqrt(n)*delta)/gamma * dnorm((delta - mu)/gamma)
}, -Inf, Inf)$value
dt(tstat, df = v, ncp = sqrt(n)*x) / num
}
lo <- uniroot(function(x) bfx(x, .5, 10, 0, .3) - 1, interval = c(-1, 0))$root
hi <- uniroot(function(x) bfx(x, .5, 10, 0, .3) - 1, interval = c(0, 2))$root
plot(function(x) bfx(x, .5, 10, 0, .3), from = -4, to = 4)
abline(v = lo)
abline(v = hi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment