#497 (no tests or examples)

This commit is contained in:
Quinn Dougherty 2022-06-27 14:31:35 -04:00
parent 8d7e6297cc
commit 14189fd848
2 changed files with 19 additions and 2 deletions

View File

@ -124,6 +124,19 @@ module Beta = {
let sample = (t: t) => Jstat.Beta.sample(t.alpha, t.beta) let sample = (t: t) => Jstat.Beta.sample(t.alpha, t.beta)
let mean = (t: t) => Ok(Jstat.Beta.mean(t.alpha, t.beta)) let mean = (t: t) => Ok(Jstat.Beta.mean(t.alpha, t.beta))
let toString = ({alpha, beta}: t) => j`Beta($alpha,$beta)` let toString = ({alpha, beta}: t) => j`Beta($alpha,$beta)`
let fromMeanAndSampleSize = (mean, sampleSize) => {
// https://en.wikipedia.org/wiki/Beta_distribution#Mean_and_sample_size
let alpha = mean *. sampleSize
let beta = (1.0 -. mean) *. sampleSize
alpha->make(beta)
}
let fromMeanAndStdev = (mean, stdev) => {
let var = stdev *. stdev
let sampleSize = mean *. (1.0 -. mean) /. var
mean->fromMeanAndSampleSize(sampleSize)
}
} }
module Lognormal = { module Lognormal = {

View File

@ -117,8 +117,12 @@ lognormal({mean: 5, stdev: 2})`,
), ),
Function.make( Function.make(
~name="Beta", ~name="Beta",
~examples=`beta(20, 25)`, ~examples=`beta(20, 25)
~definitions=[TwoArgDist.make("beta", twoArgs(SymbolicDist.Beta.make))], beta({mean: 0.39, stdev: 0.1})`,
~definitions=[
TwoArgDist.make("beta", twoArgs(SymbolicDist.Beta.make)),
TwoArgDist.makeRecordMeanStdev("beta", twoArgs(SymbolicDist.Beta.fromMeanAndStdev)),
],
(), (),
), ),
Function.make( Function.make(