API reference¶
The analyses¶
Eleven functions, each returning a Result. The frequentist
counterpart each one is paired with is named in its own documentation.
|
Estimate one unknown rate from counts. |
|
Compare a rate between two groups, or across several. |
|
Estimate one rate of events per unit of exposure. |
|
Compare the rate of events between two groups. |
|
Test whether the rows and columns of a table are related. |
|
Compare how one categorical variable splits against expected shares. |
|
Estimate one unknown average from a sample. |
|
Compare the average of two groups. |
|
Estimate the correlation between two variables. |
|
Estimate how much |
|
Compare the averages of three or more groups. |
The result object¶
Every analysis returns one of these, with the same methods throughout, so the interface learned for one carries over to all of them.
|
What every |
|
The outcome of comparing a credible interval against a ROPE. |
|
A Bayes factor, with the caveat it should never be quoted without. |
|
A forecast of the next observation, with the parameter uncertainty in it. |
Priors¶
Named presets, so nobody has to type a shape parameter to get started, and nobody can hide which assumption they used.
|
A Beta prior over a proportion, carrying its own explanation. |
|
A symmetric Dirichlet prior over the cells of a contingency table. |
|
A Cauchy prior on standardised effect size, for means and correlations. |
|
A stretched-beta prior on a correlation coefficient. |
|
A Gamma prior on a rate of events per unit of exposure. |
|
Turn whatever the user passed as |
|
Turn whatever the user passed as |
|
Turn whatever the user passed as |
|
Turn whatever the user passed as |
|
Turn whatever the user passed as |
|
Build a prior from an earlier study's counts. |
|
Build a rate prior from an earlier period's count. |
|
Explain in one line what a prior assumes. |
List the preset prior names. |
Frequentist twins¶
The conventional tests, computed and printed alongside every Bayesian result. Usable on their own when you only want the classical answer.
|
A conventional test result, with its interpretation attached. |
|
Exact binomial test and Wilson score interval for one proportion. |
|
Two-proportion chi-square test, with an interval on the chosen estimand. |
|
Chi-square test that three or more groups share one rate. |
|
Exact Poisson test and exact (Garwood) interval for one rate. |
|
Exact conditional test comparing two Poisson rates. |
|
Pearson chi-square test of independence for an r x c table. |
|
Pearson chi-square goodness-of-fit test for one categorical variable. |
|
One-sample t-test and its confidence interval. |
|
Two-sample t-test and confidence interval on the difference. |
|
Paired t-test: a one-sample t-test on the within-pair differences. |
|
Pearson correlation with its p-value and Fisher-z interval. |
|
t-test and confidence interval for a least-squares slope. |
|
One-way ANOVA F test across three or more groups. |
Teaching tools¶
Pedagogy-only helpers that show a mechanism the analysis functions deliberately hide. Nothing here belongs in a research package; all of it belongs in a first course.
|
Lay out a detection problem as whole counts instead of probabilities. |
|
Multiply prior by likelihood over a grid, then divide by the total. |
|
Likelihood of binomial data at each candidate rate on a grid. |
|
Recompute the posterior after each chunk of incoming data. |
|
Find the sample size that makes an interval narrow enough to act on. |
|
Find the sample size that pins down an average, or a difference. |
|
A 2x2 grid of whole counts, and what it implies. |
|
Prior, likelihood, and posterior over a grid, with the arithmetic shown. |
|
The posterior after each successive chunk of data. |
|
How much data a target precision requires. |
Datasets¶
List the datasets shipped with the package. |
|
|
Explain what a dataset holds and which analyses it suits. |
|
Load a shipped dataset by name. |
Load traffic collisions for Los Angeles and San Diego counties. |
|
Load ACS estimates for Los Angeles County census tracts. |
|
Load ACS estimates for Los Angeles County block groups. |
|
Load Baltimore residential parcels with assessed values. |
Configuration¶
|
Return the current default seed. |
|
Set the default seed for every subsequent analysis. |
Return the current default number of posterior draws. |
|
|
Set the default number of posterior draws. |
Core mathematics¶
Layer 0: pure functions, no objects, no printing, nothing that knows it is being used to teach. Documented because the derivations belong somewhere readable, and because a methods audience will want to check them.
Proportions¶
|
Exact Beta posterior for an unknown proportion. |
|
Draw independent samples from the exact Beta posterior. |
|
Log marginal likelihood of binomial data under a Beta prior. |
|
Log Bayes factor comparing an unknown rate against a fixed value. |
|
Mean of a |
|
Check that a successes/trials pair describes a possible experiment. |
Rates¶
|
Exact Gamma posterior for one rate. |
|
Exact posterior for the ratio of two rates, group 2 over group 1. |
|
Posterior predictive distribution of the count over a new exposure. |
|
Log marginal likelihood of a count under a proper Gamma prior. |
|
Log Bayes factor for "the rate is unknown" against "it equals rate0". |
|
Log Bayes factor for "the two rates differ" against "they are equal". |
|
Check that an events/exposure pair describes something observable. |
Contingency tables and categories¶
|
Log Bayes factor for association against independence. |
|
Draw whole tables of cell probabilities from the Dirichlet posterior. |
|
Log Bayes factor for "the shares are unknown" against fixed shares. |
|
Cramer's V for one or many tables of probabilities. |
|
Cohen's w for one or many vectors of category shares. |
|
Log odds ratio of a 2x2 table of probabilities, or a stack of them. |
|
Log of the Dirichlet normalising function. |
|
Check that an array is a usable table of counts. |
Means¶
|
Exact Student-t posterior for one unknown mean. |
|
Exact Student-t posterior for a difference of means, equal variances. |
|
Draw the difference of two means without assuming equal variances. |
|
Log JZS Bayes factor for a t statistic. |
|
Reduce a sample to the three numbers every later step needs. |
|
Check that a sample is usable, dropping missing values. |
Correlation¶
|
Log density of an observed correlation given the true one. |
|
Log density of the stretched-beta prior on a correlation. |
|
Evaluate and normalise the posterior over the true correlation. |
|
Log Bayes factor for a real correlation against no correlation. |
|
Build a grid over (-1, 1) that resolves a sharply peaked posterior. |
|
Check two paired samples and drop rows where either value is missing. |
Regression¶
|
Fit a least-squares line, dropping rows where either value is missing. |
|
The sufficient statistics of a least-squares line. |
|
Exact Student-t posterior for the slope. |
|
Exact posterior for the average outcome at |
|
Posterior predictive distribution of one new outcome at |
|
Log Zellner-Siow Bayes factor for "the slope is not zero". |
Partial pooling¶
|
Pull group means toward the overall average, in proportion to noise. |
|
Pull group rates toward the typical rate, by empirical-Bayes beta-binomial. |
|
Estimate the spread between true group means, by DerSimonian-Laird. |
Summarising a posterior¶
|
Posterior interval, taken analytically when that is possible. |
|
Highest-density interval from posterior draws. |
|
Equal-tailed interval from posterior draws. |
|
Posterior probability that a quantity satisfies a comparison. |
|
Compute the standard error of a posterior mean from i.i.d. |
Grid approximation¶
|
Turn an unnormalised log density on a grid into a proper density. |
|
Sample from a grid-approximated posterior by inverting its CDF. |
|
Posterior mean by numerical integration on a grid. |
|
Quantiles of a grid-approximated posterior. |