discretebayes.R

Jim — Sep 4, 2013, 9:36 PM

######################################
# Discrete Prior for a Proportion
######################################

# load in LearnBayes package

library(LearnBayes)

# construct the discrete prior

p <- seq(0.01, 0.99, by=0.01)
prior <- rep(1/99, 99)

# observe 5 successes, 10 failures

data <- c(5, 10)

# compute posterior probabilities

post <- pdisc(p, prior, data)

# line graph of posterior distribution

plot(p, post, type="h")

plot of chunk unnamed-chunk-1


# construct matrix, columns are p and posterior probabilities

post.distribution <- cbind(p, post)

# find 90% probability interval

discint(post.distribution, 0.90)
$prob
[1] 0.9017

$set
 [1] 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30
[15] 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.40 0.41 0.42 0.43 0.44
[29] 0.45 0.46 0.47 0.48 0.49 0.50 0.51 0.52 0.53

#################################