Home > Bayesian computation, Single parameter > Brute-force computation of a posterior

Brute-force computation of a posterior

Suppose we observe y that is normal with mean theta and standard deviation sigma. Instead of using a conjugate prior, suppose that theta has a t distribution with location mu, scale tau, and degrees of freedom df. Although there is not a nice form for the posterior density, it is straightforward to compute the posterior by use of the “prior x likelihood” recipe. We write a function post.norm.t.R that computes the posterior.

# we source this function into R


# define parameters of problem


# set up grid of values of theta


# compute the posterior on the grid


# convert the posterior value to probabilities


# sample from discrete distribution on grid


# construct a histogram of simulated sample
# and place exact posterior on top

hist(sim.theta, freq=FALSE)
con=sum(d*post) # this is normalizing constant

From the simulated sample, we can compute any summary of the posterior of interest.

  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 )

Connecting to %s

%d bloggers like this: