Pynomial - a lightweight python library for implementing the many confidence intervals for the risk parameter of a binomial model

Overview

Pynomial

Pynomial (pronounced like "binomial") is a lightweight python library for implementing the many confidence intervals for the risk parameter of a binomial model. Pynomial is more or less a python port of the R library {binom} by Sundar Dorai-Raj. As a point of philosophy and until otherwise stated, if {binom} does a thing then so should pynomial (e.g. error throwing or handling cases when the number of successes is the same as the number of trials).

Tests

Features

The following confidence intervals are implemented:

  • The Agresti Coull Interval

  • The asymptotic interval based on the central limit theorem (this is the interval you probably see in most statistics textbooks)

  • An equal tailed posterior credible interval using a conjugate Beta prior

  • The complimentary log-log interval

  • The Wilson score interval

  • The exact interval based on the incomplete beta function.

  • The logit based confidence interval with large sample theory variance.

Installation

You can install pynomial from github using

 pip install git+https://github.com/Dpananos/pynomial

Getting Started

Usage

Using pynomial is very straight forward. Each interval function has three common arguments: x -- the number of success, n -- the number of trials, and conf -- the desired confidence level. Both x and n can be either integers or arrays of integers and conf must be a float between 0 and 1 (the default is 0.95 for a 95% confidence interval). After calling an interval function with the propper arguments, a dataframe will be returned yeilding an estimate of the risk as well as the lower and upper confidence limits. As an example, suppose I flipped a coin 20 times and observed 12 heads. Using the wilson function to compute a Wilson score confidence interval, the output would be

from pynomial import wilson
x = 12
n = 20
wilson(x=x, n=n)
        estimate     lower     upper
Wilson       0.6  0.386582  0.781193

Each interval function is vectorized, so we can compute confidence intervals for many experiments at once.

from pynomial import wilson
x = np.array([11, 12, 13])
n = 20
wilson(x=x, n=n)
        estimate     lower     upper
Wilson      0.55  0.342085  0.741802
Wilson      0.60  0.386582  0.781193
Wilson      0.65  0.432854  0.818808

The output of each interval function is a pandas dataframe, making plotting the confidence intervals straightforward.

Information on Binomial Random Variables

Many textbooks have their own treatment of binomial random variables and confidence intervals. Recommended resources to familliarize one's self with the methods in this library are:

  • Lachin, John M. Biostatistical methods: the assessment of relative risks. Vol. 509. John Wiley & Sons, 2009.

  • Brown, Lawrence D., T. Tony Cai, and Anirban DasGupta. Interval estimation for a binomial proportion. Statistical science 16.2 (2001): 101-133.

  • Brown, Lawrence D., T. Tony Cai, and Anirban DasGupta. Confidence intervals for a binomial proportion and asymptotic expansions. The Annals of Statistics 30.1 (2002): 160-201.

You might also like...
the code for paper "Energy-Based Open-World Uncertainty Modeling for Confidence Calibration"

EOW-Softmax This code is for the paper "Energy-Based Open-World Uncertainty Modeling for Confidence Calibration". Accepted by ICCV21. Usage Commnd exa

Training Confidence-Calibrated Classifier for Detecting Out-of-Distribution Samples / ICLR 2018

Training Confidence-Calibrated Classifier for Detecting Out-of-Distribution Samples This project is for the paper "Training Confidence-Calibrated Clas

Learning Confidence for Out-of-Distribution Detection in Neural Networks
Learning Confidence for Out-of-Distribution Detection in Neural Networks

Learning Confidence Estimates for Neural Networks This repository contains the code for the paper Learning Confidence for Out-of-Distribution Detectio

Source code of NeurIPS 2021 Paper ''Be Confident! Towards Trustworthy Graph Neural Networks via Confidence Calibration''

CaGCN This repo is for source code of NeurIPS 2021 paper "Be Confident! Towards Trustworthy Graph Neural Networks via Confidence Calibration". Paper L

Code for "The Box Size Confidence Bias Harms Your Object Detector"

The Box Size Confidence Bias Harms Your Object Detector - Code Disclaimer: This repository is for research purposes only. It is designed to maintain r

A mini library for Policy Gradients with Parameter-based Exploration, with reference implementation of the ClipUp optimizer  from NNAISENSE.
A mini library for Policy Gradients with Parameter-based Exploration, with reference implementation of the ClipUp optimizer from NNAISENSE.

PGPElib A mini library for Policy Gradients with Parameter-based Exploration [1] and friends. This library serves as a clean re-implementation of the

A python library for implementing a recommender system

python-recsys A python library for implementing a recommender system. Installation Dependencies python-recsys is build on top of Divisi2, with csc-pys

Library for implementing reservoir computing models (echo state networks) for multivariate time series classification and clustering.
Library for implementing reservoir computing models (echo state networks) for multivariate time series classification and clustering.

Framework overview This library allows to quickly implement different architectures based on Reservoir Computing (the family of approaches popularized

This is an open source library implementing hyperbox-based machine learning algorithms
This is an open source library implementing hyperbox-based machine learning algorithms

hyperbox-brain is a Python open source toolbox implementing hyperbox-based machine learning algorithms built on top of scikit-learn and is distributed

Owner
Demetri Pananos
Statistician/Mathematician/Scientist/Former PyMC3 GSoC Student
Demetri Pananos
Based on Yolo's low-power, ultra-lightweight universal target detection algorithm, the parameter is only 250k, and the speed of the smart phone mobile terminal can reach ~300fps+

Based on Yolo's low-power, ultra-lightweight universal target detection algorithm, the parameter is only 250k, and the speed of the smart phone mobile terminal can reach ~300fps+

null 567 Dec 26, 2022
Python 3 module to print out long strings of text with intervals of time inbetween

Python-Fastprint Python 3 module to print out long strings of text with intervals of time inbetween Install: pip install fastprint Sync Usage: from fa

Kainoa Kanter 2 Jun 27, 2022
A scikit-learn-compatible module for estimating prediction intervals.

|Anaconda|_ MAPIE - Model Agnostic Prediction Interval Estimator MAPIE allows you to easily estimate prediction intervals using your favourite sklearn

SimAI 584 Dec 27, 2022
Contrastive Learning for Many-to-many Multilingual Neural Machine Translation(mCOLT/mRASP2), ACL2021

Contrastive Learning for Many-to-many Multilingual Neural Machine Translation(mCOLT/mRASP2), ACL2021 The code for training mCOLT/mRASP2, a multilingua

null 104 Jan 1, 2023
M2MRF: Many-to-Many Reassembly of Features for Tiny Lesion Segmentation in Fundus Images

M2MRF: Many-to-Many Reassembly of Features for Tiny Lesion Segmentation in Fundus Images This repo is the official implementation of paper "M2MRF: Man

null 12 Dec 14, 2022
Lightweight mmm - Lightweight (Bayesian) Media Mix Model

Lightweight (Bayesian) Media Mix Model This is not an official Google product. L

Google 342 Jan 3, 2023
Visualize Camera's Pose Using Extrinsic Parameter by Plotting Pyramid Model on 3D Space

extrinsic2pyramid Visualize Camera's Pose Using Extrinsic Parameter by Plotting Pyramid Model on 3D Space Intro A very simple and straightforward modu

JEONG HYEONJIN 106 Dec 28, 2022
Python Library for learning (Structure and Parameter) and inference (Statistical and Causal) in Bayesian Networks.

pgmpy pgmpy is a python library for working with Probabilistic Graphical Models. Documentation and list of algorithms supported is at our official sit

pgmpy 2.2k Jan 3, 2023
Outlier Exposure with Confidence Control for Out-of-Distribution Detection

OOD-detection-using-OECC This repository contains the essential code for the paper Outlier Exposure with Confidence Control for Out-of-Distribution De

Nazim Shaikh 64 Nov 2, 2022
Spherical Confidence Learning for Face Recognition, accepted to CVPR2021.

Sphere Confidence Face (SCF) This repository contains the PyTorch implementation of Sphere Confidence Face (SCF) proposed in the CVPR2021 paper: Shen

Maths 70 Dec 9, 2022