Conjugate Models
BayesianExperiments.ProbabilisticModel
— TypeProbabilisticModel
ProbabilisticModel
is a a model of the parameters that we are interested in. The model is defined by its prior distribution and likelihood function.
BayesianExperiments.ConjugateModel
— TypeConjugateModel <: ProbabilisticModel
ConjugateModel
is a ProbabilisticModel
with a conjugate prior of the corresponding likelihood function.
BayesianExperiments.ConjugateBernoulli
— TypeConjugateBernoulli <: ConjugateModel
Bernoulli likelihood with Beta distribution as the conjugate prior.
ConjugateBernoulli(α, β) # construct a ConjugateBernoulli
update!(model, stats) # update model with statistics from data
samplepost(model, numsamples) # sampling from the posterior distribution
samplestats(model, numsamples) # sampling statistics from the data generating distribution
BayesianExperiments.ConjugateExponential
— TypeConjugateExponential <: ConjugateModel
Exponential likelihood with Gamma distribution as the conjugate prior.
ConjugateExponential(α, β) # construct a ConjugateExponential
update!(model, stats) # update model with statistics from data
samplepost(model, numsamples) # sampling from the posterior distribution
samplestats(model, numsamples) # sampling statistics from the data generating distribution
BayesianExperiments.ConjugateNormal
— TypeConjugateNormal <: ConjugateModel
Normal likelihood and Normal Inverse Gamma distribution as the conjugate prior.
Parameters
- μ: mean of normal distribution
- v: scale variance of Normal
- α: shape of Gamma distribution
- θ: scale of Gamma distribution
ConjugateNormal(μ, v, α, θ) # construct a ConjugateNormal
update!(model, stats) # update model with statistics from data
samplepost(model, numsamples) # sampling from the posterior distribution
samplestats(model, numsamples) # sampling statistics from the data generating distribution
References
- The update rule for Normal distribution is based on this lecture notes.
BayesianExperiments.ConjugateLogNormal
— TypeConjugateLogNormal(μ, v, α, θ)
A model with Normal likelihood and Normal Inverse distribution with log transformed data. Notice LogNormal
in Distributions.jl
takes mean and standard deviation of $\log(x)$ instead of $x$ as the input parameters.
ConjugateLogNormal(μ, v, α, θ) # construct a ConjugateLogNormal
lognormalparams(μ_logx, σ²_logx) # convert normal parameters to log-normal parameters
update!(model, stats) # update model with statistics from data
samplepost(model, numsamples) # sampling from the posterior distribution
samplestats(model, numsamples) # sampling statistics from the data generating distributio
BayesianExperiments.ChainedModel
— TypeChainedModel <: ProbabilisticModel
ChainedModel
is a combination of ConjugateModel
s chained by the specified operator. It can be used to model a multiple step process.
Bayes Factor Models
BayesianExperiments.NormalEffectSize
— TypeNormalEffectSize <: EffectSizeModel
A standard effect size model has two hypotheses: $H_0$(null) an $H_1$(alternative):
- $H_0$: $\mu = m_0$
- $H_1$: $\mu ≠ m_0$
with the population mean $\mu$ and pre-specified standard deviation $\sigma$. We want to test whether $\mu$ is equal to $\mu_0$ or not.
The prior of the standard effect size is
$\delta | H_1 \sim \text{Normal}(0, \sigma_0^2)$
where $\delta$ is the standard effect size. When $\sigma_0 = 1$the prior is called unit-information prior.
The standard effect size $\delta$ is defined as
$\delta = \frac{\mu - \mu_0}{\sigma}.$
In practice, the standard deviations are unknown but in large sample scenario we assume they are known and use their estimates.
Fileds
μ0
: mean of null hypothesis.σ0
: The prior standard deviation of the effect size.p0
: prior belief of $H_0$. This is used to calculate the prior odds. Default $0.5$.
Methods
bayesfactor(model, stats) # calculate Bayes factor from one group statistics
bayesfactor(model, twostats) # calculate Bayes factor from two group's statistics
References
- Chapter 5 hypothesis Testing with Normal Populations in An Introduction to Bayesian Thinking.
- Deng, Alex, Jiannan Lu, and Shouyuan Chen. "Continuous monitoring of A/B tests without pain: Optional stopping in Bayesian testing." 2016 IEEE international conference on data science and advanced analytics (DSAA). IEEE, 2016.
BayesianExperiments.StudentTEffectSize
— TypeStudentTEffectSize <: BayesFactorModel
A model with Bayes factor from the Student's t distributions. We have a standard effect size model has two hypotheses: $H_0$(null) an $H_1$(alternative):
- $H_0$: $\mu = m_0$
- $H_1$: $\mu ≠ m_0$
The model uses the Jeffreys-Zellener-Siow (JZS) prior. More specifically, we use a Cauchy prior on $\mu$ for $H_1$
$\mu | \sigma^2 \sim \text{Cauchy}(0, r^2 \sigma^2)$
and a Jeffrey's prior on $\sigma$:
$p(\sigma^2) \propto \frac{1}{\sigma2}$
for both $H_0$ and $H_1$.
Fields
- $r$: Prior standard deviation of the effect size.
- $rtol$: Numerical tolerence fo the $quadgk$ function used in the denominator calculation.
- $p0$: prior belief of $H_0$. This is used to calculate the prior odds. Default $0.5$.
References
- Rouder, J. N., Speckman, P. L., Sun, D., Morey, R. D., & Iverson, G. (2009). Bayesian t tests for accepting and rejecting the null hypothesis. Psychonomic bulletin & review, 16(2), 225-237.
Stopping Rules
BayesianExperiments.ExpectedLossThresh
— TypeExpectedLossThresh <: StoppingRule
The experiment has a winning model if the model has the smallest posterior expected loss, and its expected loss value is below the threshold.
References
BayesianExperiments.ProbabilityBeatAllThresh
— TypeProbabilityBeatAllThresh <: StoppingRule
The experiment has a winning model if probability of that model's posterior samples is larger than the alternative models is above the threshold.
BayesianExperiments.OneSidedBFThresh
— TypeOneSidedBFThresh <: BayesFactorThresh
The bayes factor itself is interpretable as the comparative evidence of data under the two competing hypotheses. Higher bayes factor, as defined $\text{BF}_{10}$ favours the alternative hypothesis.
In practice, a threshold can be used to make decision in bayes factor experiment. The experiment will stop when $\text{BF}_{10}$ > threshold.
In this case, the bayes factor of alternative over null is above the threshold, we can accept the alternative hypothesis. Otherwise, we don't have enough evidence to accept alternative hypotheses.
BayesianExperiments.TwoSidedBFThresh
— TypeTwoSidedBFThresh <: BayesFactorThresh
The bayes factor itself is interpretable as the comparative evidence of data under the two competing hypotheses. Higher bayes factor, as defined $\text{BF}_{10}$ favours the alternative hypothesis.
In practice, a threshold can be used to make decision in bayes factor experiment. The experiment will stop when
- $\text{BF}_{10}$ > threshold
- $\text{BF}_{10}$ < 1/threshold
In (1), the bayes factor of alternative over null is above the threshold, we can accept the alternative hypothesis. In (2), the bayes factor is below the inverse of the threshold, we can accept the null hypothesis. Otherwise, we don't have enough evidence to accept any of these hypotheses.
Experiment
BayesianExperiments.Experiment
— TypeExperiment
An experiment has the models to compare, a stopping rule to make decision.
BayesianExperiments.ExperimentABN
— TypeExperimentABN{T,n} <: Experiment
An experiment with stopping rule of type T
and n
models. Models must have the same ProbabilisticModel
type.
BayesianExperiments.ExperimentAB
— FunctionExperimentAB(models, rule; modelnames=nothing) where T <: StoppingRule
An experiment of ExperimentABN
with two models.
BayesianExperiments.ExperimentBF
— TypeExperimentBF{M} <: Experiment
ExperimentBF
is an experiment using a Bayes Factor between the null and alternative hypothesis as the stopping rule.
Constructors
ExperimentBF(kwargs...)
Keywords
model::M
: Prior of effect size of alternative hypothesisp0::Float64
: Probablity of null hypothesiswinner::Union{String, Nothing
: Decision to reject the null hypothesis or notrule::BayesFactorThresh
: Stopping rule using Bayes Factor as the thresholdstats
: Statistics for calculating the bayes factor. Default isnothing
.modelnames
: Names of the hypotheses. Default is["null", "alternative"]
.
Simulation
BayesianExperiments.Simulation
— TypeSimulation(experiment, parameters, datagendists, maxsteps, onestepsizes, minsteps)
A simulation setup includes the experiment, data generating distributions, max number of steps and minimum number of steps.