Home > Single parameter > Discrete Bayes

Discrete Bayes

One good way of introducing Bayesian inference is by the use of discrete priors. I recently wrote a simple generic R function that does discrete Bayes for arbitrary choice of a prior and sampling density.   I’ll illustrate this function here and in the next posting.

Suppose I’m interested in learning about the rate parameter of an exponential density.  We observe a sample y_1, ..., y_n  from the density defined by

f(y|\theta) = \theta \exp(-\theta y)

where we are interested in learning about the rate parameter \theta.

In R, I read in the function “discrete.bayes” and a few associated methods by typing

> source(“http://bayes.bgsu.edu/m6480/R/discrete.bayes.functions.R”)

I define my prior.  I believe the values .05, .10, …, 0.50 are all plausible rate values and I assign each the same prior probability.  In the following R code, prior is a vector of probabilities where I’ve named the probabilities by the values of the rate.
> rate=seq(.05,.50,by=.05)
> prior=rep(.1,10)
> names(prior)=rate
> prior
0.05  0.1 0.15  0.2 0.25  0.3 0.35  0.4 0.45  0.5
0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1
Now I enter in the observations:
> y=c(6.2, 5.0, 1.2, 10.2, 5.9, 2.3, 1.1, 19.0,  4.2, 27.5)
I update my probabilities by the function discrete.bayes — the arguments are the sampling density (dexp), the prior vector, and the data vector.
> s=discrete.bayes(dexp,prior,y)
To display, graph, and summarize these probabilities, I use the generic functions “print”, “plot”, and “summary”.
Here are the posterior probabilities.
> print(s)
0.05          0.1         0.15          0.2         0.25          0.3
2.643537e-02 4.353606e-01 4.037620e-01 1.153126e-01 1.727192e-02 1.719954e-03
0.35          0.4         0.45          0.5
1.292256e-04 7.900085e-06 4.125920e-07 1.903091e-08
To display the probabilities, use “plot”.
> plot(s,xlab=”RATE”,ylab=”PROBABILITY”)
expplotTo find a 90% probability estimate for the rate, use summary:
> summary(s,coverage=0.90)
$coverage
[1] 0.9544352
$set
[1] 0.10 0.15 0.20
The probability the rate is in the set {0.10, 0.15, 0.20} is 0.95.
Advertisements
Categories: Single parameter
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: