In: Math
4.3. Referring to the previous problem, again suppose that a uniform prior is placed on the proportion π, and that from a random sample of 327 voters, 131 support the sales tax. Also suppose that the newspaper plans on taking a new survey of 20 voters. Let y∗ denote the number in this new sample who support the sales tax.
Find the posterior predictive probability that y∗ = 8.
Find the95% posterior predictive interval for y∗.Do this by finding the predictive probabilities for each of the possible values of y∗ and ordering them from largest probability to smallest. Then add the most probable values of y∗ into your probability set one at a time until the total probability exceeds 0.95 for the first time.
library(LearnBayes)
n <- 20
s = 131
f = 327-131
#assuming uniform prior
alpha = 1
beta = 1
#a
pbetap( c(alpha+ s, f + beta ), n, 8)
#b
prob <- pbetap( c(alpha+ s, f + beta ), n, 0:n)
#theoretical probability
probTable <-as.data.frame( cbind(0:n, prob))
probTable <- probTable[order(-probTable$prob),]
probTable$Cumsum = cumsum(probTable$prob)
i <- (which(probTable$Cumsum >= 0.95) ) [1]
Interval <- probTable$V1[1:i]
Interval
Please rate
Please look below in comments for help in other questions