Get startedGet started for free

Compare with classical methods

Agresti and Coull's classical interval method is available in your workspace as classical_binom_ci() and takes the arguments y, n and the confidence level conf.level.

For our example where 16 out of 20 students are concerned about being overweight, you can compute a 90% classical interval:

classical_binom_ci(16, 20, .90)

To compare between Bayesian and classical methods, suppose we assign P a uniform density (i.e. a \(beta(1, 1)\) curve).

Now you can construct a 90% Bayesian probability interval for P and compare this interval with the Agresti-Coull interval.

This exercise is part of the course

Beginning Bayes in R

View Course

Exercise instructions

  • Define the number of successes y and the sample size n.
  • Use the classical_binom_ci() function to find a 90% confidence interval for P.
  • Define the vector of prior beta shape parameters ab if we are assigning a uniform prior for P.
  • Find the vector beta shape parameters ab_new for the posterior curve.
  • Using the qbeta() function, construct a 90% Bayesian probability interval and compare with the classical interval you found in the second instruction.

Hands-on interactive exercise

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

# Define the number of successes and sample size: y, n
y <- ___
n <- ___

# Construct a 90 percent confidence interval


# Define the shape parameters for a uniform prior: ab


# Find the shape parameters of the posterior: ab_new


# Find a 90% Bayesian probability interval
Edit and Run Code