Home > Single parameter > Modeling with Cauchy errors

## 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 $y_1, ..., y_n$ distributed from a sampling density $f(y|\theta)$ depending on a parameter $\theta$.  If we assign $\theta$  a prior density $g(\theta)$, then the posterior density is given (up to a proportionality constant) by

$g(\theta | y) = g(\theta) \prod_{i=1}^n f(y_i | \theta)$

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

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 $\theta$.  The arguments to the function are theta (which could be a vector), the vector of data values, the known scale parameter $\sigma$, and the prior parameters $\mu_0$ andn $\tau$.  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)
}

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)
}

(This function is a little tricky to program since both theta and data are vectors.)
We can plot the posterior density using the curve function.   We first give the data vector, assume $\sigma = 1$ and assign a Cauchy(0, 1) prior for $\theta$.
data=c(2,5,4,3,10,11,10,9)
We then use the curve function to plot the posterior.  After some preliminary work, we know that the probability mass falls between 0 and 15, so we use from = 0, to = 15 in the function.
curve(posterior(x,data,1,0,1),from=0,to=15,xlab=”THETA”,ylab=”DENSITY”)
Here is the plot that is produced.  Note the interesting bimodal shape.  One can obtain different posterior shapes when we model using Cauchy densities.  (Question:  Why does the posterior have this particular shape?)