Hello,
I am looking for some help fitting a mixture of binomials. My data is of the form
Counts = w*Bin(p1,n) + (1-w)*Bin(p2,n)
however, when I do inference on the mixture, W is always mis-estimated. Any help is appreciated, and I can give more code if that is useful. The main goal is to estimate the mixing weight of two known distributions.
When I dummy some data, with say a mixing w of 0.4, I always get back a w of 0.6
Snippet:
n = pm.ConstantData("n",value=row["N"])
mix_frac = pm.Beta("mix_frac",alpha=1,beta=1)
p_type0 = 1e-4
p_type1 = 5e-2
observed = row["observed_counts"]
dims = "observation"
component_t0 = pm.Binomial.dist(
n = n,
p = p_type0,
)
component_t1 = pm.Binomial.dist(
n = n,
p = p_type1,
)
observed_counts = pm.Mixture(
"observed_counts",
w = pt.stack([1-mix_frac,mix_frac],axis=1),
comp_dists = [
component_t0,
component_t1
],
observed = observed,
)
idata = pm.sample(progressbar=False)
I have the same issue if i try to infer the p’s and specify the w apriori, though this is less important to me right now
Snippet:
n = pm.ConstantData("n",value=scores["N"],dims="observation")
mix_frac = pm.ConstantData("mix_frac",value=scores["fraction"],dims="observation")
component_t0 = pm.Binomial.dist(
n = n,
p = p_type0,
)
component_t1 = pm.Binomial.dist(
n = n,
p = p_type1,
)
observed_counts = pm.Deterministic(
"counts",
1-mix_frac*component_t0+mix_frac*component_t1,
observed = observed,
dims = dims,
)
idata = pm.sample()