Package: rangr 1.0.6

Katarzyna Markowska

rangr: Mechanistic Simulation of Species Range Dynamics

Integrates population dynamics and dispersal into a mechanistic virtual species simulator. The package can be used to study the effects of environmental change on population growth and range shifts. It allows for simple and straightforward definition of population dynamics (including positive density dependence), extensive possibilities for defining dispersal kernels, and the ability to generate virtual ecologist data. Learn more about the 'rangr' at <https://docs.ropensci.org/rangr/>.

Authors:Katarzyna Markowska [aut, cre], Lechosław Kuczyński [aut], Tad Dallas [rev], Joanne Potts [rev]

rangr_1.0.6.tar.gz
rangr_1.0.6.zip(r-4.5)rangr_1.0.6.zip(r-4.4)rangr_1.0.6.zip(r-4.3)
rangr_1.0.6.tgz(r-4.5-any)rangr_1.0.6.tgz(r-4.4-any)rangr_1.0.6.tgz(r-4.3-any)
rangr_1.0.6.tar.gz(r-4.5-noble)rangr_1.0.6.tar.gz(r-4.4-noble)
rangr_1.0.6.tgz(r-4.4-emscripten)rangr_1.0.6.tgz(r-4.3-emscripten)
rangr.pdf |rangr.html
rangr/json (API)
NEWS

# Install 'rangr' in R:
install.packages('rangr', repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org'))

Reviews:rOpenSci Software Review #595

Bug tracker:https://github.com/ropensci/rangr/issues4 issues

Pkgdown site:https://docs.ropensci.org

Datasets:

On CRAN:rangr-1.0.6(2025-02-26)

Conda:

5.18 score 2 stars 5 scripts 241 downloads 9 exports 6 dependencies

Last updated 22 days agofrom:a77743be6b (on main). Checks:9 OK. Indexed: yes.

TargetResultLatest binary
Doc / VignettesOKMar 04 2025
R-4.5-winOKMar 04 2025
R-4.5-macOKMar 04 2025
R-4.5-linuxOKMar 04 2025
R-4.4-winOKMar 04 2025
R-4.4-macOKMar 04 2025
R-4.4-linuxOKMar 04 2025
R-4.3-winOKMar 04 2025
R-4.3-macOKMar 04 2025

Exports:dispexponentialget_observationsgompertzinitialiseK_get_interpolationrickersimto_rast

Dependencies:assertthatlatticepbapplyRcppterrazoo

How to use rangr?

Rendered fromrangr.Rmdusingknitr::rmarkdownon Mar 04 2025.

Last update: 2024-07-26
Started: 2023-05-26

Citation

To cite rangr in publications use:

Markowska K, Kuczyński L (2023). rangr: simulating range dynamics of virtual species. R package version 1.0.5, https://github.com/ropensci/rangr.

Corresponding BibTeX entry:

  @Manual{rangr,
    title = {rangr: simulating range dynamics of virtual species},
    author = {Katarzyna Markowska and Lechosław Kuczyński},
    year = {2023},
    note = {R package version 1.0.5},
    url = {https://github.com/ropensci/rangr},
  }

Readme and manuals

rangr

The rangr package is designed to simulate a species range dynamics. This new tool mimics the essential processes that shape population numbers and spatial distribution: local dynamics and dispersal. Simulations can be run in a spatially explicit and dynamic environment, facilitating population projections in response to climate or land-use changes. By using different sampling schemes and observational error distributions, the structure of the original survey data can be reproduced, or pure random sampling can be mimicked.

The study is supported by the National Science Centre, Poland, grant no. 2018/29/B/NZ8/00066 and the Poznań Supercomputing and Networking Centre (grant no. 403).

Installation

Development version

You can install the development version from R-universe or GitHub with:

install.packages("rangr", repos = "https://ropensci.r-universe.dev")
# or
# devtools::install_github("ropensci/rangr")
install.packages("rangr", repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org'))

Basic simulation

Here’s an example of how to use the rangr package.

Input maps

Example maps available in rangr in the Cartesian coordinate system:

  • n1_small.tif
  • n1_big.tif
  • K_small.tif
  • K_small_changing.tif
  • K_big.tif

Example maps available in rangr in the longitude/latitude coordinate system:

  • n1_small_lon_lat.tif
  • n1_big_lon_lat.tif
  • K_small_lon_lat.tif
  • K_small_changing_lon_lat.tif
  • K_big_lon_lat.tif

You can find additional information about these data sets in help files:

library(rangr)

?n1_small.tif
?K_small.tif

Two of the available datasets, n1_small.tif and K_small.tif, represent the abundance of a virtual species at the starting point of a simulation and the carrying capacity of the environment, respectively. Both of these objects refer to the same relatively small area, so they are ideal for demonstrating the usage of the package. To view these maps and their dimensions, you can use the following commands:

library(terra)
#> terra 1.7.55

n1_small <- rast(system.file("input_maps/n1_small.tif", package = "rangr"))
K_small <-  rast(system.file("input_maps/K_small.tif", package = "rangr"))

You can also use the plot function from the terra package to visualize these maps:

plot(c(n1_small, K_small))

Initialise

To create a sim_data object containing the necessary information to run a simulation, use the initialise() function. For example:

sim_data_01 <- initialise(
  n1_map = n1_small,
  K_map = K_small,
  r = log(2),
  rate = 1 / 1e3
)

Here, we set the intrinsic population growth rate to log(2) and the rate parameter that is related to the kernel function describing dispersal to 1/1e3.

To see the summary of the sim_data object:

summary(sim_data_01)
#> Summary of sim_data object
#> 
#> n1 map summary: 
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
#>  0.0000  0.0000  0.0000  0.1449  0.0000 10.0000      12 
#> 
#> Carrying capacity map summary: 
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
#>    0.00    0.00   56.00   44.84   72.00  100.00      12 
#>                       
#> growth        gompertz
#> r               0.6931
#> A                    -
#> kernel_fun        rexp
#> dens_dep           K2N
#> border       reprising
#> max_dist          5000
#> changing_env     FALSE
#> dlist             TRUE

Simulation

To run a simulation, use the sim() function, which takes a sim_data object and the specified number of time steps as input parameters. For example:

sim_result_01 <- sim(obj = sim_data_01, time = 100)

To see the summary of the sim_result_01 object:

summary(sim_result_01)
#> Summary of sim_results object
#> 
#> Simulation summary: 
#>                     
#> simulated time   100
#> extinction     FALSE
#> 
#> Abundances summary: 
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
#>    0.00    0.00   12.00   10.45   19.00   54.00    1200

Note that this is a simple example and there are many more parameters that can be set for initialise() and sim(). See the documentation for the rangr package for more information.

Visualisation

You can use rangr to visualise selected time steps from the simulation. The plot() method is used to generate the plot. Here’s an example:

# generate visualisation
plot(sim_result_01,
  time_points = c(1, 10, 25, 50),
  template = sim_data_01$K_map
)
#> class       : SpatRaster 
#> dimensions  : 15, 10, 4  (nrow, ncol, nlyr)
#> resolution  : 1000, 1000  (x, y)
#> extent      : 270000, 280000, 610000, 625000  (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89 / Poland CS92 
#> source(s)   : memory
#> names       : t_1, t_10, t_25, t_50 
#> min values  :   0,    0,    0,    0 
#> max values  :  10,   19,   27,   36

You can adjust the breaks parameter to get more breaks on the colorscale:

# generate visualisation with more breaks
plot(sim_result_01,
  time_points = c(1, 10, 25, 50),
  breaks = seq(0, max(sim_result_01$N_map + 5, na.rm = TRUE), by = 5),
  template = sim_data_01$K_map
)
#> class       : SpatRaster 
#> dimensions  : 15, 10, 4  (nrow, ncol, nlyr)
#> resolution  : 1000, 1000  (x, y)
#> extent      : 270000, 280000, 610000, 625000  (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89 / Poland CS92 
#> source(s)   : memory
#> names       : t_1, t_10, t_25, t_50 
#> min values  :   0,    0,    0,    0 
#> max values  :  10,   19,   27,   36

If you prefer working on raster you can also transform any sim_result object into SpatRaster using to_rast() function:

# raster construction
my_rast <- to_rast(
  sim_result_01,
  time_points = 1:sim_result_01$simulated_time,
  template = sim_data_01$K_map
)

# print raster
print(my_rast)
#> class       : SpatRaster 
#> dimensions  : 15, 10, 100  (nrow, ncol, nlyr)
#> resolution  : 1000, 1000  (x, y)
#> extent      : 270000, 280000, 610000, 625000  (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89 / Poland CS92 
#> source(s)   : memory
#> names       : t_1, t_2, t_3, t_4, t_5, t_6, ... 
#> min values  :   0,   0,   0,   0,   0,   0, ... 
#> max values  :  10,  11,  14,  16,  20,  13, ...

And then visualise it using plot() function:

# plot selected time points
plot(my_rast, c(1, 10, 25, 50))

Vignettes

Citation

To cite rangr use citation() function:

library(rangr)
citation("rangr")

Code of Conduct

Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Help Manual

Help pageTopics
Simulating Dispersaldisp
Observation Processget_observations
Population Growth Functionsexponential gompertz growth ricker
Prepare Data Required To Perform A Simulationinitialise
Example Of Carrying Capacity Map (Big)K_big_lon_lat.tif
Example Of Carrying Capacity Map (Big)K_big.tif
Prepare Time-Varying Carrying Capacity MapsK_get_interpolation
Example Of Changing Carrying Capacity Maps (Small)K_small_changing_lon_lat.tif
Example Of Changing Carrying Capacity Maps (Small)K_small_changing.tif
Example Of Carrying Capacity Map (Small)K_small_lon_lat.tif
Example Of Carrying Capacity Map (Small)K_small.tif
Example Of Abundance Map At First Time Step Of The Simulation (Big)n1_big_lon_lat.tif
Example Of Abundance Map At First Time Step Of The Simulation (Big)n1_big.tif
Example Of Abundance Map At First Time Step Of The Simulation (Small)n1_small_lon_lat.tif
Example Of Abundance Map At First Time Step Of The Simulation (Small)n1_small.tif
Example Of Observation Points Listobservations_points
Plot 'sim_results' Objectplot.sim_results
Print 'sim_data' Objectprint.sim_data
Print 'sim_results' Objectprint.sim_results
Print 'summary.sim_data' Objectprint.summary.sim_data
Print 'summary.sim_results' Objectprint.summary.sim_results
Mechanistic Metapopulation Simulatorsim
Subset of Given Time Points from 'sim_results' Objectsubset.sim_results
Summary Of 'sim_data' Objectsummary.sim_data
Summary Of 'sim_results' Objectsummary.sim_results
Transformation 'sim_results' To Rasterto_rast
Update 'sim_data' Objectupdate.sim_data