# How to fit the Cauchy distribution to the data

I have data on financial returns, and I want to fit the Cauchy distribution and student distribution to that data. Furthermore I want to check the goodness of fit in both cases. Where should I start from?

-
@Start with a choice of a programming language, or pre-built software. – nbubis Jan 15 '13 at 13:30
thanks I'm using R. but I'm not sure how to do it. I mean do I have to estimate parameters of cauchy distribution? – user45689 Jan 15 '13 at 14:40
Of course you have to estimate parameters--that's how you fit the distribution. You might start here. – Jonathan Christensen Jan 15 '13 at 14:47

If I had a series of iid data $X_1, \dots, X_n$ that I assumed come from a Cauchy distribution with density $$f(x;\mu,\sigma)= \frac{1}{\sigma}\frac{1}{\pi(1+((x-\mu)/\sigma)^2}$$ Here is how I would do that in R: first, the log-density in R is the function

dcauchy(x,mu,sigma,log=TRUE)


then a function construction the log-likelihood function:

make_loglik <- function(x) {
function(para) {
sum(dcauchy(x,para[1],para[2],log=TRUE)) }
}


then actually making the loglik function:

loglik <- make_loglik(x)

and finally, maximizing this using optim() or some other optimization routine.

For the t-dist, you could just replace the cauchy density above with the t-density, but you should be aware that the t-likelihood is unbounded as a function of the degrees-of-freedom parameter! so just optimizing the likelihood might go very bad!

-
thanks for your comment. – user45689 Jan 15 '13 at 17:06
I have a question are yoou taking mu and sigma as mean and S.D. here or they are location and scale parameters? – user45689 Jan 15 '13 at 17:15
mu and sigma are location/scale parameters! mean do not exist! – kjetil b halvorsen Jan 15 '13 at 20:13
thanks, can we do this in that way > log <- function(theta, x) {sum(-dcauchy(x, location = theta[1], scale = theta[2], log = TRUE))} after that we can use nlm() theta.start <- c(median(x), IQR(x)/2) > out <- nlm(mlogl3, theta.start, x = x) > theta.hat <- out\$estimate – user45689 Jan 16 '13 at 12:10
In addition to accept the answer, you should really upvote it also ... – kjetil b halvorsen Jan 16 '13 at 16:06