Sampling from shifted Gompertz distribution

[This article was first published on Jakub Glinka's Blog, 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.

using Accept-Reject 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 cases1.

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 .

plot of chunk unnamed-chunk-1

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:

Accept-Reject 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 Accept-Reject method for sampling from target density with simple constant envelope function:

plot of chunk unnamed-chunk-2

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'(y|b, eta)]
Until u < p(y|b, eta)

Sampling results

plot of chunk unnamed-chunk-3

Kolmogorov Smirnov test

It’s straightforward to test whether we sample from correct distributions by comparing empirical cumulative distribution function with exact one.

	One-sample Kolmogorov-Smirnov test

data:  s
D = 0.0018236, p-value = 0.8936
alternative hypothesis: two-sided

Perfect! Sampled data distribution is indistinguishable from theoretical density. We can also inspect sampling results visually:

plot of chunk unnamed-chunk-6

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

  1. Bauckhage, Christian; Kersting, Kristian (2014). “Strong Regularities in Growth and Decline of Popularity of Social Media Services”

To leave a comment for the author, please follow the link and comment on their blog: Jakub Glinka's Blog.

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)