gleam_stats/distributions/geometric

Functions related to discrete geometric random variables.


Functions

pub fn geometric_cdf(x: Int, p: Float) -> Result(Float, String)

Evaluate, at a certain point, the cumulative distribution function (cdf) of a of a discrete geometric distribution with with parameter ‘p’ in the interval (0, 1] (the success probability).

Example:
 import gleam_stats/distributions/geometric
 import gleeunit/should

 pub fn example() {
   let p: Float = 0.5
   // For illustrational purposes, evaluate the cdf at the 
   // point -100.0
   geometric.geometric_cdf(-100.0, r, p) |> should.equal(Ok(0.0))
 }
pub fn geometric_mean(p: Float) -> Result(Float, String)

Analytically compute the mean of a discrete geometric distribution with parameter ‘p’ in the interval (0, 1] (the success probability).

pub fn geometric_pmf(x: Int, p: Float) -> Result(Float, String)

Evaluate the probability mass function (pmf) of a discrete geometric distribution with with parameter ‘p’ in the interval (0, 1] (the success probability).

Example:
 import gleam_stats/distributions/geometric
 import gleeunit/should

 pub fn example() {
   let p: Float = 0.5
   // For illustrational purposes, evaluate the pmf at the 
   // point -100.0
   geometric.geometric_pmf(-100.0, r, p) |> should.equal(Ok(0.0))
 }
pub fn geometric_random(stream: Iterator(Int), p: Float, m: Int) -> Result(
  #(List(Int), Iterator(Int)),
  String,
)

Generate ‘m’ random numbers from a discrete geometric distribution with parameter ‘p’ in the interval (0, 1] (the success probability).

The random numbers are generated using the inverse transform method.

Example:
 import gleam/iterator.{Iterator}
 import gleam_stats/generator
 import gleam_stats/distributions/geometric

 pub fn example() {
   let seed: Int = 5
   let seq: Int = 1
   let p: Float = 0.5
   assert Ok(out) =
     generators.seed_pcg32(seed)
     |> geometric.geometric_random(r, p, 5_000)
   let rands: List(Float) = pair.first(out)
   let stream: Iterator(Int) = pair.second(out)
 }
pub fn geometric_variance(p: Float) -> Result(Float, String)

Analytically compute the variance of a discrete geometric distribution with parameter ‘p’ in the interval (0, 1] (the success probability).