Skip to contents

Please see vignette("general-background") for a general model description of arrR. To get a BibTex entry, please use citation("arrR") or see vignette("publication-record").

How to use arrR

You can always use ? in front of a function to see the help page. For many functions, there are additionally arguments which you can specify, which are not necessarily explained here.

1. Import and change starting values and parameters

After you installed and loaded the package, you can access default/exemplary starting values and parameters of the model. Since both objects are just named lists, you can easily change certain parameters. If you pass the objects to check_parameters(), the function will check if all required values are available and return warnings if not.

Of course, you can also load your own data as a list containing starting values and parameters. The read_parameters() function can help with this. You can also create the starting values and parameter lists completely from scratch as long as they are two named lists containing all required values.

Please see vignette("starting-values-parameters") for more information about all parameters.

# get starting values
starting_values <- arrR::default_starting

# get parameters
parameters <- arrR::default_parameters

# change some starting values and parameters
starting_values$pop_n <- 8

parameters$pop_reserves_max <- 0.1

parameters$seagrass_thres <- -1/4

# check if all parameters are present and meaningful
check_parameters(starting_values = starting_values, parameters = parameters)
#> > ...Checking starting values...
#> > ...Checking parameter values...
#> > ...Checking if starting values are within parameter boundaries...
#> > All checking done!

2. Setup seafloor and fish population

Next, you need to setup the seafloor and the fish population. If you want to add artificial reefs (ARs), simply provide a matrix with x- and y-coordinates of all reef cells. The center cell always has the coordinate x,y(0,0). Additionally, when setting up the seafloor, you need to specify the dimensions in x- and y-directions and the grain of one cell.

The function get_req_nutrients allows to calculate the nutrients and detritus amount to keep the whole ecosystem theoretical stable (excluding fish detritus consumption and nutrient excretion). The values can be used to set up the simulation environment.

# create 5 reef cells in center of seafloor
reef_matrix <- matrix(data = c(-1, 0, 0, 1, 1, 0, 0, -1, 0, 0), 
                      ncol = 2, byrow = TRUE)

# get stable nutrient/detritus values
stable_values <- get_req_nutrients(bg_biomass = starting_values$bg_biomass,
                                   ag_biomass = starting_values$ag_biomass,
                                   parameters = parameters)

starting_values$nutrients_pool <- stable_values$nutrients_pool

starting_values$detritus_pool <- stable_values$detritus_pool

# create seafloor
input_seafloor <- setup_seafloor(dimensions = c(50, 50), grain = 1, 
                                 reef = reef_matrix, starting_values = starting_values)
#> > ...Creating seafloor with 50 rows x 50 cols...
#> > ...Creating 5 artifical reef cell(s)...

# create fishpop
input_fishpop <- setup_fishpop(seafloor = input_seafloor, 
                               starting_values = starting_values, 
                               parameters = parameters)
#> > ...Creating 8 individuals within -25 25 -25 25 (xmin, xmax, ymin, max)...

3. Run the model

The run_simulation() function is the core function of the package that starts a simulation run. You only need to provide the previously created seafloor and fish population as well as the parameters. Additionally, you need to specify the total run time of the simulation (in # of iterations called i here).

Further, you can specify how often all seagrass related processes should be simulated, e.g. only once a day using seagrass_each.

Last, because the produced output can be quite large, you can save only every j iterations, specified by save_each. The model will still simulate all processes each iteration, however, only safe and return the specified iterations to reduce the required memory.

One of the most important function arguments of run_simulation() is the movement argument, which specifies how individuals move across the simulation environment. For more information, please see vignette("movement-behaviors").

# one iterations equals 120 minutes
min_per_i <- 120

# run the model for ten years
years <- 10
max_i <- (60 * 24 * 365 * years) / min_per_i

# run seagrass once each day
days <- 1
seagrass_each <- (24 / (min_per_i / 60)) * days

# save results only every 365 days
days <- 365
save_each <- (24 / (min_per_i / 60)) * days

result <- run_simulation(seafloor = input_seafloor, fishpop = input_fishpop,
                         parameters = parameters, movement = "attr",
                         max_i = max_i, min_per_i = min_per_i, 
                         seagrass_each = seagrass_each, save_each = save_each)
#> > ...Starting at <2022-11-29 13:50:47>...
#> 
#> > Seafloor with 50 rows x 50 cols; 5 reef cell(s).
#> > Population with 8 individuals [movement: 'attr'].
#> > Simulating 43800 iterations (3650 days) [Burn-in: 0 iter.].
#> > Saving each 4380 iterations (365 days).
#> > One iteration equals 120 minutes.
#> > Storing results in RAM.
#> 
#> > ...Saving results...
#> 
#> > ...All done at <2022-11-29 13:51:07>...

4. Look at model results

You can get a first glance and the results simply printing the model output. This gives you some summary statistics at the last iteration of the model.

# print model results
result
#> Total time : 0-43800 iterations (3650 days) [Burn-in: 0 iter.]
#> Saved each : 4380 iterations (365 days)
#> Seafloor   : 50 rows x 50 cols; 5 reef cell(s)
#> Fishpop    : 8 indiv (movement: 'attr')
#> 
#> Seafloor : (ag_biomass, bg_biomass, nutrients_pool, detritus_pool)
#> Minimum  : 86.025, 605.201, 0.003, 3.062
#> Mean     : 101.935, 615.785, 0.003, 3.078
#> Maximum  : 163.698, 686.798, 0.011, 3.081
#> 
#> Fishpop  : (length, weight, died_consumption, died_background)
#> Minimum  : 15.759, 73.818, 0, 1
#> Mean     : 19.613, 173.937, 0, 1
#> Maximum  : 29.298, 524.152, 0, 1

The returning object mdl_rn object is simply a list “under the hood”, so analyzing the results yourself should be pretty straightforward. Simply access the data you need.

# show all elements of result list
names(result)
#>  [1] "seafloor"        "fishpop"         "nutrients_input" "movement"       
#>  [5] "parameters"      "starting_values" "dimensions"      "extent"         
#>  [9] "grain"           "max_i"           "min_per_i"       "burn_in"        
#> [13] "seagrass_each"   "save_each"

# show e.g. result for fish population
head(result$fishpop)
#>   id age          x          y   heading    length     weight activity
#> 1  1   0  10.797407  -1.711353  87.58893  3.913741  0.9035852        0
#> 2  2   0   7.026260 -13.652709 327.36435  3.722778  0.7714295        0
#> 3  3   0 -10.860985  18.418727 202.86666  3.406898  0.5828714        0
#> 4  4   0  12.484914 -13.613929  12.37235  4.337592  1.2506292        0
#> 5  5   0 -20.126124  -9.938572 136.13220 10.231814 18.8471504        0
#> 6  6   0  -1.796588  -7.748389  84.60788  5.155448  2.1590341        0
#>   respiration    reserves reserves_max behavior consumption excretion
#> 1           0 0.002508649  0.002709852        3           0         0
#> 2           0 0.001846619  0.002313517        3           0         0
#> 3           0 0.001628157  0.001748031        3           0         0
#> 4           0 0.002694382  0.003750637        3           0         0
#> 5           0 0.049253337  0.056522604        3           0         0
#> 6           0 0.004700572  0.006474943        3           0         0
#>   died_consumption died_background timestep burn_in
#> 1                0               0        0     yes
#> 2                0               0        0     yes
#> 3                0               0        0     yes
#> 4                0               0        0     yes
#> 5                0               0        0     yes
#> 6                0               0        0     yes

# get results of fish population of the final timestep and plot weight ~ length
(final_fishpop <- dplyr::filter(result$fishpop, timestep == max(timestep)) %>% 
  ggplot2::ggplot(ggplot2::aes(x = length, y = weight)) + 
    ggplot2::geom_point(shape = 1) + 
    ggplot2::geom_smooth(method = "lm", formula =  "y ~ x", size = 0.5) +
    ggplot2::labs(x = "Length [cm]", y = "Weight [g]") +
    ggplot2::theme_classic())
#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
#>  Please use `linewidth` instead.

Lastly, you can plot the results. Make sure to also check out the summarize argument of the plot function.

# plot map of seafloor
plot(result, what = "seafloor")

5. Various

arrR comes with many helper functions, such as get_density(), get_limits(), filter_mdlrn() or summarize_mdlrn(). Make sure to check out the Index for an overview.