Bayesian Sampler Example
In the example below, we will develop a simple Bayesian Sampler model of marginal and joint probability judgments. The first step will be to load BayesianSampler and Component arrays into the sessesion.
using BayesianSamplerModel
using ComponentArraysModel Setup
The first step of making a model is to define the joint distribution for events a and b. There are different approaches one could take. For example, one could define a 2\times 2 array, which would be convienent for computing marginals. Another way which is convienent for using a Dirichlet prior is to use a vector. One drawback is that the indices of the vector does not have an inherent meaning. ComponentArrays circumvent this problem by allowing both integer and keyword based indexing. The joint distribution is defined as:
Θs = ComponentArray(ab=.25, anb=.15, nab=.3, nanb=.3)ComponentVector{Float64}(ab = 0.25, anb = 0.15, nab = 0.3, nanb = 0.3)Next, we can define the model object by passing the joint distribution and other paremeters.
model = BSM(; Θs, β=1.0, n=10, n′=10)BSM{Float64, 1}(Θs=(ab = 0.25, anb = 0.15, nab = 0.3, nanb = 0.3), β=1.0, n=10, n′=10)Model Functions
For convienence, we can define two functions–-one to compute the marginal probability of a and another to compute the joint probablity of a and b
compute_a(m) = compute_marginal(m, m.Θs.ab + m.Θs.anb)
compute_ab(m) = compute_marginal(m, m.Θs.ab)compute_ab (generic function with 1 method)Using the Model
Now that we have set up the model and defined functions to compute the desired predictions, we can use the model. The predicted probability of a is computed as:
pa = compute_a(model)0.4166666666666667The predicted probability of a and b is computed as:
pab = compute_ab(model)0.2916666666666667