Pymc3 model where the results of a switch are directly observed

Viewed 340

I have just started learning pymc3 so I might be thinking about this completely the wrong way.

Assume that we observe a vector of 10 booleans.

The process of interest generates (observed) booleans with a Bernoulli distribution with a parameter theta1. So I define a Beta prior over theta1 and define a variable with length 10 that is a sample from Bernoulli(theta1).

However, this true sample is disturbed by sometimes switching the true data to 0, with a probability theta2. So I define a switch to 0 with a probability Bernoulli(theta2).

The switched values are the observed ones. I am not sure how to tell the model that I observed the switched variables, i.e. I am not sure how to fit the model to the observed data.

This is what I have for now, and I am kind of stuck:

# observed data (already switched)
observed_data = np.random.binomial(1, 0.5, size=10)

with pm.Model() as skeptic_model:
    # uniform probability of the bernoulli parameter
    true_model_prior = pm.Beta("true_model_prior", 1, 1)
    true_data = pm.Bernoulli("true_data", p=true_model_prior, shape=data.shape)
    disturbed_data = pm.math.switch(pm.Bernoulli("disturbed", 0.1), true_data, 0)
1 Answers

Your model can be reframed as a product of Bernoulli random variables, and therefore as a single Bernoulli random variable with a multiplicative p. Namely, the following model is equivalent to yours:

# observed data (already considered zero-inflated)
Y = np.random.binomial(1, 0.5, size=10)

with pm.Model() as zero_inflated_beta_bernoulli:
    # true_model_prior
    p = pm.Beta('p', alpha=1, beta=1)

    # dropout rate
    d = 0.1

    # disturbed_data;
    y = pm.Bernoulli('y', p = (1-d)*p, observed=Y)

You could let the dropout rate also be a random variable,

# dropout rate
d = pm.Beta('d', mu=0.1, sd=0.02)

However, it should be noted that this model really can't distinguish between dropouts and original outcomes, so the posteriors are sensitive to the priors.

Related