Conditioning on the data (again)
Let's resurrect the zombie site example where you tested text ads. Out of a 100 impressions of the text ad, 6 out of a 100 clicked and visited your site.
To the right is roughly the code you developed in the last exercise. pars
is currently the joint distribution over all combinations of proportion_clicks
and n_visitors
.
This exercise is part of the course
Fundamentals of Bayesian Data Analysis in R
Exercise instructions
- Condition on the data and keep only the rows in
pars
wheren_visitors == 6
. - Normalize
pars$probability
again, to make sure it sums to1.0
. - Plot the posterior
pars$probability
usingplot(x = , y = , type = "h")
withpars$proportion_clicks
on the x-axis andpars$probability
on the y-axis.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
n_ads_shown <- 100
proportion_clicks <- seq(0, 1, by = 0.01)
n_visitors <- seq(0, 100, by = 1)
pars <- expand.grid(proportion_clicks = proportion_clicks,
n_visitors = n_visitors)
pars$prior <- dunif(pars$proportion_clicks, min = 0, max = 0.2)
pars$likelihood <- dbinom(pars$n_visitors,
size = n_ads_shown, prob = pars$proportion_clicks)
pars$probability <- pars$likelihood * pars$prior
pars$probability <- pars$probability / sum(pars$probability)
# Condition on the data
pars <- ___
# Normalize again
pars$probability <- ___
# Plot the posterior pars$probability
plot(___)