Exercise

Simulating from a beta curve

Suppose Rebekah's beliefs about the proportion P of female students who think they are overweight is modeled by a beta curve with parameters 24.13 and 7.67.

Suppose you make 1000 draws from Rebekah's posterior curve using the rbeta() function.

The hist() function can be used to construct a histogram of the simulated values, upon which you can place the beta curve.

p_sim <- rbeta(1000, 24.13, 7.67)
hist(p_sim, freq = FALSE)
curve(dbeta(x, 24.13, 7.67),
      add = TRUE, col = "red", 
      lwd = 2)

You can perform different inferences about the proportion P by summarizing this sample of simulated draws.

Instructions

100 XP

Summarize Harry's posterior density for P, which is beta with parameters 19 and 7.

  • Define the vector ab, the beta shape parameters for Harry's posterior.
  • Use the rbeta() function to simulate 1000 values from this beta curve. Store the values in p_sim.
  • Construct a histogram of the simulated values.
  • From the simulated values, compute the probability that P is larger than 0.7.
  • Use the simulated values and the quantile() function to compute a 90% Bayesian probability interval.