Bayesian Statistics (bayesian-statistics-ai999x)
Bayesian Statistics covers Bayes' theorem, conjugate priors and posteriors, credible intervals, Bayes factors, Monte Carlo estimation, uncertainty propagation, sensitivity analysis and decision analysis: 78 calculations in 12 topics, each with its formula, its steps and its units, and a plain reason instead of a number when an input is missing or out of range. One compiled engine, four ways to use it: the desktop app, the command line, the browser and Python. Everything runs on your own computer, offline.
Four ways to use it
| Desktop app (Windows, Linux) | Windows · Linux |
Command line bayesian-statistics (Windows, Linux) |
Windows · Linux |
| Browser (any device) | Try it on the model page |
| Python 3.10+ | pip install bayesian-statistics-ai999x: on Windows and Linux (x86-64) pip installs the same compiled engine; on other systems (macOS, ARM) it installs a pure-Python build that gives the same answers |
See it
From the Bayesian Statistics desktop app: every scene and chart is drawn from the computed answer.
Charts:
![]() Positive and negative predictive values of a test |
![]() Beta-binomial conjugate posterior |
![]() Highest-density interval of a beta posterior |
![]() Expected value of perfect information (EVPI) |
Ask in words: 15 examples
Each question below was asked on this release; the comment under it is the line it printed.
import bayesian_statistics_ai999x as bayesian_statistics
a = bayesian_statistics.ask(
"Bayesian A/B test: alpha_a = 1, beta_a = 1, alpha_b = 1, beta_b = "
"1. Probability that A beats B?"
)
print(a.outcome, a.values)
# SOLVED {'prob_a_greater': 0.5, 'prob_b_greater': 0.5}
a = bayesian_statistics.ask(
"Find the beta prior with mean = 0.3 and standard deviation = 0.1."
)
print(a.outcome, a.values)
# SOLVED {'alpha': 6.0, 'beta': 14.0, 'prior_sample_size': 20.0}
a = bayesian_statistics.ask(
"Law of total probability: priors = [0.5, 0.3, 0.2], conditionals "
"= [0.01, 0.02, 0.05]. Find P(B)."
)
print(a.outcome, a.values)
# SOLVED {'p_b': 0.021, 'joint': [0.005, 0.006, 0.01]}
a = bayesian_statistics.ask(
"KL divergence between beta distributions: alpha1 = 2, beta1 = 1, "
"alpha2 = 1, beta2 = 1."
)
print(a.outcome, a.values)
# SOLVED {'kl': 0.19314718056}
a = bayesian_statistics.ask("Convert the probability 0.2 to odds.")
print(a.outcome, a.values)
# SOLVED {'odds': 0.25, 'odds_against': 4.0, 'log_odds': -1.38629436112}
a = bayesian_statistics.ask(
"Equal-tailed 90% credible interval for a Beta(1, 1) posterior."
)
print(a.outcome, a.values)
# SOLVED {'lower': 0.05, 'upper': 0.95, 'median': 0.5}
a = bayesian_statistics.ask(
"KL divergence between normal distributions: mean1 = 0, sd1 = 1, "
"mean2 = 1, sd2 = 2."
)
print(a.outcome, a.values)
# SOLVED {'kl_1_to_2': 0.44314718056, 'kl_2_to_1': 1.30685281944}
a = bayesian_statistics.ask(
"Monte Carlo integration with values = [1, 3]: lower = 0, upper = "
"2."
)
print(a.outcome, a.values)
# SOLVED {'estimate': 4.0, 'standard_error': 2.0, 'n': 2}
a = bayesian_statistics.ask(
"The pre-test probability is 0.2 and the likelihood ratio is 6. "
"What is the post-test probability?"
)
print(a.outcome, a.values)
# SOLVED {'posterior': 0.6, 'prior_odds': 0.25, 'posterior_odds': 1.5}
a = bayesian_statistics.ask(
"Repeated testing: prevalence 0.01, sensitivity 0.9, specificity "
"0.95, positives = 2, negatives = 0. Posterior probability of the "
"disease?"
)
print(a.outcome, a.values)
# SOLVED {'posterior': 0.765957446809, 'posterior_odds': 3.27272727273}
a = bayesian_statistics.ask(
"Dirichlet-multinomial evidence for counts = [2, 1, 0] with alpha "
"= [1, 1, 1]."
)
print(a.outcome, a.values)
# SOLVED {'probability': 0.1, 'log_probability': -2.30258509299}
a = bayesian_statistics.ask("Convert odds of 3 to a probability.")
print(a.outcome, a.values)
# SOLVED {'probability': 0.75, 'complement': 0.25}
a = bayesian_statistics.ask(
"Mean and variance of the polynomial with coefficients = [1, 2, 3] "
"of a normal X with mean = 0, sd = 1."
)
print(a.outcome, a.values)
# SOLVED {'mean': 4.0, 'variance': 22.0, 'sd': 4.69041575982}
a = bayesian_statistics.ask(
"Treatment threshold with loss_fp = 1 and loss_fn = 9; the "
"probability of disease is 0.05. Treat?"
)
print(a.outcome, a.values)
# SOLVED {'threshold': 0.1, 'decision': 'do not treat'}
a = bayesian_statistics.ask(
"Stratified sampling: weights = [0.6, 0.4], means = [10, 20], sds "
"= [2, 5], sizes = [30, 20]."
)
print(a.outcome, a.values)
# SOLVED {'estimate': 14.0, 'standard_error': 0.49799598392}
Command line: 15 examples
Each command below was run with bayesian-statistics of this release; the lines under it are the answer it printed (the full answer goes on with the method, every input in SI units and the conditions it assumes).
$ bayesian-statistics solve bayes_factor_normal_mean sample_mean=0 n=1 sigma=1 mu0=0 prior_sd=1
bf10 = 0.7071067812
bf01 = 1.414213562
log10_bf10 = -0.1505149978
posterior_h1 = 0.4142135624
$ bayesian-statistics solve bayes_theorem p_a=0.3 p_b_given_a=0.8 p_b_given_not_a=0.1
p_a_given_b = 0.7741935484
p_b = 0.31
p_not_a_given_b = 0.2258064516
$ bayesian-statistics solve ab_test_probability_beta alpha_a=1 beta_a=1 alpha_b=1 beta_b=1
prob_a_greater = 0.5
prob_b_greater = 0.5
$ bayesian-statistics solve gamma_poisson_credible_interval "counts=[0]" shape=1 rate=1 level=0.9
post_shape = 1
post_rate = 2
lower = 0.02564664719
upper = 1.497866137
$ bayesian-statistics solve bayes_action_minimum_expected_loss "losses=[[0, 10], [5, 0]]" "probabilities=[0.3, 0.7]"
expected_losses = [7.0,1.5]
bayes_action = 2
bayes_risk = 1.5
$ bayesian-statistics solve gauss_hermite_rule n=3
nodes = [-1.73205080757,0.0,1.73205080757]
weights = [0.166666666667,0.666666666667,0.166666666667]
$ bayesian-statistics solve control_variate_estimate "y=[1, 2, 3]" "c=[1, 2, 3]" control_mean=2.5
estimate = 2.5
coefficient = 1
plain_estimate = 2
variance_reduction = 0
$ bayesian-statistics solve likelihood_ratios sensitivity=0.9 specificity=0.8
lr_positive = 4.5
lr_negative = 0.125
diagnostic_odds_ratio = 36
$ bayesian-statistics solve laplace_approximation_beta alpha=3 beta=3 level=0.95
mode = 0.5
laplace_sd = 0.25
lower = 0.01000900386
upper = 0.9899909961
$ bayesian-statistics solve beta_prior_from_mean_sd mean=0.3 sd=0.1
alpha = 6
beta = 14
prior_sample_size = 20
$ bayesian-statistics solve morris_elementary_effects "outputs=[[10, 12], [11, 10]]" delta=1
mu = [0.5]
mu_star = [1.5]
sigma = [2.12132034356]
$ bayesian-statistics solve covariance_propagation_linear "matrix=[[1, 1], [1, -1]]" "covariance=[[0.04, 0.01], [0.01, 0.09]]"
output_covariance = [[0.15,-0.05],[-0.05,0.11]]
uncertainties = [0.387298334621,0.331662479036]
$ bayesian-statistics solve bayes_factor_point_null_binomial p0=0.5 successes=2 trials=2 alpha=1 beta=1
bf10 = 1.333333333
bf01 = 0.75
log10_bf10 = 0.1249387366
posterior_h1 = 0.5714285714
$ bayesian-statistics solve total_probability "priors=[0.5, 0.3, 0.2]" "conditionals=[0.01, 0.02, 0.05]"
p_b = 0.021
joint = [0.005,0.006,0.01]
$ bayesian-statistics solve beta_binomial_posterior alpha=2 beta=2 successes=7 trials=10
post_alpha = 9
post_beta = 5
posterior_mean = 0.6428571429
posterior_variance = 0.01530612245
posterior_sd = 0.1237179148
Guides
- Desktop app guide: the window, every calculation, scenes and charts: PDF · HTML · Markdown
- Python guide: every calculation with a Python example: PDF · HTML · Markdown
- Command-line guide: every calculation with the command and what it printed: PDF · HTML · Markdown
Every calculation, with its formula, a worked example and its figures: Bayesian Statistics on ai999x.com. Install guides for the app and the command line: https://www.ai999x.com/desktop-cli/.
Version 1.6.6 · License: Apache-2.0 · Author: Ibnul Jaif Farabi · Organization: AI999X · Contact: support@ai999x.com · Support the project
The Future Is Self-Improving.
- Downloads last month
- 286
Collections including AI999X/bayesian-statistics-ai999x
Evaluation results
- identical on every platform on Golden answers (378 documented questions, Windows + Linux Python 3.10-3.14)self-reported1.000













