NegativeBinomial

vecxt_re.NegativeBinomial
See theNegativeBinomial companion object
case class NegativeBinomial(a: Double, b: Double) extends DiscreteDistr[Int], HasMean[Double], HasCdf[Int], HasVariance[Double]

Negative Binomial Distribution with alternative parameterization.

Uses the parameterization:

  • r = a (number of successes, can be any positive real)
  • p = 1 / (1 + b) (probability of success)

Which gives:

  • mean = a * b
  • variance = a * b * (1 + b)

Under this parameterisation, as b -> 0, the distribution will converge to Poisson(ab). The parameter b is therefore a measure of overdispersion.

Implementation uses the gamma-Poisson mixture representation, which allows non-integer a: If λ ~ Gamma(a, b) and X | λ ~ Poisson(λ), then X ~ NegativeBinomial(a, b)

Value parameters

a

shape parameter (must be positive, can be non-integer)

b

scale/dispersion parameter (must be positive)

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait HasVariance[Double]
trait HasCdf[Int]
trait HasMean[Double]
trait DiscreteDistr[Int]
trait Rand[Int]
trait Density[Int]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def cdf(x: Int): Double

Attributes

Definition Classes
def draw: Int

Draw using gamma-Poisson mixture: λ ~ Gamma(a, b), X | λ ~ Poisson(λ)

Draw using gamma-Poisson mixture: λ ~ Gamma(a, b), X | λ ~ Poisson(λ)

Attributes

override def logProbabilityOf(x: Int): Double

Log PMF: log P(X = k) = logΓ(a + k) − logΓ(a) − logΓ(k + 1) + a·log(p) + k·log(1−p).

Log PMF: log P(X = k) = logΓ(a + k) − logΓ(a) − logΓ(k + 1) + a·log(p) + k·log(1−p).

For k ≥ 1 the gamma terms equal −log k − log B(a, k). Differencing log Γ directly loses ~a·log(a)·ε absolutely, which is garbage for large a (near-Poisson fits, NegativeBinomial.poisson); log B is evaluated without that cancellation.

Attributes

Definition Classes
def mean: Double
def plot(using LowPriorityPlotTarget): VizReturn
def plot(mods: Seq[SpecMod])(using LowPriorityPlotTarget): VizReturn

As plot, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

As plot, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

Attributes

def plotCdf(using LowPriorityPlotTarget): VizReturn
def plotCdf(mods: Seq[SpecMod])(using LowPriorityPlotTarget): VizReturn

As plotCdf, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

As plotCdf, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

Attributes

override def probability(x: Int, y: Int): Double

Attributes

Definition Classes
def probabilityOf(x: Int): Double

PMF: P(X = k) = Γ(a + k) / (Γ(a) * k!) * p^a * (1-p)^k

PMF: P(X = k) = Γ(a + k) / (Γ(a) * k!) * p^a * (1-p)^k

Attributes

def variance: Double

Inherited methods

def apply(x: Int): Double

Returns the unnormalized value of the measure

Returns the unnormalized value of the measure

Attributes

Inherited from:
DiscreteDistr
def drawOpt: Option[Int]

Overridden by filter/map/flatmap for monadic invocations. Basically, rejection samplers will return None here

Overridden by filter/map/flatmap for monadic invocations. Basically, rejection samplers will return None here

Attributes

Inherited from:
Rand
def flatMap[E](f: Int => Rand[E]): Rand[E]

Attributes

Inherited from:
Rand
inline def get: Int

Attributes

Inherited from:
Rand
override def logApply(x: Int): Double

Returns the log unnormalized value of the measure

Returns the log unnormalized value of the measure

Attributes

Definition Classes
Inherited from:
DiscreteDistr
def map[E](f: Int => E): Rand[E]

Converts a random sampler of one type to a random sampler of another type. Examples: uniform.map(_2) gives a Rand[Double] in the range [0,2] Equivalently, for(x <- uniform) yield 2x

Converts a random sampler of one type to a random sampler of another type. Examples: uniform.map(_2) gives a Rand[Double] in the range [0,2] Equivalently, for(x <- uniform) yield 2x

Value parameters

f

the transform to apply to the sampled value.

Attributes

Inherited from:
Rand
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
inline def sample(n: Int): IndexedSeq[Int]

Gets n samples from the distribution.

Gets n samples from the distribution.

Attributes

Inherited from:
Rand
inline def sample: Int

Gets one sample from the distribution. Equivalent to get

Gets one sample from the distribution. Equivalent to get

Attributes

Inherited from:
Rand
def sampleTo[C](n: Int)(using factory: Factory[Int, C]): C

Gets n samples from the distribution into a specified collection type.

Gets n samples from the distribution into a specified collection type.

Attributes

Inherited from:
Rand
inline def samples: Iterator[Int]

An infinitely long iterator that samples repeatedly from the Rand

An infinitely long iterator that samples repeatedly from the Rand

Attributes

Returns

an iterator that repeatedly samples

Inherited from:
Rand
def unnormalizedLogProbabilityOf(x: Int): Double

Attributes

Inherited from:
DiscreteDistr
def unnormalizedProbabilityOf(x: Int): Double

Returns the probability of that draw up to a constant

Returns the probability of that draw up to a constant

Attributes

Inherited from:
DiscreteDistr
def withFilter(p: Int => Boolean): Rand[Int]

Attributes

Inherited from:
Rand