0
$\begingroup$

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.

$\endgroup$
3
  • 2
    $\begingroup$ The correct syntax would be: x = TruncatedDistribution[{t1, t2}, ExponentialDistribution[\[Lambda]]] // PiecewiseExpand and then PDF[x, z]. $\endgroup$ Jun 22 at 5:49
  • $\begingroup$ how to get pdf of double truncated exponential distribution? $\endgroup$ Jun 22 at 7:49
  • 3
    $\begingroup$ How are your tags related to your post in any way? Please edit post to improve capitalization, sentences and include code blocks to your post. You say "an error occurs"; please be more specific and include the error message. Thanks. $\endgroup$
    – Syed
    Jun 22 at 8:12

1 Answer 1

3
$\begingroup$

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
]
*)

pretty-printed version of the Piecewise output above

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
]

plot of PDF of full and truncated distributions

$\endgroup$
1
  • $\begingroup$ +1 For the 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$
    – Bob Hanlon
    Jun 22 at 16:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.