Skip to main content

bindata

CircleCI version PyPI Latest Release License Downloads Buy Me A Coffee

A python replication of the homonymous R library bindata, based on the paper "Generation of correlated artificial binary data.", by Friedrich Leisch, Andreas Weingessel, and Kurt Hornik.

The library fully replicates the existing R-package with the following functions:

  • bincorr2commonprob
  • check_commonprob (check.commonprob in R)
  • commonprob2sigma
  • condprob
  • ra2ba
  • rmvbin
  • simul_commonprob (simul.commonprob in R)

Precomputed (via Monte Carlo simulations) SimulVals are also available.

Installation

bindata can be installed with pip as:

pip install bindata

How to

Generate uncorrelated variates

import bindata as bnd

margprob = [0.3, 0.9]

X = bnd.rmvbin(N=100_000, margprob=margprob)

Now let's verify the sample marginals and correlations:

import numpy as np

print(X.mean(0))
print(np.corrcoef(X, rowvar=False))
[0.30102 0.9009 ]
[[ 1.         -0.00101357]
 [-0.00101357  1.        ]]

Generate correlated variates

From a correlation matrix

corr = np.array([[1., -0.25, -0.0625],
                 [-0.25,   1.,  0.25],
                 [-0.0625, 0.25, 1.]])
commonprob = bnd.bincorr2commonprob(margprob=[0.2, 0.5, 0.8], 
                                        bincorr=corr)

X = bnd.rmvbin(margprob=np.diag(commonprob), 
                   commonprob=commonprob, N=100_000)
print(X.mean(0))
print(np.corrcoef(X, rowvar=False))
[0.1996  0.50148 0.80076]
[[ 1.         -0.25552    -0.05713501]
 [-0.25552     1.          0.24412401]
 [-0.05713501  0.24412401  1.        ]]

From a joint probability matrix

commonprob = [[1/2, 1/5, 1/6],
              [1/5, 1/2, 1/6],
              [1/6, 1/6, 1/2]]
X = bnd.rmvbin(N=100_000, commonprob=commonprob)

print(X.mean(0))
print(np.corrcoef(X, rowvar=False))
[0.50076 0.50289 0.49718]
[[ 1.         -0.20195239 -0.33343712]
 [-0.20195239  1.         -0.34203855]
 [-0.33343712 -0.34203855  1.        ]]

For a more comprehensive documentation please consult the documentation.

Acknowledgements

Author

Luca Mingarelli, 2022

You find this work useful? Buy Me A Coffee

Metadata

Release files for bindata 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bindata 1.0.0
File Size Uploaded
bindata-1.0.0.tar.gz 127.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bindata 1.0.0
File Interpreter ABI Platform
bindata-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 254.0 kB

Release files / bindata-1.0.0.tar.gz

Download URL bindata-1.0.0.tar.gz
Size 127.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dd7403fafd2fbee3df6b3424f99556c2b84e2f0c40306bc6bbc8baaf2ec17739
BLAKE2b-256 checksum
How to use checksums
2eb96e58cb7428f2a84b6838c34bd68d158693e5affc555766ded142e7fc78d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / bindata-1.0.0-py3-none-any.whl

Download URL bindata-1.0.0-py3-none-any.whl
Size 126.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83beea630a4fc343deae4d3f940362c1a468bbddd1ebd6c62a992d89d82b8ddd
BLAKE2b-256 checksum
How to use checksums
3660a24c5510d4e1753a36e4b3f67935b056de500f7fab929b6bf77931d06024
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.2

1 release file

0.10.1

1 release file

0.10.0

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page