项目作者: fako1024

项目描述 :
Numeric estimation of statistical uncertainties for Bernoulli experiments (k/n successful trials)
高级语言: Go
项目地址: git://github.com/fako1024/effuncert.git
创建时间: 2019-05-12T12:00:17Z
项目社区:https://github.com/fako1024/effuncert

开源协议:Apache License 2.0

下载


Numeric estimation of statistical uncertainties for Bernoulli experiments

Github Release
GoDoc
Go Report Card
Build/Test Status

This package performs a numeric estimation of quantiles and uncertainties for a Bernoulli experiment or and estimator for an efficiency (k/n successful coin flip trials) in pure Go.

Different Frequentist (e.g. Likelihood methods) and non-Frequentist approachs can be used to determine the uncertainties for the Trigger efficiency. In this case, a Bayesian approach was chosen to account for the asymmetry introduced by the Binomial distributed variables and to solve the problematic of boundary effects as well.
The underlying Binomial probability distribution function and quantiles are modeled using an incomplete, regularized Beta function (the corresponding integral / cumulative PDF) and applying a numeric root finding method to determine arbitrary quantiles.

Features

  • Estimation of classical mode and variance of Bernoulli experiment / efficiency calculation
  • Extraction / estimation of quantiles for the underlying probability distribution function
  • Extraction asymmetric uncertainty intervals equivalents for any confidence level / interval

Installation

  1. go get -u github.com/fako1024/effuncert

API summary

The API of the package is fairly straight-forward. The following functions are exposed:

  1. // Estimator denotes a numeric estimator instance for a Bernoulli experiment and
  2. // its uncertainty based on a binomial probability distribution
  3. type Estimator struct {
  4. NSuccess, NTrial float64 // Number of successes & trials
  5. Mode float64 // Mode / expectation value of the estimator
  6. Integral float64 // Integral of the PDF
  7. Variance float64 // Variance / classical uncertainty of the estimator
  8. }
  9. // New instantiates a new estimator based on a set of trails / successes
  10. // and functional options (if any)
  11. func New(nSuccess, nTrial uint64, options ...func(*Estimator)) *Estimator
  12. // String returns a human-readable string representing the estimator result
  13. func (e *Estimator) String() string
  14. // Quantile returns a quantile based on a probability
  15. func (e *Estimator) Quantile(confidence float64) float64
  16. // Interval returns the absolute lower and upper quantiles for the uncertainty estimation
  17. func (e *Estimator) Interval() (lowQuantile float64, highQuantile float64)
  18. // IntervalRelative returns the relative lower and upper quantiles for the uncertainty estimation
  19. func (e *Estimator) IntervalRelative() (lowQuantile float64, highQuantile float64)

Example

  1. // 3 successful out of 8 Bernoulli experiments
  2. nSuccess, nTrial := 3, 8
  3. // Instantiate an estimator
  4. e := effuncert.New(nSuccess, nTrial,
  5. effuncert.WithConfidence(effuncert.OneSigma)
  6. )
  7. // Print the result in a well-formatted way, making use of the String() method
  8. // Will print: (0.37500 -0.12882 +0.17969)
  9. fmt.Println(e)
  10. // Print the median
  11. // Will print: 0.39308483281062906
  12. fmt.Println(e.Quantile(0.5))

An additional example binary code can be found in the examples/effuncert folder.