Get startedGet started for free

Discrete posterior

Great work! In comparing the effectiveness of the two drugs \(S\) and \(N\), you constructed a prior distribution for the pair (pS, pN), where pS and pN are the probabilities of relieving pain. The prior was called a "testing prior" where the probability the two drugs are equally effective is 0.5.

Suppose that in a clinical trial, 12 out of 20 patients with the standard drug experienced relief, and 17 of 20 patients with the new drug experienced relief.

You can use the two_p_update() function to compute the posterior probabilities for (pS, pN) and the draw_two_p() function to construct a graph of the probabilities.

The posterior of the difference in probabilities d_NS = pN - pS is found using the two_p_summarize() function.

Now it's your turn to compute posterior probabilities using a uniform prior on (pS, pN)!

This exercise is part of the course

Beginning Bayes in R

View Course

Exercise instructions

A uniform prior, stored in prior, is defined such that each probability can take on the five values 0.1, 0.3, 0.5, 0.7, 0.9 and all possible (pS, pN) pairs are equally likely.

  • Define vectors s1f1 and s2f2 that contain the number of successes and number of failures for each of the two samples.
  • Use two_p_update() to compute the posterior distribution.
  • Use draw_two_p() to graph the posterior.
  • Use two_p_summarize() to find the posterior distribution on d_NS = pN - pS, and prob_plot() to graph this distribution.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define a uniform prior on all 25 pairs: prior
prior <- testing_prior(0.1, 0.9, 5, uniform = TRUE)

# Define the data: s1f1, s2f2
s1f1 <- ___
s2f2 <- ___

# Compute the posterior: post


# Graph the posterior


# Find the probability distribution of pN - pS: d_NS


# Graph this distribution
Edit and Run Code