So for my problem, there are n = 10,000 people involved in a clinical trial. Each has probability \theta_p of getting a virus after receiving a vaccine. We are given that \theta_p \in (0,1).
I've determined my likelihood function to be Y \sim Binomial(n, \theta_p), and my prior to be
Beta(\alpha, \beta), thus giving me a posterior distribution equal to Beta(A,B) where A = Y + \alpha, and B = n - Y + \beta.
I want to plot all these on a single graph. Here is what I have tried:
# Creating likelihood function n <- 10000 success <- 0:n likelihood <- dbinom(success, size = n, prob = .5) # p = 0.5 chosen WLOG # Creating the prior distribution p <- seq(0,1, length = n) alpha <- 1 # shape parameters alpha and beta chosen arbitrarily to be equal to 1 beta <- 1 prior <- dbeta(success, shape1 = alpha, shape2 = beta) # Creating the posterior distribution Y <- 7000 # chosen WLOG posterior <- dbeta(success, shape1 = (Y + alpha), shape2 = (n - Y + beta)) # Making the plots plot(success, likelihood , type = "l", col = "blue") lines(success, prior, type = "l", col = "red") lines(success, posterior, type = "l", col = "green")
However, when I plot these functions, I'm getting this as an error:
Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
Any help fixing this issue and getting my plots to work would be greatly appreciated. Thank you!