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.
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}\]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:
to-report weibull [a_scale a_shape x]
let Wei (a_shape / a_scale ) * ((x / a_scale)^(a_shape - 1)) * exp( - ((x / a_scale)^ a_shape))
report Wei
end
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}\]Again, fully implemented in R already:
scale <- 3
shape <- 1
x <- 5
pweibull(q = x, scale = scale, shape = shape)
[1] 0.8111244
In NetLogo we can simply translate the mathematical equation into a function:
to-report weibull_cumulative [a_scale a_shape x]
let Wei_cumu 1 - exp( - ((x / a_scale)^ a_shape))
report Wei_cumu
end
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} }