This package provides code for finding a beta distribution whose confidence interval is the one you desire
Although it is fast in terms of human usage (it takes a fifth of a second), it is not recommended for usage inside another project, like Squiggle, because 0.5s here and 0.5s there add up fairly fast. Rather, the code should be called, and the parameters included in the second program. Edit: now it is faster, though convergence is not guaranteed. Mixed feelings about including it in Squiggle.
Code for this repository is inspired by this package for R. In particular, that package uses R's powerful optim
function, and I bothered looking up what optim
uses as a default: the Nelder Mead method. From that R package, I am also using the default initial search point of a=50, b=50, though I add a grid search in case that fails.
For the Nelder Mead method, I am using this implementation (I tried other algorithms, like BFGS, and implemented a version of backtracking line search, but Nelder Mead proved to just be better). See the nelderMead
folder.
For various functions, I am using stdlib. I tried to extract the core code from them, but sadly all of its functions are fairly intertwined.
yarn add fit-beta
# npm install fit-beta
Set "type": "module",
in your package json, then:
import {find_beta_from_ci} from 'fit-beta'
let result1 = find_beta_from_ci({ci_lower: 0.3, ci_upper: 0.8})
console.log(result1)
I haven't figured this one out. In particular, including packages is annoying. The relevant parts of stdlib can be included, but they are just pretty heavy. Happy to get a pull request to bundle this for the web, though.
- R: See here
- Python: to do?
- If you are a friend: I'm happy to share an endpoint, i.e., a website url that you can call with the desired confidence intervals and get back the beta parameters.
- Add test coverage
- Add a frontend to this
- ...
Contributions are welcome.
Distributed under the MIT license, except for src/nelderMead
, which is distributed under the BSD-3-Clause license, which is satisfied by including the BSD-3-Clause license in the src/nelderMead
folder.