Get startedGet started for free

Comparison of proportions

Recall that when comparing two drugs with the use of a uniform prior, the posterior distributions for the two proportions were independent with pS as \(beta(13, 9)\) and pN as \(beta(18, 4)\).

Suppose a vector of differences d_NS = pN - pS is computed. A histogram of the posterior density of d_NS is displayed on the right with a 90 percent probability interval marked by vertical lines.

Now you will look at the posterior of the ratio of proportions r_NS = pN / pS.

This exercise is part of the course

Beginning Bayes in R

View Course

Exercise instructions

  • Use the code provided in the editor to simulate 1000 draws from the posterior of (pS, pN).
  • For each pair of simulated proportions, compute the ratio of proportions r_NS.
  • Construct a histogram of the simulated values of r_NS.
  • Find the probability r_NS is larger than 1.
  • Find an 80% probability interval for r_NS.

Hands-on interactive exercise

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

# Simulate 1000 draws from the posterior: sim_pS, sim_pN
sim_pS <- rbeta(1000, 13, 9)
sim_pN <- rbeta(1000, 18, 4)

# For each pair of proportions, compute the ratio: r_NS


# Plot a histogram of the values in r_NS


# Find the probability r_NS is larger than 1


# Find a 80% probability interval for r_NS
Edit and Run Code