Turning Equations into Functions in NetLogo

NetLogo rstats distributions

While some programming languages, such as R, offer many native functions, others (e.g., NetLogo) offer fewer built-in options. However, users can create their own functions easily. Here, we will show the example of a Weibull density distribution function & associated cumulative density distribution function—both not yet implemented in NetLogo or NetLogo extensions.

Marius Grabow (IZW Berlin)https://ecodynizw.github.io/
11/11/2022

Density distribution function

Let’s first take a look at the Weibull density distribution function:

\[\begin{equation} f(x) = \frac{\gamma} {\alpha} (\frac{x-\mu} {\alpha})^{(\gamma - 1)}\exp{(-((x-\mu)/\alpha)^{\gamma})} \hspace{.3in} x \ge \mu; \gamma, \alpha > 0 \end{equation}\]

R

In R, this is already implemented:

scale <- 3
shape <- 1

dweibull(scale, shape = shape)
[1] 0.04978707

In Netlogo we can simply translate the mathematical equation into a function:

Cumulative density function

Let’s also take a look at the Weibull cumulative density function:

\[\begin{equation} F(x) = 1 - e^{-(x^{\gamma})} \hspace{.3in} x \ge 0; \gamma > 0 \end{equation}\]

R

Again, fully implemented in R already:

scale <- 3
shape <- 1
x <- 5

pweibull(q = x, scale = scale, shape = shape)
[1] 0.8111244

NetLogo

In NetLogo we can simply translate the mathematical equation into a function:

Citation

For attribution, please cite this work as

Grabow (2022, Nov. 11). Ecological Dynamics: Turning Equations into Functions in NetLogo. Retrieved from https://ecodynizw.github.io/posts/netlogo-weibull/

BibTeX citation

@misc{grabow2022turning,
  author = {Grabow, Marius},
  title = {Ecological Dynamics: Turning Equations into Functions in NetLogo},
  url = {https://ecodynizw.github.io/posts/netlogo-weibull/},
  year = {2022}
}