I am looking for a distribution where the probability density decreases quickly after some point away from the mean, or in my own words a "plateau-shaped distribution".
Something in between the Gaussian and the uniform.
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It only takes a minute to sign up.
Sign up to join this communityI am looking for a distribution where the probability density decreases quickly after some point away from the mean, or in my own words a "plateau-shaped distribution".
Something in between the Gaussian and the uniform.
You may be looking for distribution known under the names of generalized normal (version 1), Subbotin distribution, or exponential power distribution. It is parametrized by location $\mu$, scale $\sigma$ and shape $\beta$ with pdf
$$ \frac{\beta}{2\sigma\Gamma(1/\beta)} \exp\left[-\left(\frac{|x-\mu|}{\sigma}\right)^{\beta}\right] $$
as you can notice, for $\beta=1$ it resembles and converges to Laplace distribution, with $\beta=2$ it converges to normal, and when $\beta = \infty$ to uniform distribution.
If you are looking for software that has it implemented, you can check normalp
library for R (Mineo and Ruggieri, 2005). What is nice about this package is that, among other things, it implements regression with generalized normally distributed errors, i.e. minimizing $L_p$ norm.
Mineo, A. M., & Ruggieri, M. (2005). A software tool for the exponential power distribution: The normalp package. Journal of Statistical Software, 12(4), 1-24.
@StrongBad's comment is a really good suggestion. The sum of a uniform RV and gaussian RV can give you exactly what you're looking for if you pick the parameters right. And it actually has a reasonably nice closed form solution.
The pdf of this variable is given by the expression:
$$\dfrac{1}{4a}\left[\mathrm{erf}\left(\dfrac{x+a}{\sigma\sqrt{2}}\right)-\mathrm{erf}\left(\dfrac{x-a}{\sigma\sqrt{2}}\right) \right]$$
$a$ is the "radius" of the zero-mean uniform RV. $\sigma$ is the standard deviation of the zero-mean gaussian RV.
There's an infinite number of "plateau-shaped" distributions.
Were you after something more specific than "in between the Gaussian and the uniform"? That's somewhat vague.
Here's one easy one: you could always stick a half-normal at each end of a uniform:
You can control the "width" of the uniform relative to the scale of the normal so you can have wider or narrower plateaus, giving a whole class of distributions, which include the Gaussian and the uniform as limiting cases.
The density is:
$\frac{h}{\sqrt{2\pi}\sigma} e^{-\frac{1}{2\sigma^2}(x-\mu+w/2)^2} \mathbb{I}_{x\leq \mu-w/2} \\ + \:\frac{h}{\sqrt{2\pi}\sigma}\quad\mathbb{I}_{\mu-w/2< x\leq \mu+w/2} \\ + \frac{h}{\sqrt{2\pi}\sigma} e^{-\frac{1}{2\sigma^2}(x-\mu-w/2)^2} \mathbb{I}_{x > \mu+w/2} $
where $h = \frac{1}{1 + w/(\sqrt{2\pi}\sigma)}$
As $\sigma \to 0$ for fixed $w$, we approach the uniform on $(\mu-w/2,\mu+w/2)$ and as $w \to 0$ for fixed $\sigma$ we approach $N(\mu,\sigma^2)$.
Here are some examples (with $\mu=0$ in each case):
We might perhaps call this density a "Gaussian-tailed uniform".
See my "Devil's tower" distribution in here [1]:
$f(x) = 0.3334$, for $|x| < 0.9399$;
$f(x) = 0.2945/x^2$, for $0.9399 \leq |x| < 2.3242$; and
$f(x) = 0$, for $2.3242 \leq |x|$.
The "slip-dress"distribution is even more interesting.
It is easy to construct distributions having whatever shape you want.
[1]: Westfall, P.H. (2014)
"Kurtosis as Peakedness, 1905 – 2014. R.I.P."
Am. Stat. 68(3): 191–195. doi:10.1080/00031305.2014.917055
public access pdf: http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4321753/pdf/nihms-599845.pdf
Lots of nice answers. The solution proffered here has 2 features: (i) that it has a particularly simple functional form, and (ii) that the resulting distribution necessarily produces a plateau-shaped pdf (not just as a special case). I'm not sure if this already has a name in the literature, but absent same, let us call it a Plateau distribution with pdf $f(x)$:
$$f(x) = k \frac{1}{1 + x^{2 a}} \quad \quad \text{for } x \in \mathbb{R}$$
where:
Here is a plot of the pdf, for different values of parameter $a$:
.
As parameter $a$ becomes large, the density tends towards a Uniform(-1,1) distribution. The following plot also compares to a standard Normal (gray dashed):
Another one (EDIT: I simplified it now. EDIT2: I simplified it even further, though now the picture doesn't really reflect this exact equation):
$$f(x) = \frac{1}{3 \cdot \alpha} \cdot \log{\left( \frac{\cosh{\left(\alpha \cdot a\right)}+ \cosh{\left(\alpha \cdot x\right)}} {\cosh{\left(\alpha \cdot b\right)}+ \cosh{\left(\alpha \cdot x\right)}} \right)} $$
Clunky, I know, but here I took advantage of the fact that $\log(\cosh(x))$ approaches a line as $x$ increases.
Basically you have control over how smooth is the transition ($alpha$). If $a = 2$ and $b = 1$ I guarantee it's a valid probability density (sums to 1). If you choose other values then you'll have to renormalize it.
Here is some sample code in R:
f = function(x, a, b, alpha){
y = log((cosh(2*alpha*pi*a)+cosh(2*alpha*pi*x))/(cosh(2*alpha*pi*b)+cosh(2*alpha*pi*x)))
y = y/pi/alpha/6
return(y)
}
f
is our distribution. Let's plot it for a sequence of x
plot(0, type = "n", xlim = c(-5,5), ylim = c(0,0.4))
x = seq(-100,100,length.out = 10001L)
for(i in 1:10){
y = f(x = x, a = 2, b = 1, alpha = seq(0.1,2, length.out = 10L)[i]); print(paste("integral =", round(sum(0.02*y), 3L)))
lines(x, y, type = "l", col = rainbow(10, alpha = 0.5)[i], lwd = 4)
}
legend("topright", paste("alpha =", round(seq(0.1,2, length.out = 10L), 3L)), col = rainbow(10), lwd = 4)
Console output:
#[1] "integral = 1"
#[1] "integral = 1"
#[1] "integral = 1"
#[1] "integral = 1"
#[1] "integral = 1"
#[1] "integral = 1"
#[1] "integral = 1"
#[1] "integral = NaN" #I suspect underflow, inspecting the plots don't show divergence at all
#[1] "integral = NaN"
#[1] "integral = NaN"
And plot:
You could change a
and b
, approximately the start and end of the slope respectively, but then further normalization would be needed, and I didn't calculate it (that's why I'm using a = 2
and b = 1
in the plot).
If you are looking for something very simple, with a central plateau and the sides of a triangle distribution, you can for instance combine N triangle distributions, N depending on the desired ratio between the plateau and the descent. Why triangles, because their sampling functions already exist in most languages. You randomly sort from one of them.
In R that would give:
library(triangle)
rplateau = function(n=1){
replicate(n, switch(sample(1:3, 1), rtriangle(1, 0, 2), rtriangle(1, 1, 3), rtriangle(1, 2, 4)))
}
hist(rplateau(1E5), breaks=200)
Here's a pretty one: the product of two logistic functions.
(1/B) * 1/(1+exp(A*(x-B))) * 1/(1+exp(-A*(x+B)))
This has the benefit of not being piecewise.
B adjusts the width and A adjusts the steepness of the drop off. Shown below are B=1:6 with A=2. Note: I haven't taken the time to figure out how to properly normalize this.