NLMR and landscapetools: An integrated environment for simulating and modifying neutral landscape models in R
rOpenSci Resources:
The software package NLMR and landscapetools developed as part of this research effort, was extensively reviewed and approved by the rOpenSci project (https://ropensci.org). A full record of the review is available at Link to package on rOpenSci: https://github.com/ropensci/NLMR and https://github.com/ropensci/landscapetools
Abstract
- Neutral landscape models (NLMs) simulate landscape patterns based on theoretical distributions and can be used to systematically study the effect of landscape structure on ecological processes. NLMs are commonly used in landscape ecology to enhance the findings of field studies as well as in simulation studies to provide an underlying landscape. However, their creation so far has been limited to software that is platform dependent, does not allow a reproducible workflow or is not embedded in R, the prevailing programming language used by ecologists.
- Here, we present two complementary R packages NLMR and landscapetools, that allow users to generate and manipulate NLMs in a single environment. They grant the simulation of the widest collection of NLMs found in any single piece of software thus far while allowing for easy manipulation in a self‐contained and reproducible workflow. The combination of both packages should stimulate a wider usage of NLMs in ecology. NLMR is a comprehensive collection of algorithms with which to simulate NLMs. landscapetools provides a utility toolbox which facilitates an easy workflow with simulated neutral landscapes and other raster data.
- We show two example applications that illustrate potential use cases for NLMR and landscapetools: First, an agent‐based simulation study in which the effect of spatial structure on disease persistence was studied. The second example shows how increases in spatial scaling can introduce biases in calculated landscape metrics.
- Simplifying the workflow around generating and handling NLMs should encourage an uptake in the usage of NLMs. NLMR and landscapetools are both generic frameworks that can be used in a variety of applications and are a further step to having a unified simulation environment in R for answering spatial research questions.
1 INTRODUCTION
Neutral landscape models (NLMs) are algorithms which generate landscape patterns in the absence of biotic and abiotic processes (Caswell, 1976; Gardner, Milne, Turnei, & O’Neill, 1987; Li et al., 2004). These models were originally developed as null models to test landscape‐scale hypotheses (Gardner & Urban, 2007; With & King, 1997). NLMs are now used in a variety of ways to examine landscape‐scale observations and metrics of ecological patterns and processes (With & King, 1997; Turner, Gardner, & O’Neill, 2001). With and King (1997) outlined three uses for NLMs which were further highlighted by Turner and Gardner (2015): (a) coupling ecological models with NLMs to predict changes in ecological processes, (b) analyse the extent of structural deviation between real and neutral landscapes, and (c) development and testing of novel landscape metrics. The large number of applications and their increased uptake has led to the development of a variety of software designed to generate NLMs, using a range of algorithms. Options include standalone software such as RULE (Gardner, 1999), its successor QRULE (Gardner & Urban, 2007) and SIMMAP (Saura & Martínez‐Millán, 2000), as well as LG (van Strien, Slager, de Vries, & Grêt‐Regamey, 2016). However, arguably the most useful pieces of software are those that offer a collection of different NLM algorithms based in an open‐source programming language which allow for reproducible and consistent workflow. Packages developed for common programming languages, such as NLMpy (Etherington, Holland, & O’Sullivan, 2015) for PYTHON, fulfill these criteria. However, currently there is no NLM software package available for R, the programming language most widely used by ecologists (R Core Team, 2017). Examining 150 recent articles in Methods in Ecology and Evolution, we found a clear trend in the community towards R with 106 publications utilising R (see Supporting Information, Figure S1). The lack of a flexible framework in R may limit the overall use of NLMs. We have, therefore, developed two complementary R packages, NLMR and landscapetools, to allow for the easy simulation and manipulation of NLMs and other rasters. These packages are the first to provide a large range of NLM algorithms, along with tools to manipulate them, embedded in a reproducible framework in the R environment. This utility allows for the easier generation and handling of NLMs, while also allowing for these simulations to be tied into the extensive body of geospatial libraries native to R.
Both packages will allow a growing group of scientific R users to make use of NLMs in their research while permitting a streamlined workflow contained in the R environment. Furthermore, the integration of major geographical information system libraries (such as GDAL and GEOS) in R embed our packages in a framework that allows analyses and simulations to be done in R without relying on proprietary software.
2 FUNCTIONALITY
NLMR and landscapetools both build on the established geospatial environments in R, e.g. the raster (Hijmans, 2017) and sf packages (Pebesma, 2018). The nomenclature of all our functions was designed to facilitate a reproducible workflow while being distinct from the naming conventions of other geospatial packages, thus avoiding namespace conflicts with other functions and packages.
2.1 NLMR
The NLMR package is a generic numeric framework to generate NLMs using the widest collection of algorithms found in any single piece of software, while also enabling different NLM algorithms to be combined and integrated. Functions in NLMR (Table 1) simulate two‐dimensional raster objects. By default, no spatial reference system is applied but can be incorporated, allowing NLMs to be projected to the spatial extent of any study area. Algorithms differ from each other in terms of how spatial autocorrelation is controlled. Some algorithms have no control over spatial autocorrelation ranging from no autocorrelation (i.e. random) to a constant gradient (i.e. planar gradients). Other algorithms allow the user to control the level of spatial autocorrelation through one (nlm_mpd) or many (nlm_gaussian) parameters (Figure 1).
| Function | Model specification | Cross‐reference | Reference |
|---|---|---|---|
| nlm_curds | Simulates a randomly curdled or wheyed neutral landscape model. Random curdling recursively subdivides the landscape into blocks. At each level of the recursion, a fraction of these blocks is declared as habitat while the remaining stays matrix. When option q is set, it simulates a wheyed curdling model, where previously selected cells that were declared matrix during recursion, can now contain a proportion of habitat cells | Figure 1a,p | O’Neill, Gardner, and Turner (1992); Keitt (2000) |
| nlm_distance gradient | Simulates a distance gradient neutral landscape model. The gradient is always measured from a rectangle that one has to specify in the function (parameter origin) | Figure 1b | Etherington et al. (2015) |
| nlm_edge gradient | Simulates a linear gradient orientated neutral model. The gradient has a specified or random direction that has a central peak, which runs perpendicular to the gradient direction | Figure 1c | Travis and Dytham (2004) |
| nlm_fbm | Simulates neutral landscapes using fractional Brownian motion (fBm). fBm is an extension of Brownian motion in which the amount of spatial autocorrelation between steps is controlled by the Hurst coefficient H | Figure 1d | Travis and Dytham (2004); Schlather et al. (2015) |
| nlm_gaussian field | Simulates a spatially correlated random fields (Gaussian random fields) model, where one can control the distance and magnitude of spatial autocorrelation | Figure 1e | Schlather et al. (2015) |
| nlm_mosaic field | Simulates a mosaic random field neutral landscape model. The algorithm imitates fault lines by repeatedly bisecting the landscape and lowering the values of cells in one half and increasing the values in the other half. If one sets the parameter infinit to TRUE, the algorithm approaches a fractal pattern | Figure 1f | Schlather et al. (2015) |
| nlm_neigh | Simulates a neutral landscape model with land cover classes and clustering based on neighbourhood characteristics. The cluster are based on the surrounding cells. If there is a neighbouring cell of the current value/type, the target cell will more likely turned into a cell of that type/value | Figure 1g | Schlather et al. (2015) |
| nlm_percolation | Simulates a binary neutral landscape model based on percolation theory. The probability for a cell to be assigned habitat is drawn from a uniform distribution | Figure 1h | Gardner, O’Neill, Turner, and Dale (1989) |
| nlm_planar gradient | Simulates a planar gradient neutral landscape model. The gradient is sloping in a specified or (by default) random direction between 0 and 360 degree | Figure 1i | Palmer (1992) |
| nlm_mosaictess | Simulates a patchy mosaic neutral landscape model based on the tessellation of a random point process. The algorithm randomly places points (parameter germs) in the landscape, which are used as the centroid points for a voronoi tessellation. A higher number of points therefore leads to a more fragmented landscape | Figure 1k | Gaucherel (2008), Method 1 |
| nlm_mosaic gibbs | Simulates a patchy mosaic neutral landscape model based on the tessellation of an inhibition point process. This inhibition point process starts with a given number of points and uses a minimisation approach to fit a point pattern with a given interaction parameter (0 ‐ hardcore process; 1 ‐ Poisson process) and interaction radius (distance of points/germs being apart) | Figure 1j | Gaucherel (2008), Method 2 |
| nlm_random | Simulates a spatially random neutral landscape model. The values are drawn a uniform distribution | Figure 1l | With and Crist (1995) |
| nlm_random cluster | Simulates a random cluster nearest‐neighbour neutral landscape. The parameter ai controls for the number and abundance of land cover classes and p controls for proportion of elements randomly selected to form clusters | Figure 1m | Saura and Martínez‐Millán (2000) |
| nlm_mpd | Simulates a midpoint displacement neutral landscape model where the parameter roughness controls the level of spatial autocorrelation | Figure 1n | Peitgen and Saupe (1988) |
| nlm_random rectangular cluster | Simulates a random rectangular cluster neutral landscape model. The algorithm randomly distributes overlapping rectangles until the landscape is filled | Figure 1o | Gustafson and Parker (1992) |

The basic syntax used to simulate an NLM is as follows:
nlm_modeltype(ncol, nrow, resolution, ...)
Raster objects returned from NLMR can readily be transformed and visualised by landscapetools or incorporated into spatially‐explicit analyses or simulations.
2.2 landscapetools
The package landscapetools contains a set of utility functions to complete tasks involved in most landscape manipulations and presentation (Figure 2). This includes visualisation, (re‐)classification and merging methods, thus providing a workflow to apply NLM algorithms in a broad range of different contexts. All functions in landscapetools require raster objects as inputs.

The functions util_classify and util_binarise (re‐)classify raster data into proportions based upon given weightings. util_classify allows users to factorially encode (classify) landscape data in raster objects, for example, to label different land‐use types. util_binarise returns landscapes with a binary representation of a raster, e.g. matrix/habitat distributions. As simulation experiments often rely on multiple proportions of matrix and habitat, it is possible to define multiple breaks and compute a collection (RasterStack) of binarised landscapes simultaneously. The function util_merge merges a weighted combination of multiple rasters allowing for even more sophisticated landscape patterns. The merging of NLMs, such as planar gradients with less autocorrelated landscapes, provides an established method for deriving ecotones (Etherington et al., 2015; Travis & Dytham, 2004). util_rescale is used internally in all algorithms implemented in NLMR, but is a public function in landscapetools to linearly rescale raster cell data into a range between zero and one.
landscapetools offers functions and themes for the visual communication of spatial data as ggplot2 objects (Wickham, 2009). The visualisation focuses on achieving outputs that can be used in publications, consequently applying one of the colourblind friendly colour scales (which can be changed with the scales parameter in the plot and theme functions) from the viridis package (Garnier, 2018) and typographic elements that support a reproducible workflow. Auxiliary functions in landscapetools help to coerce raster data in tibbles (Müller & Wickham, 2018), the new standard for rectangular data in R, and vice versa.
3 EXAMPLE APPLICATIONS
This section describes two example applications of NLMR and landscapetools (code available in Data accessibility): (i) disease persistence in heterogeneous landscapes and (ii) effects of changing resolution on landscape metrics under different landscape patterns.
3.1 Case study 1: Disease persistence in heterogeneous landscapes
Simulation models often assume underlying landscapes to be homogeneous or simply suitable habitat distributed in an unsuitable matrix. Given the comprehensive collection of NLMs with differing distribution patterns provided by NLMR, we were able to test the effect of homogeneous versus heterogeneous landscapes on ecological dynamics. We demonstrate the effect of spatial heterogeneity on the dynamics of a directly transmitted disease, Classical Swine Fever, infecting a wild boar population. We used a modified version of an existing agent‐ and grid‐based simulation model (Kramer‐Schadt, Fernández, Eisinger, Grimm, & Thulke, 2009; Lange, Kramer–Schadt & Thulke, 2012) with an SIR epidemiological classification (susceptible, infected, recovered). Susceptibility and disease‐induced mortality differed between age classes and the processes were simulated stochastically for each individual. Transmission between individuals was calculated based on the health status of individuals in the same and adjacent cells.
Heterogeneous landscapes (50 × 25 cells) were simulated using the nlm_mosaictess() function with two levels of fragmentation (low with germs = 25 and high with germs = 250). Total carrying capacities were equal for all simulated landscapes. Patchy, fragmented mosaic NLMs were selected to represent typically fragmented landscape structures in which the boars were located. The algorithm used to create those landscapes allowed to control for different levels of fragmentation in terms of overall number of patches (germs). landscapetools allowed for the classification of the generated landscapes into ecologically reasonable breeding capacities per cell (0 to 9 breeding females per home range with a mean of 4.5, resulting in a density of c. 5 wild boars per km2; (EFSA Panel on Animal Health and Welfare, 2009; Spitz, 1986)) and analysis of our results, all within the R environment. Our results show that disease outcomes were less variable in homogeneous setups compared to heterogeneous, fragmented landscapes (Figure 3). On the one hand, the reason for the differences in invasion success is plausibly the initial conditions the pathogen faces with a lower number of susceptible individuals in some heterogeneous landscapes compared to homogeneous ones (critical invasion threshold, Keeling & Rohani, 2008). The longer outbreak duration on the other hand is most likely the result of the presence of high density patches of hosts and the asynchronous dynamics between patches of different densities leading to recurrent infections (Bolker & Grenfell, 1995; Hess, 1996). Our simulation results underline that the assumption of a well‐mixed population in epidemiological models might overestimate the real invasion success while underestimating the possible number of infections within a population (Riley, Eames, Isham, Mollison, & Trapman, 2015).

3.2 Case study 2: effects of changing resolution on landscape metrics under different landscape patterns
Altering the resolution of maps (scaling up) can result in a systematic bias of metrics describing any contained spatial patterns (Wu, Shen, Sun, & Tueller, 2002). We utilised NLMRs’ functionality to generate differing neutral landscapes as a base for investigating this phenomenon. Initially, we started with landscapes similar to the ones used by Bocedi, Pe’er, Heikkinen, Matsinos, and Travis (2012); these landscapes were essentially discrete fractal landscapes with a varying amount of habitat cells and multiple degrees of spatial autocorrelation. To highlight several possible scaling outcomes we implemented two different aggregation methods.
First, we produced multiple landscapes (70 landscapes per parameter combination, each with 1,024 × 1,024 cells) with low to high fragmentation grade (roughness = 0.1, 0.5, 0.9) by using NLMR's midpoint displacement algorithm (nlm_mpd()). Afterwards, we discretised the desired amount of habitat cells (p = 0.1, 0.3, 0.5, 0.7) with landscapetools’ classification algorithm (util_classify()). Second, we used (aggregate()) from the raster package with a simple averaging (fun = mean) and majority rule (fun = modal) as aggregation methods to scale up the landscape (Figure 4).

Third, we calculated the desired landscape metric p (proportion of suitable cells; in the case of average rule cells that contain at least some suitable habitat) for each scaling step and visualised possible biases (Figure 5).

This example demonstrates over‐ and underestimation of the targeted metric which could occur due to scaling methods, depending on the initial landscape. These results confirm that scaling up is most problematic in highly fragmented landscapes. However, this bias drops significantly in specific variable combinations (e.g. p = 0.5, roughness = 0.9, majority rule). Additionally, it is not always clear if a metric is overestimated or underestimated as it can change with differing combinations of scaling method and parameter choice (see majority rule).
4 CONCLUSION AND OUTLOOK
NLMR is the first software to allow the simulation of NLMs within the self‐contained, reproducible framework of R. It can be applied in all landscape analyses in which one wants to test the influence of NLMs on ecological dynamics. Although existing tools are capable of simulating some of the NLMs contained in NLMR (Gardner, 1999; Gardner & Urban, 2007; Saura & Martínez‐Millán, 2000; van Strien et al., 2016; Etherington et al., 2015), none of them combine as many different types and none are as well integrated in a native geospatial workflow. Hence, the majority of the limitations that previous NLM software exhibit, such as developing own methods for spatial operations like masking and extracting, are overcome. The functions in landscapetools provide a variety of established methods to handle raster data, and allow for NLMs to easily be analysed with current R packages and tools. We believe that our functions are complementary to packages like rasterVis (Perpiñán & Hijmans, 2018), which enhance the visualisation of landscape patterns allowing for clearer communication of landscape research.
NLMR and landscapetools are both designed to simplify the workflow of landscape analyses. Thus, it is extensively documented and the implementation of each simulation model was based on published literature. Every function provides examples in its respective help file. A vignette in NLMR combines the information about the functions and the examples into an introduction of a basic workflow for using NLMs. Future extensions of NLMR and landscapetools aim to include all established algorithms that have been used to create NLMs and accompanying utility functions.
We believe that being capable of simulating NLMs natively in R is highly beneficial for the field of landscape ecology. NLMR and landscapetools have been officially released on CRAN (current versions 0.3.0) and peer‐reviewed by rOpenSci (https://github.com/ropensci/onboarding/issues/188).
ACKNOWLEDGEMENTS
M.S. was supported by the German Research Foundation (DFG) through grant number WI 1816/18‐1 (FOR2432) and DFG‐GRK 1644/3. M.F. was supported by the DFG through grant number DFG‐GRK 1644/2. C.S. was supported by the DFG through grant number DFG‐GRK 2118/1. We thank Kerstin Wiegand and two anonymous reviewers for their help in improving the manuscript, as well as rOpenSci for their extensive code review.
AUTHORS’ CONTRIBUTIONS
M.S. and C.E.S. conceived of the original package concept. M.S. led code development, and all other coauthors were co‐developers. M.S. drafted the manuscript, with case studies analysed and drafted by C.S. and M.F. All co‐authors contributed critically to the drafts and gave final approval for publication.
DATA ACCESSIBILITY
The NLMR and landscapetools packages and documentation are hosted at https://github.com/ropensci/NLMR as well as at https://github.com/ropensci/landscapetools. Reproducible scripts for the figures and case studies are available from https://zenodo.org/record/1298646.
REFERENCES
Citing Literature
Number of times cited according to CrossRef: 12
- Cédric Scherer, Viktoriia Radchuk, Mathias Franz, Hans‐Hermann Thulke, Martin Lange, Volker Grimm, Stephanie Kramer‐Schadt, Moving infections: individual movement decisions drive disease persistence in spatially structured landscapes, Oikos, 10.1111/oik.07002, 129, 5, (651-667), (2020).
- Caitlin D. Kuempel, Melanie Frazier, Kirsty L. Nash, Nis Sand Jacobsen, David R. Williams, Julia L. Blanchard, Richard S. Cottrell, Peter B. McIntyre, Daniel Moran, Lex Bouwman, Halley E. Froehlich, Jessica A. Gephart, Marc Metian, Johannes Többen, Benjamin S. Halpern, Integrating Life Cycle and Impact Assessments to Map Food's Cumulative Environmental Footprint, One Earth, 10.1016/j.oneear.2020.06.014, 3, 1, (65-78), (2020).
- Matthias Fritsch, Heike Lischke, Katrin M. Meyer, Scaling methods in ecological modelling, Methods in Ecology and Evolution, 10.1111/2041-210X.13466, 0, 0, (2020).
- Neil A. Gilbert, John D. J. Clare, Jennifer L. Stenglein, Benjamin Zuckerberg, Abundance estimation of unmarked animals based on camera‐trap data, Conservation Biology, 10.1111/cobi.13517, 0, 0, (2020).
- Thomas Etherington, O. Omondiagbe, virtualNicheR: generating virtual fundamental and realised niches for use in virtual ecology experiments, Journal of Open Source Software, 10.21105/joss.01661, 4, 41, (1661), (2019).
- Maria Langhammer, Jule Thober, Martin Lange, Karin Frank, Volker Grimm, Agricultural landscape generators for simulation models: A review of existing solutions and an outline of future directions, Ecological Modelling, 10.1016/j.ecolmodel.2018.12.010, 393, (135-151), (2019).
- Matthew G. Betts, Christopher Wolf, Marion Pfeifer, Cristina Banks-Leite, Víctor Arroyo-Rodríguez, Danilo Bandini Ribeiro, Jos Barlow, Felix Eigenbrod, Deborah Faria, Robert J. Fletcher, Adam S. Hadley, Joseph E. Hawes, Robert D. Holt, Brian Klingbeil, Urs Kormann, Luc Lens, Taal Levi, Guido F. Medina-Rangel, Stephanie L. Melles, Dirk Mezger, José Carlos Morante-Filho, C. David L. Orme, Carlos A. Peres, Benjamin T. Phalan, Anna Pidgeon, Hugh Possingham, William J. Ripple, Eleanor M. Slade, Eduardo Somarriba, Joseph A. Tobias, Jason M. Tylianakis, J. Nicolás Urbina-Cardona, Jonathon J. Valente, James I. Watling, Konstans Wells, Oliver R. Wearn, Eric Wood, Richard Young, Robert M. Ewers, Extinction filters mediate the global effects of habitat fragmentation on animals, Science, 10.1126/science.aax9387, 366, 6470, (1236-1239), (2019).
- Maximilian H. K. Hesselbarth, Marco Sciaini, Kimberly A. With, Kerstin Wiegand, Jakub Nowosad, landscapemetrics: an open‐source R tool to calculate landscape metrics, Ecography, 10.1111/ecog.04617, 42, 10, (1648-1657), (2019).
- André Lourenço, João Gonçalves, Filipe Carvalho, Ian J. Wang, Guillermo Velo‐Antón, Comparative landscape genetics reveals the evolution of viviparity reduces genetic connectivity in fire salamanders, Molecular Ecology, 10.1111/mec.15249, 28, 20, (4573-4591), (2019).
- Rebecca Money, Sarah Wilde, David Dawson, Review: The effectiveness of Theraplay for children under 12 – a systematic literature review, Child and Adolescent Mental Health, 10.1111/camh.12416, 0, 0, (undefined).
- Xingtang Wang, Leonard F.S. Wang, External bargaining versus internal manipulation: A theory of managerial delegation, Managerial and Decision Economics, 10.1002/mde.3218, 0, 0, (undefined).
- Xing Dong, Xu Dan, Ao Yawen, Xu Haibo, Li Huan, Tu Mengqi, Chen Linglong, Ruan Zhao, Identifying sarcopenia in advanced non‐small cell lung cancer patients using skeletal muscle CT radiomics and machine learning, Thoracic Cancer, 10.1111/1759-7714.13598, 0, 0, (undefined).




