# R-help follow-up: truncated exponential

**BioStatMatt » R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I recently posted the message below with regard to sampling from the truncated exponential distribution. I left out the derivation of the CDF (mostly because text math is ugly), so I’ve included it here. There is also a short JSS article about truncated distributions in `R`. This problem in particular may likely be found in an introductory text on survival analysis or probability theory.

Where is the level of truncation and is the rate, the normalization constant is given by

The truncated exponential CDF is then

Solving for the inverse CDF yields the `itexp` function below. From the `R`-help list:

Since there is a simple closed form for the truncated exponential CDF, you can use inverse transform sampling. I believe this is quite common in survival analysis methods. The first step is to compute and write an R function to compute the inverse CDF for the truncated exponential, say

itexp <- function(u, m, t) { -log(1-u*(1-exp(-t*m)))/m }where u is the quantile, m is the rate, and t is the level of truncation. Next, we draw from the truncated exponential with something like

rtexp <- function(n, m, t) { itexp(runif(n), m, t) }

**leave a comment**for the author, please follow the link and comment on their blog:

**BioStatMatt » R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.