Search code examples
netlogoprng

How to create a "random-pareto" in NetLogo?


Since I am not well-versed in mathematics, I am struggling with the implementation of a random number generator in NetLogo which follows roughly a pareto distribution. This is the follow-up question of this one here, where I would like to substitue the random-float with something like "random-pareto" in order to have events taking place in the model following a pareto distribution (thinking of simulated earthquakes and their degree of destructiveness).

The code in question is:

  ask hits [
     let %draw (random-float 100)
     let %strength 0  ;; no damage
     if (%draw < 50) [set %strength (%strength + 1)]  ;;1 for little damage
     if (%draw < 10) [set %strength (%strength + 1)]  ;;2 for middle damage
     if (%draw < 5) [set %strength (%strength + 1)]  ;;3 for strong damage
     if (%draw < 1) [set %strength (%strength + 1)]  ;;4 for complete destruction

     ifelse pcolor = red [die]
     [ ask n-of %strength patches [ set pcolor red ]]
   ]

I got inspired by this question here to do the same in R and the Netlogo Dictionary here about the fact that random-exponential can be written as (- mean) * ln random-float 1.0.

Can somebody help?


Solution

  • What you need is the equation to convert from a uniform distribution (random-float) to the distribution you want. This might be a better question for the stackexchange stats. However, according to Wikipedia, the formula is:

    $$ T = \frac{m}{U^\frac{1}{\alpha}} $$

    where $U$ is the uniform input, $T$ is the Pareto distributed random number, $m$ (minimum) and $\alpha$ are parameters of the distribution. If this is correct, you could code in NetLogo as

    to-report random-pareto [alpha mm]
      report mm / ( random-float 1 ^ (1 / alpha) )
    end
    

    Say you wanted a random Pareto from the distribution with minimum of 1 and alpha of 3, you could then get one with the code random-pareto 3 1