Bayesian Thinking

Learning about a correlation — part III

Advertisements

In Chapter 5, we discuss the SIR method of simulating from a posterior density .  Like rejection sampling, we find a proposal density that is easy to simulate from and covers the posterior density of interest.  Here’s the algorithm:

1.  We simulate a sample  from the proposal density .

2.  We compute weights .

3.  We resample from the with replacement with weights proportional to .

The resampled values are approximately from the distribution of interest .

The function sir in the LearnBayes package implements this algorithm when the proposal density is a t density with arbitrary mean, variance and degrees of freedom.

For this example, we showed that a Normal(0.50, 0.009) density was a reasonable approximation to the posterior.  So we use a t proposal density with location 0.50, variance 0.009 and 4 degrees of freedom.  We decide to simulate 10,000 values.

The sir function’s arguments are similar to those for rejectsampling — function that defines the log posterior, parameters of the t proposal, number of simulated draws, and the data used in the log posterior function.

R=sir(cor.sampling,list(m=.5,var=.009,df=4),10000,dz)
plot(density(R),col=”blue”,lwd=3)

R=sir(cor.sampling,list(m=.5,var=.009,df=4),10000,dz)

The output is a vector of 10,000 values.  We construct a density plot of the draws and it resembles the display in the previous posting.

plot(density(R),col=”blue”,lwd=3)

Advertisements