Get startedGet started for free

Bayesian models and conditioning

1. Bayesian models and conditioning

2. Bayes needs this 5

Now we have a generative model and priors, and together these form a Bayesian model.

3. Bayes needs this 6

So if some statistician is talking about that she’s developed a Bayesian model of something, that just means she has specified a generative model for the data plus priors over what is uncertain in the model. The only thing we need now to do Bayesian inference is some data. And it’s actually the case that you got tired of me talking about probability distributions and just decided to run your ad campaign. And it went better than expected!

4. Bayes needs this 6 and a half

When the ad was shown a 100 times, 13 people clicked and visited your site. So now we have data,

5. Bayes needs this 7

and we are ready to do some Bayesian inference, we are ready to use this data to learn about how likely people are to click on your ad. How could we do that? Let’s take a look at

6. Bayes 1

the model we have so far and see if we can figure that out. The prior over proportion_clicks and the generative model for n_visitors together define a prior probability distribution over both parameters and future, unknown data. I’m going to put these together in a data frame and call it just prior.

7. Bayes 2

Now the data frame prior represents the joint probability distribution of proportion_clicks and n_visitors together. We could have a look at the first couple of samples in this data frame.

8. Bayes 3

But it’s easier to see what going on if we plot this data frame as

9. marginal_plot_all.png

a scatter plot. On the x-axis we have the number of visitors, and on the y-axis we have the underlying proportion of clicks. The histograms show the marginal distributions, and you should recognize them both, the one for the proportion of clicks is uniform between 0% and 20%, just as we defined it to be, and the one for n_visitors is the one we looked at last exercise. We clearly see a pattern in the plot, the higher the underlying proportion of clicks, the more visitors we’ll probably get. But we also see that the more visitors we get, the higher the underlying proportion of clicks probably is. If we knew that proportion_clicks was exactly 10%, we could condition on this, that is,

10. marginal_plot_prop_10.png

remove all samples that don’t fulfill the condition of proportion_clicks being 10%. This would also reduce the uncertainty in how many visitors we would get. If we knew the proportion of clicks was 10%, we would be pretty certain we would end up with between 2 and 15 visitors.

11. marginal_plot_prop_animation.gif

If we condition on other values the probability distribution over the number of visitors shifts accordingly. However, there is no point to this, because the problem was that we didn’t know what the underlying proportions of clicks could be.

12. marginal_plot_all.png

But what we can know is the data, and we can condition on the data too. Say that 5 out of a 100 clicked when we ran the ad campaign. If we

13. marginal_plot_visit_5.png

remove all samples that doesn’t fulfill this condition, we also reduce the uncertainty in what the underlying proportion of clicks could be. We end up with a distribution that doesn’t look at all like the uniform distribution between 0% and 20% we defined before. And if we actually would have gotten 5 visitors we could have concluded that proportion_clicks probably would be between 3% and 10%.

14. marginal_plot_visit_animation.gif

And similarly we could condition on other values for the data. We have now reached

15. The essence of Bayesian inference

the essence of what Bayesian inference is, it is conditioning on the data, in order to learn about what parameters values likely gave rise to this data. So, when you ran the ad campaign you got 13 site visits out of a 100 shown ads.

16. Try some Bayesian inference yourself!

Now you try doing some Bayesian inference yourself and condition on this data.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.