using AcceptReject method –
Shifted Gompertz distribution
Shifted Gompertz distribution is useful distribution which can be used to describe time needed for adopting new innovation within the market. Recent studies showed that it outperforms Bass model of diffusion in some cases^{1}.
Its pdf is given by
Below we show what happens if we increase parameter (inverse of propensity to adopt) for different values of appeal of innovation.
Higher parameter is set more density mode is shifted away from .
This distribution do not have closed form solutions for moments. If we want to calculate them and also simulate data for model validation we need to be able to sample from it.
Luckily there is a simple way of producing samples from arbitrary density:
Fundamental Theorem of Simulation.
Simulating
is equivalent to simulating
Direct corollary introduces convenient way of simulating from target distribution:
AcceptReject algorithm.
Let and let be a density function that satisfies for some constant and .
Then, to simulate it is sufficient to generate pair
until
Function is sometimes called envelope function. More tight the inequality the more efficient sampling will be.
Simulating from Shifted Gumbel distribution
Let’s assume for a moment that our density has bounded support.
Below we plot an example of using AcceptReject method for sampling from target density with simple constant envelope function:
This way of simulating distribution works but is not particularly efficient as more than 75% of sample is rejected and that’s with assumption that the support of target density is in . If we would extend support of the target density to further away from we would see increasing drop of sampler efficiency.
We can easily improve our sampling method by noticing the following inequality:
This will provide us nice majorization function for the tail of shifted Gompertz distribution by scaled exponential density.
In order to make it more tight around mode of our target density we can define improved envelope function as:
where is a point where envelope function reaches maximum of shifted Gompertz density and is a value of the density at this point.
Of course is not a density itself. Since it is integrable we can recover density as
which is mixture of uniform and truncated exponential distribution.
Algorithm pseudocode
select component with probabilities p1(b, eta) and p2(b, eta)
Repeat
sample y from selected density component
sample u from U[0, h'(yb, eta)]
Until u < p(yb, eta)
Sampling results
Kolmogorov Smirnov test
It’s straightforward to test whether we sample from correct distributions by comparing empirical cumulative distribution function with exact one.
Onesample KolmogorovSmirnov test
data: s
D = 0.0018236, pvalue = 0.8936
alternative hypothesis: twosided
Perfect! Sampled data distribution is indistinguishable from theoretical density. We can also inspect sampling results visually:
Summary
We created from scratch new sampler for shifted Gompertz distribution 🙂 and it’s fairly efficient: for one milion of sampled values it takes latter algorithm only 0.138 of a second.
Code for this post can be found here:
https://github.com/jakubglinka/posts/tree/master/diffusion_part1

Bauckhage, Christian; Kersting, Kristian (2014). “Strong Regularities in Growth and Decline of Popularity of Social Media Services” ↩
Rbloggers.com offers daily email updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...