Is there an R function to calculate the Total Probability, once I get a Beta Posterior, after beginning with an initial Beta Prior in R

Viewed 114

I started with a uniform Prior of Beta [1,1] to model a probability Theta. P(Theta)

I used the Beta Binomial conjugacy approach, and got a posterior Beta [3,1]. P(Theta|X)

This is because ( I got 3 success in 3 trials).

Now I know I can visualize this Beta[3,1] as a PDF and draw information from it.(such as credible interval of Theta).

However, What I am interested in , is the Total Probability given the Theta.(Denominator of Bayes rule) . P(X)

I am not that good in integration. So is there some function in R, which will, calculate the Total Probability, using my new Posterior Beta prior. So that I can get a predictive interval.

1 Answers

I am not sure if the code below is for your purpose

p <- function(x) x**3*dbeta(x,1,1)/dbeta(x,3,1)
px <- function(x) p(x)/(integrate(p,0,1)$value)
Related