## Modeling with Cauchy errors

One attractive feature of Bayesian thinking is that one can consider alternative specifications for the sampling density and prior and these alternatives makes one think more carefully about the typical modeling assumptions.

Generally we observe a sample distributed from a sampling density depending on a parameter . If we assign a prior density , then the posterior density is given (up to a proportionality constant) by

Consider the following Cauchy/Cauchy model as an alternative to the usual Normal/Normal model. We let be distributed from a Cauchy density with location and known scale parameter , and we assign a Cauchy prior with location and scale .

Of course, this is not going to be a conjugate analysis — the posterior density has a complicated form. But it is easy to use R to plot and summarize the posterior density.

First we define the posterior density for . The arguments to the function are theta (which could be a vector), the vector of data values, the known scale parameter , and the prior parameters andn . The output is a vector of values of the (unnormalized) posterior density.

posterior=function(theta,data,scale,mu0,tau)

{

f=function(theta) prod(dcauchy(data,theta,scale))

likelihood=sapply(theta,f)

prior=dcauchy(theta, mu0, tau)

return(prior*likelihood)

}