MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Laplace Distribution



In a message dated 4/3/98 6:05:23 AM, tie@cscn.com wrote:

>I am working on Lapalace Distribution with pdf f(x) = (2*beta)^(-1) *
>exp(-(absx)/beta). variance of this distribution is 2*(beta^2). so if
>we take beta=1/sqrt(2), we have laplace dist'n with unit variance. how
>can i write a Mathematica function for this density and how can i plot
>the  theoretical q-q plot of laplace against Normal.
>
>note. it has to integrate to one.

Needs["Statistics`ContinuousDistributions`"];
Needs["Statistics`DescriptiveStatistics`"];

dist = LaplaceDistribution[m, b]; PDF[dist, x]

E^(-((-m + x)*Sign[-m + x])/(2*b^2))

This PDF is in error.

D[CDF[dist, x] /. Sign[x - m] -> 1, x]

1/(2*b*E^((-m + x)/b))

D[CDF[dist, x] /. Sign[x - m] -> -1, x]

E^((-m + x)/b)/(2*b)

The PDF should be

Exp[-((Sign[x - m]*(x - m))/b)]/(2*b)

Since you are interested in the case of zero mean and unit variance,
then the  PDF is

Exp[-Sign[x - m]*(x - m)/b]/(2*b) /. {m -> 0, b -> 1/Sqrt[2]}

1/(Sqrt[2]*E^(Sqrt[2]*x*Sign[x]))

dist01 = LaplaceDistribution[0, 1/Sqrt[2]];  f[x_] :=
Exp[-Sign[x]*Sqrt[2]*x]/Sqrt[2]; 

Integrating the PDF over the domain should give unity:

Integrate[f[x] /. Sign[x] -> -1, {x, -Infinity, 0}] + 
  Integrate[f[x] /. Sign[x] -> 1, {x, 0, Infinity}]

1

Plot[{f[x], CDF[dist01, x]}, {x, -3, 3}]; 

The mean is

Integrate[x*f[x] /. Sign[x] -> -1, {x, -Infinity, 0}] + 
  Integrate[x*f[x] /. Sign[x] -> 1, {x, 0, Infinity}]

0

With a zero mean, the variance is equal to the mean square

Integrate[x^2*f[x] /. Sign[x] -> -1, {x, -Infinity, 0}] + 
  Integrate[x^2*f[x] /. Sign[x] -> 1, {x, 0, Infinity}]

1

Quantile is the inverse of the CDF.

Quantile[dist01, q]

-((Log[1 - (-1 + 2*q)*Sign[-1 + 2*q]]*Sign[-1 + 2*q])/Sqrt[2])

Plot[Quantile[dist01, q], {q, 0.1, 0.9}]; 

Plot[Quantile[dist01, CDF[dist01, x]], {x, -5, 5}]; 

Plot[CDF[dist01, Quantile[dist01, q]], {q, 0, 1}]; 

distNorm = NormalDistribution[0, 1]; PDF[distNorm, x]

1/(E^(x^2/2)*Sqrt[2*Pi])

Quantile[distNorm, q]

Sqrt[2]*InverseErf[0, -1 + 2*q]

I do not know what "the  theoretical q-q plot of laplace against Normal"
means; however, it may be something like one of the following

Plot[CDF[distNorm, Quantile[dist01, q]], {q, 0, 1}]; 

Plot[CDF[dist01, Quantile[distNorm, q]], {q, 0, 1}]; 


Bob Hanlon



  • Prev by Date: RE: Is it a BUG?
  • Next by Date: Re: AutoEvaluateOnOpen
  • Prev by thread: Laplace Distribution
  • Next by thread: PrograMMMing challenge