I am trying to find the pdf of a double truncated exponential distribution using the following code:
x = TruncatedDistribution[{t1, t2}, ExponentialDistribution] // PiecewiseExpand
fx = PDF[x]
fx
but an errror occurs.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI am trying to find the pdf of a double truncated exponential distribution using the following code:
x = TruncatedDistribution[{t1, t2}, ExponentialDistribution] // PiecewiseExpand
fx = PDF[x]
fx
but an errror occurs.
You can obtain it as follows:
truncated = TruncatedDistribution[{t1, t2}, ExponentialDistribution[lambda]];
Assuming[{t1 > 0, t2 > t1}, PDF[truncated, x]]
(* Out:
Piecewise[
{
{lambda/(E^(lambda*x)*(E^((-lambda)*t1) - E^((-lambda)*t2))), t1 - x < 0 && t2 - x >= 0 && x >= 0},
{0, x < 0 || t1 - x >= 0 || x < 0 || t2 - x < 0}
},
Indeterminate
]
*)
For a graphical comparison, invluding the full non-truncated distribution from which the truncated one derives (choosing arbitrary values of $\lambda,t_1,t_2$):
values = {lambda -> 1, t1 -> 1/2, t2 -> 2};
full = ExponentialDistribution[lambda];
Plot[
Evaluate[{
1/(CDF[full, t2] - CDF[full, t1]) PDF[full, x],
PDF[truncated, x]
} /. values
],
{x, 0, 6},
Exclusions -> None, PlotRange -> All, AspectRatio -> 1,
PlotLegends -> {"full", "truncated"},
AxesStyle -> Directive[Black, 14], Filling -> Axis
]
PDF
include FullSimplify
, i.e., pdf = Assuming[{t1 > 0, t2 > t1}, PDF[truncated, x] // FullSimplify]
Plotting Evaluate[PDF[#, x] & /@ {full, truncated} /. values]
better illustrates that the total probability is always one.
$\endgroup$
Jun 22 at 16:36
x = TruncatedDistribution[{t1, t2}, ExponentialDistribution[\[Lambda]]] // PiecewiseExpand
and thenPDF[x, z]
. $\endgroup$