How do I calculate a Cauchy random variable and how do I calculate the probability mass function to show it is "heavy tailed"
-
By "calculate", do you mean simulate? As in, feed some input from a standard random number generator into an algorithm and get an output that is a sample from a Cauchy distribution? – Michael Hardy Sep 04 '13 at 23:09
-
It doesn't have a probability mass function, i.e. it's not a discrete distribution. But the probability density function is often taken to be the definition, so they're handing you that much free on a silver platter. How you go on from there to show it is heavy-tailed is another matter. But at this point maybe you should be more explicit about what you already know and what you're asking about. – Michael Hardy Sep 04 '13 at 23:10
-
@MichaelHardy, maybe? I need to generate a Cauchy random variable in MATLAB. I know nothing about Cauchy random variables. This is a classic graduate school homework assignment without any covering it in class. – Elpezmuerto Sep 04 '13 at 23:11
-
2I believe a Cauchy random variable is continuous, so it has a probability density function, not a probability mass function. – Tunococ Sep 04 '13 at 23:13
-
2If you don't know what a Cauchy distribution is, you should start with that question. Googling will probably answer it instantly, and maybe looking in the index to your textbook would as well. – Michael Hardy Sep 04 '13 at 23:15
-
Michael Hardy's comment is exactly what I have in mind. How do you define a distribution that you don't know? – Tunococ Sep 04 '13 at 23:18
-
@MichaelHardy, I checked out the wikipedia article but that didn't explain to me why in non-mathy terms. I also generated a distribution in Matlab and can see it is heavy tailed, just don't understand why. – Elpezmuerto Sep 04 '13 at 23:22
-
@Elpezmuerto : It says right at the beginning that it's a distribution whose density is $1/(\pi(1+x^2))$. That's a simple as you can get. If you want to understand why it has heavy tails, or even what heavy tails are, you're going to need to work with that. Including some integrals involving that function. If that's too "mathy" for you, then you won't be able to do this. – Michael Hardy Sep 04 '13 at 23:28
-
It's not clear that you've asked a question here. If someone writes a question in a language you don't understand, and you copy it here, that's not a question in your mind that you're addressing to us. – Michael Hardy Sep 04 '13 at 23:29
-
@MichaelHardy I am just lose on how I go from the pdf to generating a random variable. I can obviously see what the pdf is – Elpezmuerto Sep 04 '13 at 23:30
-
@MichaelHardy I guess the question then is how to go from pdf to generating random variables, specifically cauchy – Elpezmuerto Sep 04 '13 at 23:33
4 Answers
In general, the fundamental result you need is that for any random variable $X$ with distribution function $F$, the random variable $Y=F(X)$ has a uniform distribution on $[0,1]$. Consequently, if you can invert $F$, then you can use a uniform density to simulate back your random variable $X$, since $X = F^{-1}(Y)$.'
In your case, the cdf of a standard Cauchy is $$F=\dfrac{1}{\pi}\arctan(x)+\dfrac{1}{2}$$ and therefore if you let $$y= \dfrac{1}{\pi}\arctan(x)+\dfrac{1}{2}$$ you immediately get $$x = \tan{\left(\pi \left(y - \dfrac{1}{2}\right)\right)}$$
Hence, to generate a standardized Cauchy, use the rand
function in Matlab to generate a uniform $[0,1]$ variate subtract 1/2 from it, multiply the result by $\pi$, and apply the tangent function. Repeat a bunch of times to get your sample.
Another interesting way to simulate a Cauchy variable is based upon the observation that the ratio of two Normal distributions is Cauchy distributed. Hence you can generate two standard independent Normal arrays and do their ratio term by term. The resulting array will be Cauchy distributed.

- 1,885
-
-
2"Cumulative density"? There's no such thing as cumulative density. The word "cumulative" contradicts the word "density". There are cumulative probability distribution functions. Those are certainly not probability density functions. – Michael Hardy Sep 05 '13 at 18:52
-
-
Could this also work for the multivariate Cauchy distribution? Is there a cdf of the multivariate Cauchy distribution? I cant find it, and have no clue about how to derive it. – Hjan Aug 30 '18 at 09:08
-
the inverse cdf is also called the "percent point function" denoted by ppf in software in case anyone wants to know in the future – Larry Pickles Oct 09 '22 at 21:20
The expected value of a random variable with density $f$ is equal to $$ \int_{-\infty}^\infty xf(x)\,dx $$ provided $$ \int_{-\infty}^\infty |x|f(x)\,dx<\infty. $$ If that last condition fails to hold, then some strange things can happen. One of those is that the conclusion of the strong law of large numbers will fail. With the Cauchy distribution, one has $$ \int_{-\infty}^\infty |x|f(x)\,dx=\infty. $$ Consequently things like the following can happen: \begin{align} & \int_{-a}^a x f(x)\,dx \to 0\text{ as } a\to\infty \\[8pt] \text{ but } & \int_{-a}^{2a} xf(x)\,dx\to\text{a nonzero number as }a\to\infty. \end{align} Work out the integrals and you'll see that. That's the "heavy-tailed" nature of the thing.
Now suppose $X$ is uniformly distributed between $-\pi/2$ and $\pi/2$. Then \begin{align} f_{\tan X}(w) & =\frac{d}{dw} F_{\tan X}(w) = \frac{d}{dw}\Pr(\tan X\le w) \\[8pt] & = \frac{d}{dw} \Pr(X\le\arctan w) \\[8pt] & = \frac{d}{dw}\int_{-\pi/2}^{\arctan w} \frac{dx}\pi \\[8pt] & = \frac1\pi\cdot\frac{d}{dz} \left( \arctan w +\frac\pi2 \right) \\[8pt] & = \frac{1}{\pi(1+w^2)}. \end{align}
So there you have a way to simulate a Cauchy-distributed random variable: First simulate a random variable uniformly distributed between $\pm\pi/2$. Then take its tangent (in radians).
Cauchy random variables can be obtained by sampling the inverse CDF of the distribution. This technique is referred to as inverse transform sampling and is very useful for generating random variates from many distributions. Starting with the cumulative distribution function, where $\mu$ is the location parameter and $c$ is the scale parameter
$$F(x;\mu,c) = \frac{1}{\pi}\text{arctan}\left(\frac{x - \mu}{c}\right) - \frac{1}{2}$$
we solve for $x$ as a function for $F$, which in this case is straightforward:
$$x = c\cdot\text{tan}(\pi (F - ½))+\mu$$
$F$, being the CDF, varies from 0 to 1. Thus, if we can replace $F$ with values randomly sampled from the uniform distribution on $(0, 1)$, we obtain corresponding values sampled from the Cauchy distribution. If $\mu = 0$ and $c = 1$ one obtains the "standard" Cauchy distribution.
In Matlab:
function r = cauchyrnd(mu,c,varargin)
%R = CAUCHYRND(mu,c,M,N)
r = c.*tan(pi*(rand(varargin{:})-0.5))+mu;
The first two arguments are the location and scale parameters of the Cauchy distribution and any subsequent arguments just need to match the input format of the rand
function.

- 3,203
Ratio of two standard normal variables is Cauchy. Sample two gaussian random variables and take their ratio, you will get a Cauchy.

- 597