class BinomialDistribution extends AnyRef
A high-precision implementation of the math for binomial probabilities. This implementation is several times slower (though not orders of magnitude slower) than the implementation in Apache Commons Math, but retains precision throughout the computation where the Commons implementation underflows.
One implementation choice to be aware of when using this implementation is that each instance of the class will calculate and cache factorials up to factorial(n) where n is the highest value of n supplied to any call to probability() or cumulativeProbability(). Thus to ensure reasonable performance it is recommended to create one instance of this class and reuse it for as many calculations as is practical.
- Alphabetic
- By Inheritance
- BinomialDistribution
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
BinomialDistribution(mc: MathContext = MathContext.UNLIMITED)
- mc
the MathContext to use for controlling precision and rounding. Changing from the default MathContext.UNLIMITED can lead to a loss of precision.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
+(other: String): String
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to any2stringadd[BinomialDistribution] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
-
def
->[B](y: B): (BinomialDistribution, B)
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to ArrowAssoc[BinomialDistribution] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
coefficient(n: Int, k: Int): BigInt
Computes the binomial coefficient, i.e.
Computes the binomial coefficient, i.e. the number of combinations of k items given a total of n items, often phrased "n choose k".
- n
The number of items being picked from
- k
The number of items being picked (must be 0 <= k <= n)
- returns
The number of combinations of k items from n
-
def
cumulativeProbability(k: Int, n: Int, p: BigDecimal, lower: Boolean = true): BigDecimal
Calculates the cumulative probability of
[0, k]
successes fromn
trials withp
probability of success in any individual trial.Calculates the cumulative probability of
[0, k]
successes fromn
trials withp
probability of success in any individual trial. Akin topbinom
in R.- k
the number of successes to compute the cumulative probability up to, inclusive
- n
the number of trials
- p
the probability of success in any single trial
- lower
if true return the cumulative probability of
(0,k)
trials inclusive otherwise return the cumulative probability of(k+1, n)
trials inclusive.
-
def
ensuring(cond: (BinomialDistribution) ⇒ Boolean, msg: ⇒ Any): BinomialDistribution
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to Ensuring[BinomialDistribution] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: (BinomialDistribution) ⇒ Boolean): BinomialDistribution
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to Ensuring[BinomialDistribution] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean, msg: ⇒ Any): BinomialDistribution
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to Ensuring[BinomialDistribution] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean): BinomialDistribution
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to Ensuring[BinomialDistribution] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to StringFormat[BinomialDistribution] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val mc: MathContext
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
probability(k: Int, n: Int, p: BigDecimal): BigDecimal
Calculates the probability of exactly
k
successes inn
trials givenp
probability.Calculates the probability of exactly
k
successes inn
trials givenp
probability. Akin todbinom
in R.- k
The number of successful trials
- n
The number of trials
- p
The probability of the success in any one trial
- returns
The probability of exactly k successes in n trials of p probability
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
→[B](y: B): (BinomialDistribution, B)
- Implicit
- This member is added by an implicit conversion from BinomialDistribution to ArrowAssoc[BinomialDistribution] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc