2

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?

Community
  • 1
  • 1
Til Hund
  • 1,543
  • 5
  • 21
  • 37

1 Answers1

4

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

JenB
  • 17,620
  • 2
  • 17
  • 45
  • looks like there's no maths markdown on stackexchange! – JenB Feb 04 '15 at 14:11
  • Thank you very much, JenB. Now I understand better how to "transliterate" a formula into NetLogo. – Til Hund Feb 04 '15 at 21:55
  • is there a way to have a max value for this formula, like `random` netlogo command has? – David Lojudice Sb. Dec 28 '17 at 18:12
  • If you want to have a truncated distribution, use a while loop and keep generating a random value until it falls within the limits you want. If this is not enough explanation, please ask a separate question (which is what you really should do anyway). – JenB Dec 29 '17 at 11:23