[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.
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
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="55.15ex" height="3.176ex" style="vertical-align: -0.838ex;" viewBox="-38.5 -1006.6 23745.2 1367.4" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-70">< use x="503" y="0" xlink:href="#MJMAIN-28">< use x="893" y="0" xlink:href="#MJMATHI-74">< use x="1254" y="0" xlink:href="#MJMAIN-7C">< use x="1533" y="0" xlink:href="#MJMATHI-62">< use x="1962" y="0" xlink:href="#MJMAIN-2C">< use x="2407" y="0" xlink:href="#MJMATHI-3B7">< use x="2911" y="0" xlink:href="#MJMAIN-29">< use x="3578" y="0" xlink:href="#MJMAIN-3D">< use x="4634" y="0" xlink:href="#MJMATHI-62">< g transform="translate(5230,0)">< use xlink:href="#MJMAIN-65">< use x="444" y="0" xlink:href="#MJMAIN-78">< use x="973" y="0" xlink:href="#MJMAIN-70">< use x="6760" y="0" xlink:href="#MJMAIN-28">< use x="7149" y="0" xlink:href="#MJMAIN-2212">< use x="7928" y="0" xlink:href="#MJMATHI-62">< use x="8357" y="0" xlink:href="#MJMATHI-74">< use x="8719" y="0" xlink:href="#MJMAIN-29">< g transform="translate(9275,0)">< use xlink:href="#MJMAIN-65">< use x="444" y="0" xlink:href="#MJMAIN-78">< use x="973" y="0" xlink:href="#MJMAIN-70">< use x="10805" y="0" xlink:href="#MJMAIN-28">< use x="11194" y="0" xlink:href="#MJMAIN-2212">< use x="11973" y="0" xlink:href="#MJMATHI-3B7">< g transform="translate(12476,0)">< use x="0" y="0" xlink:href="#MJMATHI-65">< g transform="translate(466,412)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-2212">< use transform="scale(0.707)" x="778" y="0" xlink:href="#MJMATHI-62">< use transform="scale(0.707)" x="1208" y="0" xlink:href="#MJMATHI-74">< use x="14152" y="0" xlink:href="#MJMAIN-29">< use x="14542" y="0" xlink:href="#MJMAIN-5B">< use x="14820" y="0" xlink:href="#MJMAIN-31">< use x="15543" y="0" xlink:href="#MJMAIN-2B">< use x="16544" y="0" xlink:href="#MJMATHI-3B7">< use x="17047" y="0" xlink:href="#MJMAIN-28">< use x="17437" y="0" xlink:href="#MJMAIN-31">< use x="18160" y="0" xlink:href="#MJMAIN-2212">< g transform="translate(19160,0)">< use xlink:href="#MJMAIN-65">< use x="444" y="0" xlink:href="#MJMAIN-78">< use x="973" y="0" xlink:href="#MJMAIN-70">< use x="20690" y="0" xlink:href="#MJMAIN-28">< use x="21079" y="0" xlink:href="#MJMAIN-2212">< use x="21858" y="0" xlink:href="#MJMATHI-62">< use x="22287" y="0" xlink:href="#MJMATHI-74">< use x="22649" y="0" xlink:href="#MJMAIN-29">< use x="23038" y="0" xlink:href="#MJMAIN-29">< use x="23428" y="0" xlink:href="#MJMAIN-5D">
Below we show what happens if we increase < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.169ex" height="2.176ex" style="vertical-align: -0.838ex;" viewBox="0 -576.1 503.5 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-3B7"> parameter (inverse of propensity to adopt) for different values of < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="0.998ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 429.5 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-62">appeal of innovation.
Higher < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.169ex" height="2.176ex" style="vertical-align: -0.838ex;" viewBox="0 -576.1 503.5 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-3B7"> parameter is set more density mode is shifted away from < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.162ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 500.5 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-30">.
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
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="9.496ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 4088.6 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-58">< use x="1130" y="0" xlink:href="#MJMAIN-223C">< use x="2186" y="0" xlink:href="#MJMATHI-66">< use x="2737" y="0" xlink:href="#MJMAIN-28">< use x="3126" y="0" xlink:href="#MJMATHI-78">< use x="3699" y="0" xlink:href="#MJMAIN-29">
is equivalent to simulating
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="38.384ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 16526.6 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-28">< use x="389" y="0" xlink:href="#MJMATHI-58">< use x="1242" y="0" xlink:href="#MJMAIN-2C">< use x="1687" y="0" xlink:href="#MJMATHI-55">< use x="2454" y="0" xlink:href="#MJMAIN-29">< use x="3121" y="0" xlink:href="#MJMAIN-223C">< use x="4178" y="0" xlink:href="#MJAMS-55">< use x="4900" y="0" xlink:href="#MJMAIN-7B">< use x="5401" y="0" xlink:href="#MJMAIN-28">< use x="5790" y="0" xlink:href="#MJMATHI-78">< use x="6363" y="0" xlink:href="#MJMAIN-2C">< use x="6808" y="0" xlink:href="#MJMATHI-75">< use x="7380" y="0" xlink:href="#MJMAIN-29">< use x="8048" y="0" xlink:href="#MJMAIN-3A">< use x="8604" y="0" xlink:href="#MJMAIN-30">< use x="9382" y="0" xlink:href="#MJMAIN-3C">< use x="10439" y="0" xlink:href="#MJMATHI-75">< use x="11289" y="0" xlink:href="#MJMAIN-3C">< use x="12345" y="0" xlink:href="#MJMATHI-66">< use x="12896" y="0" xlink:href="#MJMAIN-28">< use x="13285" y="0" xlink:href="#MJMATHI-78">< use x="13858" y="0" xlink:href="#MJMAIN-29">< use x="14247" y="0" xlink:href="#MJMAIN-7D">< use x="15748" y="0" xlink:href="#MJAMS-25A0">
Direct corollary introduces convenient way of simulating from target distribution:
Accept-Reject algorithm.
Let < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="9.496ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 4088.6 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-58">< use x="1130" y="0" xlink:href="#MJMAIN-223C">< use x="2186" y="0" xlink:href="#MJMATHI-66">< use x="2737" y="0" xlink:href="#MJMAIN-28">< use x="3126" y="0" xlink:href="#MJMATHI-78">< use x="3699" y="0" xlink:href="#MJMAIN-29"> and let < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="4.255ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 1832 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-67">< use x="480" y="0" xlink:href="#MJMAIN-28">< use x="870" y="0" xlink:href="#MJMATHI-78">< use x="1442" y="0" xlink:href="#MJMAIN-29"> be a density function that satisfies < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="14.213ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 6119.6 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-66">< use x="550" y="0" xlink:href="#MJMAIN-28">< use x="940" y="0" xlink:href="#MJMATHI-78">< use x="1512" y="0" xlink:href="#MJMAIN-29">< use x="2179" y="0" xlink:href="#MJMAIN-2264">< use x="3236" y="0" xlink:href="#MJMATHI-4D">< use x="4287" y="0" xlink:href="#MJMATHI-67">< use x="4768" y="0" xlink:href="#MJMAIN-28">< use x="5157" y="0" xlink:href="#MJMATHI-78">< use x="5730" y="0" xlink:href="#MJMAIN-29"> for some constant < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.703ex" height="2.343ex" style="vertical-align: -0.505ex;" viewBox="0 -791.3 2886.1 1008.6" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-4D">< use x="1329" y="0" xlink:href="#MJMAIN-2265">< use x="2385" y="0" xlink:href="#MJMAIN-31"> and < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="8.642ex" height="2.509ex" style="vertical-align: -0.671ex;" viewBox="0 -791.3 3721.1 1080.4" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-68">< g transform="translate(854,0)">< use xlink:href="#MJMAIN-3A">< use x="278" y="0" xlink:href="#MJMAIN-3D">< use x="2189" y="0" xlink:href="#MJMATHI-4D">< use x="3240" y="0" xlink:href="#MJMATHI-67">.
Then, to simulate < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.357ex" height="2.509ex" style="vertical-align: -0.671ex;" viewBox="0 -791.3 2737.1 1080.4" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-58">< use x="1130" y="0" xlink:href="#MJMAIN-223C">< use x="2186" y="0" xlink:href="#MJMATHI-66"> it is sufficient to generate pair
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="37.957ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 16342.3 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-59">< use x="1041" y="0" xlink:href="#MJMAIN-223C">< use x="2097" y="0" xlink:href="#MJMATHI-67">< use x="3578" y="0" xlink:href="#MJMATHI-61">< use x="4107" y="0" xlink:href="#MJMATHI-6E">< use x="4708" y="0" xlink:href="#MJMATHI-64">< use x="6231" y="0" xlink:href="#MJMAIN-28">< use x="6621" y="0" xlink:href="#MJMATHI-55">< use x="7388" y="0" xlink:href="#MJMAIN-7C">< use x="7667" y="0" xlink:href="#MJMATHI-59">< use x="8708" y="0" xlink:href="#MJMAIN-3D">< use x="9764" y="0" xlink:href="#MJMATHI-79">< use x="10262" y="0" xlink:href="#MJMAIN-29">< use x="10929" y="0" xlink:href="#MJMAIN-223C">< use x="11985" y="0" xlink:href="#MJAMS-55">< use x="12708" y="0" xlink:href="#MJMAIN-5B">< use x="12986" y="0" xlink:href="#MJMAIN-30">< use x="13487" y="0" xlink:href="#MJMAIN-2C">< use x="13932" y="0" xlink:href="#MJMATHI-68">< use x="14508" y="0" xlink:href="#MJMAIN-28">< use x="14898" y="0" xlink:href="#MJMATHI-79">< use x="15395" y="0" xlink:href="#MJMAIN-29">< use x="15785" y="0" xlink:href="#MJMAIN-5D">< use x="16063" y="0" xlink:href="#MJMAIN-2C">
until < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="13.753ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 5921.6 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-30">< use x="778" y="0" xlink:href="#MJMAIN-3C">< use x="1834" y="0" xlink:href="#MJMATHI-75">< use x="2684" y="0" xlink:href="#MJMAIN-3C">< use x="3741" y="0" xlink:href="#MJMATHI-66">< use x="4291" y="0" xlink:href="#MJMAIN-28">< use x="4681" y="0" xlink:href="#MJMATHI-78">< use x="5253" y="0" xlink:href="#MJMAIN-29">< use x="5643" y="0" xlink:href="#MJMAIN-2E">< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.292ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 2278.5 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="1500" y="0" xlink:href="#MJAMS-25A0">
Function < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.339ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 576.5 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-68"> 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:
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 < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.331ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 2725.7 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-28">< use x="389" y="0" xlink:href="#MJMAIN-30">< use x="890" y="0" xlink:href="#MJMAIN-2C">< g transform="translate(1335,0)">< use xlink:href="#MJMAIN-34">< use x="500" y="0" xlink:href="#MJMAIN-30">< use x="2336" y="0" xlink:href="#MJMAIN-29">. If we would extend support of the target density to further away from < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.162ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 500.5 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-30"> we would see increasing drop of sampler efficiency.
We can easily improve our sampling method by noticing the following inequality:
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="40.089ex" height="2.843ex" style="vertical-align: -0.838ex;" viewBox="0 -863.1 17260.4 1223.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-2200">< g transform="translate(556,-150)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.707)" x="361" y="0" xlink:href="#MJMAIN-3E">< use transform="scale(0.707)" x="1140" y="0" xlink:href="#MJMAIN-30">< use x="2316" y="0" xlink:href="#MJMATHI-70">< use x="2820" y="0" xlink:href="#MJMAIN-5B">< use x="3098" y="0" xlink:href="#MJMATHI-74">< use x="3460" y="0" xlink:href="#MJMAIN-7C">< use x="3738" y="0" xlink:href="#MJMATHI-62">< use x="4168" y="0" xlink:href="#MJMAIN-2C">< use x="4613" y="0" xlink:href="#MJMATHI-3B7">< use x="5116" y="0" xlink:href="#MJMAIN-5D">< use x="5672" y="0" xlink:href="#MJMAIN-2264">< use x="6729" y="0" xlink:href="#MJMAIN-28">< use x="7118" y="0" xlink:href="#MJMAIN-31">< use x="7841" y="0" xlink:href="#MJMAIN-2B">< use x="8842" y="0" xlink:href="#MJMATHI-3B7">< use x="9345" y="0" xlink:href="#MJMAIN-29">< use x="9735" y="0" xlink:href="#MJMATHI-62">< g transform="translate(10331,0)">< use xlink:href="#MJMAIN-65">< use x="444" y="0" xlink:href="#MJMAIN-78">< use x="973" y="0" xlink:href="#MJMAIN-70">< use x="11860" y="0" xlink:href="#MJMAIN-28">< use x="12250" y="0" xlink:href="#MJMAIN-2212">< use x="13028" y="0" xlink:href="#MJMATHI-62">< use x="13458" y="0" xlink:href="#MJMATHI-74">< use x="13819" y="0" xlink:href="#MJMAIN-29">< use x="14487" y="0" xlink:href="#MJMAIN-3D">< use x="15543" y="0" xlink:href="#MJMATHI-68">< use x="16119" y="0" xlink:href="#MJMAIN-28">< use x="16509" y="0" xlink:href="#MJMATHI-74">< use x="16870" y="0" xlink:href="#MJMAIN-29">
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:
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="54.112ex" height="3.343ex" style="vertical-align: -1.171ex;" viewBox="0 -934.9 23298.1 1439.2" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-68">< use transform="scale(0.707)" x="815" y="583" xlink:href="#MJMAIN-2032">< use x="871" y="0" xlink:href="#MJMAIN-28">< use x="1260" y="0" xlink:href="#MJMATHI-74">< use x="1622" y="0" xlink:href="#MJMAIN-29">< use x="2289" y="0" xlink:href="#MJMAIN-3D">< g transform="translate(3345,0)">< use x="0" y="0" xlink:href="#MJMAIN-31">< g transform="translate(500,-187)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-5B">< use transform="scale(0.707)" x="278" y="0" xlink:href="#MJMAIN-30">< use transform="scale(0.707)" x="779" y="0" xlink:href="#MJMAIN-2C">< g transform="translate(747,0)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="386" xlink:href="#MJMAIN-2217">< use transform="scale(0.707)" x="1925" y="0" xlink:href="#MJMAIN-5D">< use x="5726" y="0" xlink:href="#MJMAIN-2217">< use x="6449" y="0" xlink:href="#MJMATHI-6D">< use x="7328" y="0" xlink:href="#MJMAIN-28">< use x="7717" y="0" xlink:href="#MJMATHI-62">< use x="8147" y="0" xlink:href="#MJMAIN-2C">< use x="8592" y="0" xlink:href="#MJMATHI-3B7">< use x="9095" y="0" xlink:href="#MJMAIN-29">< use x="9707" y="0" xlink:href="#MJMAIN-2B">< g transform="translate(10708,0)">< use x="0" y="0" xlink:href="#MJMAIN-31">< g transform="translate(500,-187)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-28">< g transform="translate(275,0)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="386" xlink:href="#MJMAIN-2217">< use transform="scale(0.707)" x="1257" y="0" xlink:href="#MJMAIN-2C">< use transform="scale(0.707)" x="1535" y="0" xlink:href="#MJMAIN-2B">< use transform="scale(0.707)" x="2314" y="0" xlink:href="#MJMAIN-221E">< use transform="scale(0.707)" x="3314" y="0" xlink:href="#MJMAIN-29">< use x="14150" y="0" xlink:href="#MJMAIN-2217">< use x="14873" y="0" xlink:href="#MJMAIN-28">< use x="15262" y="0" xlink:href="#MJMAIN-31">< use x="15985" y="0" xlink:href="#MJMAIN-2B">< use x="16986" y="0" xlink:href="#MJMATHI-3B7">< use x="17489" y="0" xlink:href="#MJMAIN-29">< use x="18101" y="0" xlink:href="#MJMAIN-2217">< use x="18823" y="0" xlink:href="#MJMATHI-62">< g transform="translate(19420,0)">< use xlink:href="#MJMAIN-65">< use x="444" y="0" xlink:href="#MJMAIN-78">< use x="973" y="0" xlink:href="#MJMAIN-70">< use x="20949" y="0" xlink:href="#MJMAIN-28">< use x="21339" y="0" xlink:href="#MJMAIN-2212">< use x="22117" y="0" xlink:href="#MJMATHI-62">< use x="22547" y="0" xlink:href="#MJMATHI-74">< use x="22908" y="0" xlink:href="#MJMAIN-29">
where < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.894ex" height="2.176ex" style="vertical-align: -0.338ex;" viewBox="0 -791.3 815.4 936.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.707)" x="511" y="513" xlink:href="#MJMAIN-2217"> is a point where envelope function reaches maximum of shifted Gompertz density and < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.04ex" height="1.676ex" style="vertical-align: -0.338ex;" viewBox="0 -576.1 878.5 721.6" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-6D"> is a value of the density at this point.
Of course < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.024ex" height="2.343ex" style="vertical-align: -0.338ex;" viewBox="0 -863.1 871.3 1008.6" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-68">< use transform="scale(0.707)" x="815" y="513" xlink:href="#MJMAIN-2032"> is not a density itself. Since it is integrable we can recover density < svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.116ex" height="2.009ex" style="vertical-align: -0.671ex;" viewBox="0 -576.1 480.5 865.1" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-67"> as
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="47.032ex" height="7.009ex" style="vertical-align: -3.171ex;" viewBox="0 -1652.5 20250 3017.9" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMATHI-67">< use x="480" y="0" xlink:href="#MJMAIN-28">< use x="870" y="0" xlink:href="#MJMATHI-74">< use x="1231" y="0" xlink:href="#MJMAIN-7C">< use x="1510" y="0" xlink:href="#MJMATHI-62">< use x="1939" y="0" xlink:href="#MJMAIN-2C">< use x="2384" y="0" xlink:href="#MJMATHI-3B7">< use x="2888" y="0" xlink:href="#MJMAIN-29">< g transform="translate(3555,0)">< use xlink:href="#MJMAIN-3A">< use x="278" y="0" xlink:href="#MJMAIN-3D">< g transform="translate(4612,0)">< g transform="translate(397,0)">< rect stroke="none" width="450" x="0" y="220">< g transform="translate(1440,770)">< use x="0" y="0" xlink:href="#MJMATHI-68">< use transform="scale(0.707)" x="815" y="513" xlink:href="#MJMAIN-2032">< use x="871" y="0" xlink:href="#MJMAIN-28">< use x="1260" y="0" xlink:href="#MJMATHI-74">< use x="1622" y="0" xlink:href="#MJMAIN-7C">< use x="1900" y="0" xlink:href="#MJMATHI-62">< use x="2330" y="0" xlink:href="#MJMAIN-2C">< use x="2775" y="0" xlink:href="#MJMATHI-3B7">< use x="3278" y="0" xlink:href="#MJMAIN-29">< g transform="translate(60,-867)">< use x="0" y="0" xlink:href="#MJSZ1-222B">< use transform="scale(0.707)" x="921" y="754" xlink:href="#MJMAIN-221E">< use transform="scale(0.707)" x="668" y="-484" xlink:href="#MJMAIN-30">< g transform="translate(1626,0)">< use x="0" y="0" xlink:href="#MJMATHI-68">< use transform="scale(0.707)" x="815" y="408" xlink:href="#MJMAIN-2032">< use x="2497" y="0" xlink:href="#MJMAIN-28">< use x="2886" y="0" xlink:href="#MJMATHI-73">< use x="3356" y="0" xlink:href="#MJMAIN-7C">< use x="3634" y="0" xlink:href="#MJMATHI-62">< use x="4064" y="0" xlink:href="#MJMAIN-2C">< use x="4509" y="0" xlink:href="#MJMATHI-3B7">< use x="5013" y="0" xlink:href="#MJMAIN-29">< use x="5402" y="0" xlink:href="#MJMAIN-64">< use x="5959" y="0" xlink:href="#MJMATHI-73">< use x="11956" y="0" xlink:href="#MJMAIN-3D">< g transform="translate(12735,0)">< g transform="translate(397,0)">< rect stroke="none" width="450" x="0" y="220">< use x="1414" y="676" xlink:href="#MJMAIN-31">< g transform="translate(60,-771)">< use x="0" y="0" xlink:href="#MJMATHI-4D">< use x="1051" y="0" xlink:href="#MJMAIN-28">< use x="1441" y="0" xlink:href="#MJMATHI-62">< use x="1870" y="0" xlink:href="#MJMAIN-2C">< use x="2315" y="0" xlink:href="#MJMATHI-3B7">< use x="2819" y="0" xlink:href="#MJMAIN-29">< g transform="translate(16581,0)">< use x="0" y="0" xlink:href="#MJMATHI-68">< use transform="scale(0.707)" x="815" y="583" xlink:href="#MJMAIN-2032">< use x="17452" y="0" xlink:href="#MJMAIN-28">< use x="17842" y="0" xlink:href="#MJMATHI-74">< use x="18203" y="0" xlink:href="#MJMAIN-7C">< use x="18482" y="0" xlink:href="#MJMATHI-62">< use x="18911" y="0" xlink:href="#MJMAIN-2C">< use x="19356" y="0" xlink:href="#MJMATHI-3B7">< use x="19860" y="0" xlink:href="#MJMAIN-29">
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="59.793ex" height="6.009ex" style="vertical-align: -2.671ex;" viewBox="0 -1437.2 25744.2 2587.3" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-3D">< g transform="translate(778,0)">< g transform="translate(397,0)">< rect stroke="none" width="450" x="0" y="220">< use x="1414" y="676" xlink:href="#MJMAIN-31">< g transform="translate(60,-771)">< use x="0" y="0" xlink:href="#MJMATHI-4D">< use x="1051" y="0" xlink:href="#MJMAIN-28">< use x="1441" y="0" xlink:href="#MJMATHI-62">< use x="1870" y="0" xlink:href="#MJMAIN-2C">< use x="2315" y="0" xlink:href="#MJMATHI-3B7">< use x="2819" y="0" xlink:href="#MJMAIN-29">< g transform="translate(4624,0)">< use x="0" y="-1" xlink:href="#MJSZ1-7B">< g transform="translate(583,0)">< use x="0" y="0" xlink:href="#MJMAIN-31">< g transform="translate(500,-187)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-5B">< use transform="scale(0.707)" x="278" y="0" xlink:href="#MJMAIN-30">< use transform="scale(0.707)" x="779" y="0" xlink:href="#MJMAIN-2C">< g transform="translate(747,0)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="386" xlink:href="#MJMAIN-2217">< use transform="scale(0.707)" x="1925" y="0" xlink:href="#MJMAIN-5D">< use x="2381" y="0" xlink:href="#MJMAIN-2217">< use x="3103" y="0" xlink:href="#MJMATHI-6D">< use x="3982" y="0" xlink:href="#MJMAIN-28">< use x="4371" y="0" xlink:href="#MJMATHI-62">< use x="4801" y="0" xlink:href="#MJMAIN-2C">< use x="5246" y="0" xlink:href="#MJMATHI-3B7">< use x="5749" y="0" xlink:href="#MJMAIN-29">< use x="6361" y="0" xlink:href="#MJMAIN-2B">< g transform="translate(7362,0)">< use x="0" y="0" xlink:href="#MJMAIN-31">< g transform="translate(500,-187)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-28">< g transform="translate(275,0)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="386" xlink:href="#MJMAIN-2217">< use transform="scale(0.707)" x="1257" y="0" xlink:href="#MJMAIN-2C">< use transform="scale(0.707)" x="1535" y="0" xlink:href="#MJMAIN-2B">< use transform="scale(0.707)" x="2314" y="0" xlink:href="#MJMAIN-221E">< use transform="scale(0.707)" x="3314" y="0" xlink:href="#MJMAIN-29">< use x="10804" y="0" xlink:href="#MJMAIN-2217">< use x="11527" y="0" xlink:href="#MJMAIN-28">< use x="11916" y="0" xlink:href="#MJMAIN-31">< use x="12639" y="0" xlink:href="#MJMAIN-2B">< use x="13640" y="0" xlink:href="#MJMATHI-3B7">< use x="14143" y="0" xlink:href="#MJMAIN-29">< use x="14755" y="0" xlink:href="#MJMAIN-2217">< use x="15478" y="0" xlink:href="#MJMATHI-62">< g transform="translate(16074,0)">< use xlink:href="#MJMAIN-65">< use x="444" y="0" xlink:href="#MJMAIN-78">< use x="973" y="0" xlink:href="#MJMAIN-70">< use x="17603" y="0" xlink:href="#MJMAIN-28">< use x="17993" y="0" xlink:href="#MJMAIN-2212">< use x="18771" y="0" xlink:href="#MJMATHI-62">< use x="19201" y="0" xlink:href="#MJMATHI-74">< use x="19562" y="0" xlink:href="#MJMAIN-29">< use x="20535" y="-1" xlink:href="#MJSZ1-7D">
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="71.215ex" height="6.843ex" style="vertical-align: -2.671ex;" viewBox="0 -1796 30661.8 2946.1" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-3D">< g transform="translate(778,0)">< g transform="translate(397,0)">< rect stroke="none" width="450" x="0" y="220">< g transform="translate(60,770)">< use x="0" y="0" xlink:href="#MJMATHI-6D">< use x="878" y="0" xlink:href="#MJMAIN-28">< use x="1268" y="0" xlink:href="#MJMATHI-62">< use x="1697" y="0" xlink:href="#MJMAIN-2C">< use x="2142" y="0" xlink:href="#MJMATHI-3B7">< use x="2646" y="0" xlink:href="#MJMAIN-29">< g transform="translate(3035,0)">< use x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.707)" x="511" y="513" xlink:href="#MJMAIN-2217">< g transform="translate(381,-771)">< use x="0" y="0" xlink:href="#MJMATHI-4D">< use x="1051" y="0" xlink:href="#MJMAIN-28">< use x="1441" y="0" xlink:href="#MJMATHI-62">< use x="1870" y="0" xlink:href="#MJMAIN-2C">< use x="2315" y="0" xlink:href="#MJMATHI-3B7">< use x="2819" y="0" xlink:href="#MJMAIN-29">< use x="5489" y="0" xlink:href="#MJMAIN-2217">< g transform="translate(5990,0)">< g transform="translate(342,0)">< rect stroke="none" width="450" x="0" y="220">< use x="217" y="676" xlink:href="#MJMAIN-31">< g transform="translate(60,-686)">< use x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.707)" x="511" y="408" xlink:href="#MJMAIN-2217">< g transform="translate(7387,0)">< use x="0" y="0" xlink:href="#MJMAIN-31">< g transform="translate(500,-187)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-5B">< use transform="scale(0.707)" x="278" y="0" xlink:href="#MJMAIN-30">< use transform="scale(0.707)" x="779" y="0" xlink:href="#MJMAIN-2C">< g transform="translate(747,0)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="386" xlink:href="#MJMAIN-2217">< use transform="scale(0.707)" x="1925" y="0" xlink:href="#MJMAIN-5D">< use x="9768" y="0" xlink:href="#MJMAIN-2B">< g transform="translate(10547,0)">< g transform="translate(342,0)">< rect stroke="none" width="450" x="0" y="220">< g transform="translate(60,770)">< use x="0" y="0" xlink:href="#MJMATHI-6D">< use x="878" y="0" xlink:href="#MJMAIN-28">< use x="1268" y="0" xlink:href="#MJMATHI-62">< use x="1697" y="0" xlink:href="#MJMAIN-2C">< use x="2142" y="0" xlink:href="#MJMATHI-3B7">< use x="2646" y="0" xlink:href="#MJMAIN-29">< g transform="translate(3035,0)">< use x="0" y="0" xlink:href="#MJMATHI-65">< g transform="translate(466,362)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-2212">< use transform="scale(0.707)" x="778" y="0" xlink:href="#MJMATHI-62">< g transform="translate(854,0)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="446" xlink:href="#MJMAIN-2217">< use x="5070" y="0" xlink:href="#MJMAIN-28">< use x="5459" y="0" xlink:href="#MJMAIN-31">< use x="6182" y="0" xlink:href="#MJMAIN-2B">< use x="7182" y="0" xlink:href="#MJMATHI-3B7">< use x="7686" y="0" xlink:href="#MJMAIN-29">< g transform="translate(2493,-771)">< use x="0" y="0" xlink:href="#MJMATHI-4D">< use x="1051" y="0" xlink:href="#MJMAIN-28">< use x="1441" y="0" xlink:href="#MJMATHI-62">< use x="1870" y="0" xlink:href="#MJMAIN-2C">< use x="2315" y="0" xlink:href="#MJMATHI-3B7">< use x="2819" y="0" xlink:href="#MJMAIN-29">< use x="19427" y="0" xlink:href="#MJMAIN-2217">< g transform="translate(20150,0)">< use x="0" y="0" xlink:href="#MJMAIN-31">< g transform="translate(500,-187)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMAIN-28">< g transform="translate(275,0)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="386" xlink:href="#MJMAIN-2217">< use transform="scale(0.707)" x="1257" y="0" xlink:href="#MJMAIN-2C">< use transform="scale(0.707)" x="1535" y="0" xlink:href="#MJMAIN-2B">< use transform="scale(0.707)" x="2314" y="0" xlink:href="#MJMAIN-221E">< use transform="scale(0.707)" x="3314" y="0" xlink:href="#MJMAIN-29">< use x="23370" y="0" xlink:href="#MJMATHI-62">< g transform="translate(23966,0)">< use xlink:href="#MJMAIN-65">< use x="444" y="0" xlink:href="#MJMAIN-78">< use x="973" y="0" xlink:href="#MJMAIN-70">< use x="25495" y="0" xlink:href="#MJMAIN-28">< use x="25885" y="0" xlink:href="#MJMAIN-2212">< use x="26663" y="0" xlink:href="#MJMATHI-62">< use x="27093" y="0" xlink:href="#MJMAIN-28">< use x="27482" y="0" xlink:href="#MJMATHI-74">< use x="28066" y="0" xlink:href="#MJMAIN-2212">< g transform="translate(29067,0)">< use x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.707)" x="511" y="583" xlink:href="#MJMAIN-2217">< use x="29882" y="0" xlink:href="#MJMAIN-29">< use x="30272" y="0" xlink:href="#MJMAIN-29">
< svg xmlns:xlink="http://www.w3.org/1999/xlink" width="40.645ex" height="3.176ex" style="vertical-align: -1.005ex;" viewBox="0 -934.9 17499.8 1367.4" role="img" focusable="false">< g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">< use x="0" y="0" xlink:href="#MJMAIN-3D">< g transform="translate(1056,0)">< use x="0" y="0" xlink:href="#MJMATHI-70">< use transform="scale(0.707)" x="712" y="-213" xlink:href="#MJMAIN-31">< use x="2013" y="0" xlink:href="#MJMAIN-28">< use x="2403" y="0" xlink:href="#MJMATHI-62">< use x="2832" y="0" xlink:href="#MJMAIN-2C">< use x="3277" y="0" xlink:href="#MJMATHI-3B7">< use x="3781" y="0" xlink:href="#MJMAIN-29">< use x="4393" y="0" xlink:href="#MJMAIN-2217">< use x="5115" y="0" xlink:href="#MJAMS-55">< use x="5838" y="0" xlink:href="#MJMAIN-5B">< use x="6116" y="0" xlink:href="#MJMAIN-30">< use x="6617" y="0" xlink:href="#MJMAIN-2C">< g transform="translate(7062,0)">< use x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.707)" x="511" y="583" xlink:href="#MJMAIN-2217">< use x="7877" y="0" xlink:href="#MJMAIN-5D">< use x="8378" y="0" xlink:href="#MJMAIN-2B">< g transform="translate(9379,0)">< use x="0" y="0" xlink:href="#MJMATHI-70">< use transform="scale(0.707)" x="712" y="-213" xlink:href="#MJMAIN-32">< use x="10336" y="0" xlink:href="#MJMAIN-28">< use x="10726" y="0" xlink:href="#MJMATHI-62">< use x="11155" y="0" xlink:href="#MJMAIN-2C">< use x="11600" y="0" xlink:href="#MJMATHI-3B7">< use x="12104" y="0" xlink:href="#MJMAIN-29">< use x="12716" y="0" xlink:href="#MJMAIN-2217">< g transform="translate(13438,0)">< use x="0" y="0" xlink:href="#MJMAIN-45">< use x="681" y="0" xlink:href="#MJMAIN-78">< use x="1210" y="0" xlink:href="#MJMAIN-70">< use x="15205" y="0" xlink:href="#MJMAIN-28">< use x="15594" y="0" xlink:href="#MJMATHI-62">< use x="16024" y="0" xlink:href="#MJMAIN-29">< g transform="translate(16413,0)">< use x="0" y="0" xlink:href="#MJMAIN-7C">< use transform="scale(0.707)" x="393" y="675" xlink:href="#MJMAIN-221E">< g transform="translate(278,-286)">< use transform="scale(0.707)" x="0" y="0" xlink:href="#MJMATHI-74">< use transform="scale(0.574)" x="445" y="386" xlink:href="#MJMAIN-2217">
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
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:
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.