Package 'Rpath'

Title: R implementation of Ecopath with Ecosim
Description: This package implements the core mass balance equations made popular by Ecopath with Ecosim. There are two parts to the package, the static snapshot of energy flow through the system using rpath and dynamic simulations run using the rsim family of functions.
Authors: Kerim Aydin [aut, cre] (ORCID: <https://orcid.org/0000-0003-3792-9828>), Sean Lucey [aut] (ORCID: <https://orcid.org/0000-0001-6675-5500>), Sarah Gaichas [aut] (ORCID: <https://orcid.org/0000-0002-5788-3073>), Sarah Weisberg [aut] (ORCID: <https://orcid.org/0000-0003-4271-9534>), Andy Whitehouse [aut] (ORCID: <https://orcid.org/0000-0002-9130-9403>), Bia Dias [ctb] (ORCID: <https://orcid.org/0000-0001-5905-4044>), Ron Klasky [ctb], Andy Beet [ctb] (ORCID: <https://orcid.org/0000-0001-8270-7090>), Max Grezlik [ctb]
Maintainer: Kerim Aydin <[email protected]>
License: file LICENSE
Version: 1.1.0
Built: 2026-06-07 07:50:15 UTC
Source: https://github.com/NOAA-EDAB/Rpath

Help Index


AB.params

Description

Anchovy Bay (AB.params) is a sample ecosystem frequently used as an example ecosystem with EwE (see Christensen and Walters, 2024).

Usage

AB.params

Format

An unbalanced Rpath model object that contains:

model

A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).

diet

A data.table containing the Ecopath model's diet matrix.

stanzas

Parameters for multistanza groups.

pedigree

A data.table containing the data quality (pedigree) for the Ecopath model.

...

Source

Christensen V, Walters CJ (2024) Ecosystem Modelling with EwE. The University of British Columbia, Vancouver, BC. doi:10.14288/24d7-ab68

Examples

# Balance the model
AB_bal <- rpath(AB.params)

Adjust Fishing Mortality

Description

Modifies the fishing mortality value for a species by a particular gear. Parameters that can be adjusted using this function are: ForcedEffort, ForcedFRate, or ForcedCatch.

Usage

adjust.fishing(
  Rsim.scenario,
  parameter,
  group = NA,
  sim.year = 1,
  sim.month = 0,
  value
)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

parameter

Parameters to be modified (ForcedEffort,ForcedCatch,ForcedFRate)

group

Name of the group whose parameter is being changed. Valid values are found in the 'Group' field of the object created from running rpath()

sim.year

Year of the simulation that should be modified. Can be a range of years.

sim.month

Month of the year that should be modified. If set to 0, all months of the year are modified.

value

New value for the parameter.

Value

Returns an Rsim.scenario() object with the new fishing parameter values.

See Also

Other Adjust functions: adjust.forcing(), adjust.scenario(), set.rsim.scene()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Change value of forcedFRate for Squids in years 3 through 5 to the value of 2 (for all months)
Rsim.scenario.adjusted.fishing <- adjust.fishing(Rsim.scenario, parameter = "ForcedFRate", group = "cod", sim.year = 3:5, value = 2)
head(Rsim.scenario.adjusted.fishing$fishing$ForcedFRate)

Adjust Forcing Parameters

Description

Modifies the various forcing parameters of the rsim scenario object.

Usage

adjust.forcing(
  Rsim.scenario,
  parameter,
  group,
  sim.year = 1,
  sim.month = 0,
  bymonth = F,
  value
)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

parameter

Parameters to be modified (ForcedEffort,ForcedCatch,ForcedFRate)

group

Name of the group whose parameter is being changed. Valid values are found in the 'Group' field of the object created from running rpath()

sim.year

Year of the simulation that should be modified. Can be a range of years.

sim.month

Month of the year that should be modified. If set to 0, all months of the year are modified.

bymonth

Boolean value that denotes whether to use sim.year/sim.month combo or just sim.month as a sequential vector starting at 1.

value

New value for the parameter.

Value

Returns an Rsim.scenario object with the new parameter.

See Also

Other Adjust functions: adjust.fishing(), adjust.scenario(), set.rsim.scene()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Adjust the ForcedPrey parameter for cod in year 1 for all months. Change the value to 10
Rsim.scenario.adjusted <- adjust.forcing(Rsim.scenario, parameter="ForcedPrey",group = "cod", sim.year = 1, sim.month=0,value=10)
head(Rsim.scenario.adjusted$forcing$ForcedPrey)

Adjust Rsim.scenario parameters

Description

Modifies the various parameters of the rsim.scenario() object. Parameters that can be adjusted using this function are: B_BaseRef, MzeroMort,UnassimRespFrac, ActiveRespFrac, FtimeAdj, FtimeQBOpt, PBopt, NoIntegrate,HandleSelf, ScrambleSelf, QQ, DD, VV, HandleSwitch, PredPredWeight, PreyPreyWeight

Usage

adjust.scenario(Rsim.scenario, parameter, group, groupto = NA, value)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

parameter

Parameters to be modified (Choose from: B_BaseRef, MzeroMort, UnassimRespFrac, ActiveRespFrac, FtimeAdj, FtimeQBOpt, PBopt, NoIntegrate, HandleSelf, ScrambleSelf, QQ, DD, VV, HandleSwitch, PredPredWeight, PreyPreyWeight)

group

The model group that the parameter change will affect. Note that a value of 'all' will affect all groups associated with the 'groupto' variable. Valid values are found in the 'Group' field of the object created from running rpath()

groupto

The corresponding group who's parameter is affecting the group variable. Required for parameters QQ, DD, VV, HandleSwitch,PredPredWeight, PreyPreyWeight

value

New value for the parameter.

Value

Returns an rsim.scenario() object with the new parameter.

See Also

Other Adjust functions: adjust.fishing(), adjust.forcing(), set.rsim.scene()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Adjust the PBopt parameter for cod. Set to value = 2
Rsim.scenario.adjusted <- adjust.scenario(Rsim.scenario, parameter="PBopt",group = "cod", groupto = "all", value = 2)

Check Rpath parameter files

Description

Logical check that the parameter files are filled out correctly, i.e. data is entered where it is expected.

Usage

check.rpath.params(Rpath.params)

Arguments

Rpath.params

R object containing the parameters needed to create a Rpath model. This is generated either by the create.rpath.params() or read.rpath.params() functions.

Value

Checks Rpath parameter files for consistency. An error message will be produced if one of the logical checks fails. Checks include: verification that all types are represented (e.g. consumer, producer, detrital, and fleet); check if input parameters were entered correctly; check if Diet columns sum to 1. (NOTE: This does not ensure data is correct just that it is in the right places).

See Also

Other Rpath functions: MTI(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()


Creates an Rpath object from an EwE exported model (EIIXML format)

Description

Parses an eiixml file exported using the Ecopath with Ecosim (EwE) GUI into an unbalanced Rpath model object, which can then be balanced. This function was tested on files exported by EwE version 6.7.

Usage

create.rpath.from.eiixml(eiifile, verbose = FALSE)

Arguments

eiifile

Path to exported EwE XML file

verbose

Logical. Use for debugging. If TRUE, prints out a list of parsed tables and number of rows read from the XML file

Value

An Rpath object (list) with the following components:

stanzas

Stanza parameters

pedigree

Pedigree parameters

diet

Diet parameters

model

Model parameters

See Also

Other xml: import.eiixml()

Examples

# Import an eiixml file previously exported from the EwE GUI, check that the
# unbalanced model is functional, recalculate age-structured groups based on
# imported stanza parameters (if the imported model has stanzas), and balance
# the model.
eiixml <- system.file("extdata/xml/Western_Bering_Sea.eiixml", package = "Rpath")
rpath_object <- create.rpath.from.eiixml(eiixml)
check.rpath.params(rpath_object)
rpath_object <- rpath.stanzas(rpath_object)
rpath_balanced <- rpath(rpath_object)

Creates a shell for the Rpath.params object

Description

Creates a shell of the Rpath.params list object which contains the model, diet, multistanza, and pedigree parameters.

Usage

create.rpath.params(group, type, stgroup = NA)

Arguments

group

Vector of group names.

type

Numeric vector of group type. Living = 0, Producer = 1, Detritus = 2, Fleet = 3.

stgroup

Vector of multistanza group names. Include NA for non-stanza groups.

Value

Outputs a list object of Rpath.params which are populated with values of NA or logical default values. Values can then be filled in using R. Use check.rpath.params() to ensure parameter files are filled out correctly (NOTE: This does not ensure data is correct just that it is in the right places).

See Also

Other Rpath functions: MTI(), check.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()


Eastern Bering Sea 1990s Ecopath model

Description

Rpath inputs for the eastern Bering Sea 1990s Ecopath model (53 biological groups and 1 fleet).

Usage

Ecosense.EBS

Format

An unbalanced Rpath model object that contains:

model

A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).

diet

A data.table containing the Ecopath model's diet matrix.

stanzas

Parameters for multistanza groups.

pedigree

A data.table containing the data quality (pedigree) for the Ecopath model.

...

Note

This is an aggregated version of the 1990s eastern Bering Sea Ecopath model of Aydin et al. (2007) and does not include stanzas.

Source

Whitehouse and Aydin 2020. Assessing the sensitivity of three Alaska marine food webs to perturbations: an example of Ecosim simulations using Rpath. https://doi.org/10.1016/j.ecolmodel.2020.109074

References

Aydin KY, Gaichas S, Ortiz I, Kinzey D, Friday N (2007) A comparison of the Bering Sea, Gulf of Alaska, and Aleutian Islands large marine ecosystems through food web modeling. U.S. Dep. Commer., NOAA Tech. Memo. NMFS-AFSC-178.

Examples

# Balance the model
ebs_bal <- rpath(Ecosense.EBS)

Eastern Chukchi Sea Ecopath model

Description

Rpath inputs for the eastern Chukchi Sea Ecopath model (52 biological groups and 1 fleet).

Usage

Ecosense.ECS

Format

An unbalanced Rpath model object that contains:

model

A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).

diet

A data.table containing the Ecopath model's diet matrix.

stanzas

Parameters for multistanza groups.

pedigree

A data.table containing the data quality (pedigree) for the Ecopath model.

...

Note

This is an aggregated version of the eastern Chukchi Sea Ecopath model of Whitehouse and Aydin (2016).

Source

Whitehouse and Aydin 2020. Assessing the sensitivity of three Alaska marine food webs to perturbations: an example of Ecosim simulations using Rpath. https://doi.org/10.1016/j.ecolmodel.2020.109074

References

Whitehouse GA, Aydin KY (2016) Trophic structure of the eastern Chukchi Sea: An updated mass balance food web model. U.S. Dep Commer, NOAA Tech. Memo. NMFS-AFSC-318. doi:10.7289/V5/TM-AFSC-318

Examples

# Balance the model
ecs_bal <- rpath(Ecosense.ECS)

Gulf of Alaska (west/central) 1990s Ecopath model

Description

Rpath inputs for the Gulf of Alaska (west/central) 1990s Ecopath model (49 biological groups and 1 fleet).

Usage

Ecosense.GOA

Format

An unbalanced Rpath model object that contains:

model

A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).

diet

A data.table containing the Ecopath model's diet matrix.

stanzas

Parameters for multistanza groups.

pedigree

A data.table containing the data quality (pedigree) for the Ecopath model.

...

Note

This is an aggregated version of the 1990s Gulf of Alaska Ecopath model of Aydin et al. (2007) and does not include stanzas.

Source

Whitehouse and Aydin 2020. Assessing the sensitivity of three Alaska marine food webs to perturbations: an example of Ecosim simulations using Rpath. https://doi.org/10.1016/j.ecolmodel.2020.109074

References

Aydin KY, Gaichas S, Ortiz I, Kinzey D, Friday N (2007) A comparison of the Bering Sea, Gulf of Alaska, and Aleutian Islands large marine ecosystems through food web modeling. U.S. Dep. Commer., NOAA Tech. Memo. NMFS-AFSC-178.

Examples

# Balance the model
goa_bal <- rpath(Ecosense.GOA)

Extract node/group data from an Rsim run

Description

Extracts group/node specific information from a scenario run using rsim.run()

Usage

extract.node(Rsim.output, group)

Arguments

Rsim.output

Object generated by rsim.run().

group

Name of the node/group for which you want to extract data. Valid values are found in the 'Group' field of the object created from running rpath()

Value

Returns a list object with monthly node specific data

Biomass

Vector of monthly Biomass values

AnnualBiomass

Vector of annual Biomass

TotalCatch

Vector of monthly Catch values

AnnualTotalCatch

Vector of annual Catch values

Landings

Dataframe (n x l) of monthly Landings. (Each column is a fishery that Lands the 'group')

Discards

Dataframe (n x d) of monthly Discards (Each column is a fishery that Discards the 'group')

See Also

Other Rsim functions: rsim.params(), rsim.plot(), rsim.run(), rsim.scenario(), rsim.step(), write.Rsim()

Examples

# Read in Rpath parameter file and balance model
Rpath <- rpath(Ecosense.EBS)
# Create a 50 yr Rpath scenario
Rsim.scenario <- rsim.scenario(Rpath, Ecosense.EBS, years = 1:50)
# Run a scenario
Rsim.output <- rsim.run(Rsim.scenario, method = "RK4", years = 1:50)
# Extracts group (node) specific data from the simulation run
group <- extract.node(Rsim.output,Rpath$Group['Squids'])

Fishing Mortality Table

Description

Creates a table of fishing mortalities by species group and gear for an rsim.scenario() object.

Usage

frate.table(Rsim.scenario)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

Value

Returns a data table of F values for each species/gear combination.

Group

Group/node

Fishery/gearType

Gear type for the fishery

...

Total

Sum over all gear types

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
rates <- frate.table(Rsim.scenario)
# display the head of the data frame
head(rates)

Retrieve fishing forcing parameters from an Rsim scenario

Description

Helper function that will retrieve the fishing forcing parameters that were used in an Rsim scenario

Usage

get.rsim.fishing(Rsim.scenario)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

Value

Returns a 'fishing' object.

See Also

Other Get functions: get.rsim.forcing(), get.rsim.params(), get.rsim.stanzas(), get.rsim.start_state()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
params <- get.rsim.fishing(Rsim.scenario)
names(params)

Retrieve forcing parameters from an Rsim scenario

Description

Helper function that will retrieve the forcing parameters that were used in an Rsim scenario

Usage

get.rsim.forcing(Rsim.scenario)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

Value

Returns a 'forcing' object.

See Also

Other Get functions: get.rsim.fishing(), get.rsim.params(), get.rsim.stanzas(), get.rsim.start_state()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
params <- get.rsim.forcing(Rsim.scenario)
names(params)

Retrieve parameters from an Rsim scenario

Description

Helper function that will retrieve the parameters that were used in an Rsim scenario

Usage

get.rsim.params(Rsim.scenario)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

Value

Returns a 'params' object.

See Also

Other Get functions: get.rsim.fishing(), get.rsim.forcing(), get.rsim.stanzas(), get.rsim.start_state()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
params <- get.rsim.params(Rsim.scenario)
names(params)

Retrieve stanza parameters from an Rsim scenario

Description

Helper function that will retrieve the stanza parameters that were used in an Rsim scenario

Usage

get.rsim.stanzas(Rsim.scenario)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

Value

Returns a 'stanzas' object.

See Also

Other Get functions: get.rsim.fishing(), get.rsim.forcing(), get.rsim.params(), get.rsim.start_state()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
params <- get.rsim.stanzas(Rsim.scenario)
names(params)

Retrieve starting state values from an Rsim scenario

Description

Helper function that will retrieve the starting state values that were used in an Rsim scenario

Usage

get.rsim.start_state(Rsim.scenario)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

Value

Returns an 'start_state' object.

See Also

Other Get functions: get.rsim.fishing(), get.rsim.forcing(), get.rsim.params(), get.rsim.stanzas()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
params <- get.rsim.start_state(Rsim.scenario)
names(params)

ggplot routine for Rpath food web

Description

Plots the food web associated with an Rpath object using ggplot functions

Usage

ggwebplot(
  Rpath.obj,
  eco.name = attr(Rpath.obj, "eco.name"),
  line.col = "grey",
  highlight = NULL,
  highlight.col = c("black", "red", "orange"),
  labels = FALSE,
  label.num = FALSE,
  label.cex = 1,
  fleets = FALSE,
  type.col = "grey50",
  box.order = NULL,
  line.alpha = 0.5,
  point.size = 1,
  text.size = 5,
  max.overlaps = 10
)

Arguments

Rpath.obj

Rpath model created by the rpath() function.

eco.name

Optional name of the ecosystem. Default is the 'eco.name' attribute from the rpath object.

line.col

The color of the lines between nodes of the food web.

highlight

Set to the group number or name to highlight the connections of that group. Valid values are found in the 'Group' field of the object created from running rpath().

highlight.col

Color of the connections to the highlighted group, vector of length 3. Defaults to black = predator, red = prey, orange = fleet.

labels

Logical whether or not to display group names.

label.num

Logical whether or not to display group numbers instead of points at nodes. If TRUE, type.col must be length 1, not 4.

label.cex

Numeric value of the relative size of the labels within the plot.

fleets

Logical value indicating whether or not to include fishing fleets in the food web.

type.col

The color of the points corresponding to the types of the group. Can either be of length 1 or 4. Color order will be living, primary producers, detrital, and fleet groups.

box.order

Vector of box numbers to change the default plot order. Must include all box numbers. Passed to summarize.for.webplot()

line.alpha

Transparency of lines between nodes of the food web.

point.size

Size of points at nodes.

text.size

Size of text

max.overlaps

Maximum number of overlaps allowed for group labels by ggrepel

Value

Returns a ggplot object visualizing the food web

Examples

# Read in Rpath parameter file, generate and name model object
Rpath.obj <- rpath(AB.params, eco.name = "Anchovy Bay")
# Plot food web diagram with all groups labeled, including fleets, using ggplot
ggwebplot(Rpath.obj, labels = TRUE, fleets = TRUE)
# Plot food web diagram without labels, highlighting connections of cod group
ggwebplot(Rpath.obj, highlight = "cod",fleets = TRUE)

Reads in EwE exported XML file and parses into data frames

Description

Parses an eiixml file exported using the Ecopath with Ecosim (EwE) GUI into a list of data frames, one frame for each table in the exported XML file. This function is usually called by the function create.rpath.from.eiixml() that converts these tables into an unbalanced rpath model object. However import.xml can be used on its own to examine the full set of tables exported by EwE, including tables not currently imported into Rpath objects, such as Ecosim runs or model metadata. This function was tested on files exported by EwE version 6.7.

Usage

import.eiixml(eiifile, verbose = FALSE)

Arguments

eiifile

Path to exported EwE XML file

verbose

Logical. Use for debugging. If TRUE, prints out a list of parsed tables and number of rows read from the XML file

Value

A list of data frames, one data frame for each node (exported EwE table) in the XML file. Each table has the naming convention ewe_[table name] where [table name] is the name of the table provided by EwE.

See Also

Other xml: create.rpath.from.eiixml()

Examples

# Import an eiixml file previously exported from the EwE GUI into a list of
# data frames containing the model data
eiixml <- system.file("extdata/xml","Western_Bering_Sea.eiixml", package = "Rpath")
xml_data <- import.eiixml(eiixml)

Quantify mixed trophic impacts

Description

Uses a static Rpath model and creates a matrix of mixed trophic impacts.

Usage

MTI(Rpath, Rpath.params, increase = T)

Arguments

Rpath

Rpath R object containing a static Rpath model.

Rpath.params

R object containing the Rpath model parameters. This is generated either by the create.rpath.params() or read.rpath.params() functions.

increase

Logical value indicating whether a marginal increase is applied.

Value

Returns a matrix of mixed trophic impacts.

See Also

Other Rpath functions: check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()


Read Rpath parameters from .csv files

Description

Creates an Rpath.param object from a series of .csv files.

Usage

read.rpath.params(
  modfile,
  dietfile,
  pedfile = NA,
  stanzagroupfile = NA,
  stanzafile = NA
)

Arguments

modfile

file location of the flat file containing the model parameters.

dietfile

file location of the flat file containing the diet parameters.

pedfile

file location of the flat file containing the pedgigree parameters.

stanzagroupfile

file location of the flat file containing the group parameters for multistanza groups. If not specified a blank stanza list will be created.

stanzafile

file location of the flat file containing the individual stanza parameters for multistanza groups. If not specified a blank stanza list will be created.

Value

Outputs an Rpath.param object that can be used for Rpath and subsequently Rsim. (NOTE: This does function does not ensure data is correct or in the correct locations.Run check.rpath.params() to ensure the appropriate columns are present).

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()


REco.params

Description

Rpath inputs for a tutorial Rpath ecosystem.

Usage

REco.params

Format

An unbalanced Rpath model object that contains:

model

A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).

diet

A data.table containing the Ecopath model's diet matrix.

stanzas

Parameters for multistanza groups.

pedigree

A data.table containing the data quality (pedigree) for the Ecopath model.

...

References

Lucey SM, Gaichas SK, Aydin KY (2020) Conducting reproducible ecosystem modeling using the open source mass balance model Rpath. Ecol Model 427:11. doi:10.1016/j.ecolmodel.2020.109057

See Also

vignette("ModelSetup", package = "Rpath") for an example of how to build this tutorial ecosystem.

Examples

# Balance the model
REco_bal <- rpath(REco.params)

Ecopath module of Rpath

Description

Performs initial mass balance using a Rpath.params() file

Usage

rpath(Rpath.params, eco.name = NA, eco.area = 1)

Arguments

Rpath.params

R object containing the parameters needed to create a Rpath model. This is generated either by the create.rpath.params() or read.rpath.params() functions.

eco.name

Optional name of the ecosystem which becomes an attribute of the Rpath model.

eco.area

Optional area of the ecosystem which becomes an attribute of the Rpath model.

Value

Returns a static Rpath model that can be supplied to the rsim.scenario function.

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()


List of Rpath consumer groups

Description

List of consumer groups from Rpath object with species type = 0.

Usage

rpath.consumers(Rpath)

Arguments

Rpath

Balanced Rpath model generated by rpath()

Value

Returns a string vector containing the names of Rpath functional groups that are consumers

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Build the balanced Rpath model and parameter file by calling `rpath`
Rpath <- rpath(Ecosense.EBS)
# Run the consumers command
consumerGroups = rpath.consumers(Rpath)
# Print out the first few consumer group names
head(consumerGroups)

List of Rpath detrital groups

Description

List of detrital groups from Rpath object with species type = 2

Usage

rpath.detrital(Rpath)

Arguments

Rpath

Balanced Rpath model generated by rpath()

Value

Returns a string vector containing the names of Rpath functional groups that are detrital.

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Build the balanced Rpath model and parameter file by calling `rpath`
Rpath <- rpath(Ecosense.EBS)
# Run the rpath.detrital command
detritalGroups = rpath.detrital(Rpath)
# Print out the first few detrital group names
head(detritalGroups)

List of Rpath gears groups

Description

List of gears groups from Rpath object with species type = 3

Usage

rpath.gears(Rpath)

Arguments

Rpath

Balanced Rpath model generated by rpath()

Value

Returns a string vector containing the names of Rpath functional groups that are gear types

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Build the balanced Rpath model and parameter file by calling `rpath`
Rpath <- rpath(Ecosense.EBS)
# Run the groups command
gearGroups = rpath.gears(Rpath)
# Print out the first few gear type group names
head(gearGroups)

Rpath functional group names

Description

Get a character vector of functional group names from an Rpath object (balanced model) or an Rpath.params object (unbalanced model parameters) based on the 'type' input parameter as follows: (0: consumers, 1: producers, 2: detrital, 3: gears, 0<type<1: mixotrophs). Living groups are consumers + producers. Note that mixotrophs are not returned as either consumers or producers, only separately.

Usage

rpath.groups(Rpath)

Arguments

Rpath

Balanced Rpath model generated by rpath()

Value

Returns a string vector containing the names of Rpath functional groups by category (group type).

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Build the balanced Rpath model and parameter file by calling `rpath`
Rpath <- rpath(Ecosense.EBS)
# Run the groups command
groups = rpath.groups(Rpath)
# Print out the first few group names
head(groups)

List of Rpath living groups

Description

List of living groups from Rpath object. Living groups are those species groups with type < 2.

Usage

rpath.living(Rpath)

Arguments

Rpath

Balanced Rpath model generated by rpath()

Value

Returns a string vector containing the names of Rpath functional groups that are living.

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Build the balanced Rpath model and parameter file by calling `rpath`
Rpath <- rpath(Ecosense.EBS)
# Run the rpath.living command
livingGroups = rpath.living(Rpath)
# Print out the first few living group names
head(livingGroups)

List of Rpath mixotroph groups

Description

List of groups from Rpath object with species type between 0 and 1

Usage

rpath.mixotrophs(Rpath)

Arguments

Rpath

Balanced Rpath model generated by rpath()

Value

Returns a string vector containing the names of Rpath functional groups that are mixotrophs

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Build the balanced Rpath model and parameter file by calling `rpath`
Rpath <- rpath(Ecosense.EBS)
# Run the groups command
mixotrophGroups = rpath.mixotrophs(Rpath)
# Print out the first few mixotroph group names
head(mixotrophGroups)

List of Rpath producer groups

Description

List of producer groups from Rpath object with species type = 1

Usage

rpath.producers(Rpath)

Arguments

Rpath

Balanced Rpath model generated by rpath()

Value

Returns a string vector containing the names of Rpath functional groups that are producers

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Build the balanced Rpath model and parameter file by calling `rpath`
Rpath <- rpath(Ecosense.EBS)
# Run the groups command
producerGroups = rpath.producers(Rpath)
# Print out the first few producer group names
head(producerGroups)

Calculate biomass and consumption for multistanza groups

Description

Uses the leading stanza to calculate the biomass and consumption of other stanzas necessary to support the leading stanza.

Usage

rpath.stanzas(Rpath.params)

Arguments

Rpath.params

R object containing the parameters needed to create a Rpath model. This is generated either by the create.rpath.params() or read.rpath.params() functions.

Value

Calculates and adds biomass and consumption for trailing stanza groups. Also adds weight at age and number at age for multi-staza groups.

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), stanzaplot(), webplot(), write.Rpath(), write.rpath.params()


Calculate the derivatives for a time step

Description

Calculates the derivative for a single time step and saves the output

Usage

rsim.deriv(Rsim.scenario, sim.year = 0, sim.month = 0, tstep = 0)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

sim.year

Will inherit from apply functions

sim.month

Will inherit from apply functions

tstep

Sub-monthly time step usually set to 0.

Value

a data.frame object of model group (rows) values for 12 derivatives (columns):

  • Species, character names of model groups

  • DerivT, numeric net flow; Total Gain - Total Loss at the timestep

  • TotGain, numeric Total Gain, all flows into the group at the timestep

  • TotLoss, numeric Total Loss, all flows out of the group at the timestep

  • FoodGain, numeric flows into the group from consuming prey at the timestep

  • DetritalGain, numeric flows into the group from detritus at the timestep

  • FishingGain, numeric flows into the group from fishing at the timestep

  • UnAssimLoss, numeric flows out of the group due to unassimilated consumption at the timestep

  • ActiveRespLoss, numeric flows out of the group due to "heat loss" at the timtestep

  • FoodLoss, numeric flows out of the group from being consumed by predators at the timestep

  • MzeroLoss, numeric flows out of the group due to unaccounted mortality at the timestep

  • FishingLoss, numeric flows out of the group due to fishing at the timestep

  • DetritalLoss, numeric flows out of the group to detritus at the timestep

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Calculate derivatives for year 2, month 6, first timestep
Rsim.deriv <- rsim.deriv(Rsim.scenario, sim.year=2, sim.month = 6, tstep = 0)

Output consumption of each prey by an individual predator group from Rsim run

Description

Extracts a matrix of consumption (in model biomass units) of each prey over time by a particular predator from the Rsim model output of rsim.run().

Usage

rsim.diet(Rsim.output, group)

Arguments

Rsim.output

R object containing the output from rsim.run.

group

Predator group from the Rpath model that is of interest

Value

a numeric matrix of annual (rows) consumption of each prey group (columns)

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Run the Rsim simulation
Rsim.output <- rsim.run(Rsim.scenario, method = "RK4", years = 1:50)
# Extract a preadator's consumption of each prey over the model run
Rsim.diet.whales <- rsim.diet(Rsim.output, group = "whales")

Initialize fishing matrix for Rsim scenario

Description

Creates a matrix for forcing functions related to fishing: (ForcedEffort, ForcedFRate, and ForcedCatch). Default values are set to 1 for ForcedEffort, and to 0 ForcedFRate, and ForcedCatch for all timesteps and groups.

Usage

rsim.fishing(params, years)

Arguments

params

Rsim parameter object generated by rsim.params.

years

A vector of each year of the simulation.

Value

S3 object class Rsim.fishing, a list of 3 objects:

  • ForcedEffort, numeric matrix of monthly (rows) effort multiplier by fleet (columns)

  • ForcedFRate, numeric matrix of annual (rows) fishing mortality rate by biomass group (columns)

  • ForcedEffort, numeric matrix of annual (rows) total catch removal by biomass group (columns)

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create dynamic parameters from Rpath model
Rsim.params <- rsim.params(Rpath)
# Create fishing matrix with default values
Rsim.fishing <- rsim.fishing(Rsim.params, years = 1:50)

Initialize forcing matrix for Rsim scenario

Description

Creates a matrix for forcing functions not related to fishing (ForcedPrey ForcedMort, ForcedRecs, ForcedSearch, ForcedActResp, ForcedMigrate, and ForcedBio). Default values are set to 1 for ForcedPrey ForcedMort, ForcedRecs, ForcedSearch and ForcedActResp, to 0 for ForcedMigrate and to -1 for ForcedBio for all timesteps and groups.

Usage

rsim.forcing(params, years)

Arguments

params

Rsim parameter object generated by rsim.params.

years

A vector of each year of the simulation.

Value

S3 object class Rsim.forcing, a list of 7 objects:

  • ForcedPrey, numeric matrix of monthly (rows) prey forcing by biomass group (columns)

  • ForcedMort, numeric matrix of monthly (rows) mortality multiplier by biomass group (columns)

  • ForcedRecs, numeric matrix of monthly (rows) recruitment multiplier by biomass group (columns)

  • ForcedSearch, numeric matrix of monthly (rows) search rate multiplier by biomass group (columns)

  • ForcedActresp, numeric matrix of monthly (rows) active respiration multiplier by biomass group (columns)

  • ForcedMigrate, numeric matrix of monthly (rows) migration forcing by biomass group (columns)

  • ForcedBio, numeric matrix of monthly (rows) biomass multiplier by biomass group (columns)

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create dynamic parameters from Rpath model
Rsim.params <- rsim.params(Rpath)
# Create forcing matrix with default values
Rsim.forcing <- rsim.forcing(Rsim.params, years = 1:50)

Output biomass removed by each predator for an individual prey group from Rsim run

Description

Extracts a matrix of biomass removed (in model biomass units) for a particular prey by each of its predators from the Rsim model output of rsim.run().

Usage

rsim.mort(Rsim.output, group)

Arguments

Rsim.output

R object containing the output from rsim.run.

group

Predator group from the Rpath model that is of interest

Value

a numeric matrix of annual (rows) biomass removed by each predator group (columns)

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Run the Rsim simulation
Rsim.output <- rsim.run(Rsim.scenario, method = "RK4", years = 1:50)
# Extract a prey's biomass loss from each predator over the model run
Rsim.mort.anchovy <- rsim.mort(Rsim.output, group = "anchovy")

Initial set up for Rsim dynamic simulation

Description

Converts the outputs from Rpath into rates for use in Rsim.

Usage

rsim.params(
  Rpath,
  mscramble = 2,
  mhandle = 1000,
  preyswitch = 1,
  scrambleselfwt = 0,
  handleselfwt = 0,
  steps_yr = 12,
  steps_m = 1
)

Arguments

Rpath

R object containing a static Rpath model.

mscramble

Base value for vulnerability in functional response; default = 2 (mixed response).

mhandle

Base value for handling time in functional response; default = 1000 (off).

preyswitch

Exponent for prey switching in functional response; default = 1 (off).

scrambleselfwt

Value of 1 indicates all predators overlap in the foraging arena while 0 treats predators individually.

handleselfwt

Value of 1 indicates all prey overlap in the arena and contribute to saturation while 0 treats prey individually.

steps_yr

Number of time steps per year; default = 12.

steps_m

Number of time steps per month; default = 1.

Value

Returns an object of class Rsim.params, a list of 39 objects that is passed to the rsim.run function via the rsim.scenario function.

  • NUM_GROUPS, number of total model groups

  • NUM_LIVING, number of living model groups

  • NUM_DEAD, number of detritus model groups

  • NUM_GEARS, number of fishery model groups

  • NUM_BIO, number of living + detritus model groups

  • spname, named NUM_GROUPS+1 length character vector beginning with "Outside" containing names of all model groups

  • spnum, named NUM_GROUPS+1 length character vector beginning with "Outside" numbered 0, containing numbers of all model groups

  • B_BaseRef, named NUM_GROUPS+1 length character vector beginning with "Outside" containing Rpath base biomass of all model groups

  • MzeroMort, named NUM_GROUPS+1 length character vector beginning with "Outside" containing unaccounted mortality, calculated as PB * (1.0 - EE), of all model groups

  • UnassimRespFrac, named NUM_GROUPS+1 length character vector beginning with "Outside" containing the proportion of consumption that goes to detritus of all model groups

  • ActiveRespFrac, named NUM_GROUPS+1 length character vector beginning with "Outside" containing the proportion of consumption that is "lost to heat" for all model groups

  • FtimeAdj, named NUM_GROUPS+1 length character vector beginning with "Outside" containing rate of change of feeding time, currently set to 0 for all model groups

  • FtimeQBOpt, named NUM_GROUPS+1 length character vector beginning with "Outside" containing base QB for all consumer model groups, or base PB for primary producers

  • PBopt, named NUM_GROUPS+1 length character vector beginning with "Outside" containing base PB for all model groups

  • NoIntegrate, named NUM_GROUPS+1 length character vector beginning with "Outside" containing flag set to 0 for high turnover model groups and set to spnum for all others

  • Handleself, named NUM_GROUPS+1 length character vector beginning with "Outside" containing flag for handling time influence, set for all model groups with function argument handleselfwt, default 0 for individual prey handling time

  • Scrambleself, named NUM_GROUPS+1 length character vector beginning with "Outside" containing flag for predator density influence, set for all model groups with function argument scrambleselfwt, default 0 for individual predator density dependent predation

  • PreyFrom, numeric vector length NumPredPreyLinks+1, spnum of prey for each predator prey interaction pair in the model

  • PreyTo, numeric vector length NumPredPreyLinks+1, spnum of predator for each predator prey interaction pair in the model

  • QQ, numeric vector length NumPredPreyLinks+1, base consumption rate for each predator prey interaction pair in the model

  • DD, numeric vector length NumPredPreyLinks+1, handling time effect on functional response for each predator prey pair, set for all model groups with function argument mhandle, default = 1000

  • VV, numeric vector length NumPredPreyLinks+1, vulnerability effect on functional response for each predator prey pair, set for all model groups with function argument mscramble, default = 2

  • HandleSwitch, numeric vector length NumPredPreyLinks+1, prey density dependence effect on functional response for each predator prey pair, set for all model groups with function argument preyswitch, default = 1

  • PredPreyWeight, numeric vector length NumPredPreyLinks+1, relative weight of individual predator to total predators for each predator prey pair, used if scrambleselfwt>0

  • PreyPreyWeight, numeric vector length NumPredPreyLinks+1, relative weight of individual prey to total prey for each predator prey pair, used if handleselfwt>0

  • NumPredPreyLinks, number of predator to prey linkages over all groups in the model

  • FishFrom, numeric vector length NumFishingLinks+1, spnum of landing and discard for each fishery interaction in the model

  • FishThrough, numeric vector length NumFishingLinks+1, spnum of gear type for each fishery interaction in the model

  • FishQ, numeric vector length NumFishingLinks+1, landings or discards relative to base fished group biomass for each fishery interaction in the model

  • FishTo, numeric vector length NumFishingLinks+1, spnum of sink for each fishery interaction in the model ("Outside" for landings or detritus group for discards)

  • NumFishingLinks, number of model group landings and discards to fishery links over all groups in the model

  • DetFrac, numeric vector length NumDetLinks+1, fraction of detritus going to DetTo for each living and detritus group in the model

  • DetFrom, numeric vector length NumDetLinks+1, spnum flowing to detritus for each living and detritus group in the model

  • DetTo, numeric vector length NumDetLinks+1, spnum of detritus sink for each living and detritus group in the model

  • NumDetLinks, number of model group links to detritus over all groups in the model

  • BURN_YEARS, number of model run burn-in (spin up) years, default value -1

  • COUPLED, number to control species interactions, value of 0 allows density dependent non-interacting species, default value 1

  • RK4_STEPS, number of RK4 integration steps per month, default value 4

  • SENSE_LIMIT, numeric vector of multipliers on biomass determining acceptable range for continuing a model run within BURN_YEARS

See Also

Other Rsim functions: extract.node(), rsim.plot(), rsim.run(), rsim.scenario(), rsim.step(), write.Rsim()

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create default dynamic parameters from Rpath model
Rsim.params <- rsim.params(Rpath)

Plot routine for Rsim runs

Description

Plots the relative biomass of each group from an Rsim.output object.

Usage

rsim.plot(Rsim.output, spname = "all", indplot = F)

Arguments

Rsim.output

R object containing the output from rsim.run().

spname

Vector of species names to be displayed. The default "all" will display all group names

indplot

Logical value of whether to plot a single group or multiple groups

Value

Creates a figure of relative biomass

Details

For a detailed example of how to use this plot command please see vignette("RunRsim")

See Also

Other Rsim functions: extract.node(), rsim.params(), rsim.run(), rsim.scenario(), rsim.step(), write.Rsim()


Run a dynamic simulation

Description

Carries out the numerical integration of the Rsim alogrithms.

Usage

rsim.run(Rsim.scenario, method = "RK4", years = 1:100)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

method

Numerical integration method. Either 'AB' for Adams-Bashforth or 'RK4' for 4th order Runge-Kutta.

years

A vector of each year of the simulation.

Value

S3 object class Rsim.output, a list of 16 objects:

  • out_Biomass, numeric matrix of monthly (rows) output biomass values by biomass group (columns) for model run

  • out_Catch, numeric matrix of monthly (rows) output catch values by biomass group (columns) for model run

  • out_Gear_Catch, numeric matrix of monthly (rows) output catch by species/gear/disposition (columns) for model run

  • annual_Catch, numeric matrix of annual (rows) output catch values by biomass group (columns) for model run

  • annual_Biomass, numeric matrix of annual (rows) output biomass values by biomass group (columns) for model run

  • annual_QB, numeric matrix of annual (rows) output consumption:biomass values by biomass group (columns) for model run

  • annual_Qlink, numeric matrix of annual (rows) output consumption values by predator-prey pair (columns) for model run

  • end_state, list of 9 final value vectors for biomass groups, same components as those produced by rsim.state()

  • crash_year, integer flag; -1 no crash or year of model crash

  • pred, named character vector of predators in each predator prey pair

  • prey, named character vector of prey in each predator prey pair

  • Gear_Catch_sp, named character vector of species caught in gears for each disposition

  • Gear_Catch_gear, named character vector of gear types for each species and disposition

  • Gear_Catch_disp, character vector of catch disposition (Landing or Discard) for each species and gear

  • start_state, list of 9 initial value vectors for biomass groups, see output of rsim.state()

  • params, list of 4; 3 dimensioning parameters and 1 biomass group and fleet name vector

See Also

Other Rsim functions: extract.node(), rsim.params(), rsim.plot(), rsim.scenario(), rsim.step(), write.Rsim()

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Run the Rsim simulation
Rsim.output <- rsim.run(Rsim.scenario, method = "RK4", years = 1:50)

Specify a dynamic simulation scenario

Description

Uses a static Rpath model and creates a scenario consisting of 5 list objects: params generated by rsim.params(), start_state generated by rsim.state(), forcing generated by rsim.forcing(), fishing generated by rsim.fishing(), and 'stanzas generated by rsim.stanzas().

Usage

rsim.scenario(Rpath, Rpath.params, years = 1:100)

Arguments

Rpath

R object containing a static Rpath model.

Rpath.params

R object containing the parameters needed to create a Rpath model. This is generated either by the create.rpath.params() or read.rpath.params() functions.

years

A vector of each year of the simulation.

Value

Returns an Rsim.scenario object that can be supplied to the rsim.run() function. Rsim.scenario is a list of 5 objects:

  • params, list of 39 dynamic parameters and vectors derived from an Rpath model, see output of rsim.params()

  • start_state, list of 9 initial value vectors for biomass and size structured stanza groups, see output of rsim.state() and rsim.stanzas()

  • forcing, list of 7 matrices for time series forcing of biological attributes, see output of rsim.forcing()

  • fishing, list of 3 matrices for time series forcing of fishing attributes, see output of rsim.fishing()

  • stanzas, list of 21 parameters and vectors for age structured groups, see output of rsim.stanzas()

See Also

Other Rsim functions: extract.node(), rsim.params(), rsim.plot(), rsim.run(), rsim.step(), write.Rsim()

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)

Ecosense function for Rpath

Description

rsim.sense() draws a random Rsim parameter set from distributions centered on the supplied Rpath parameter estimates. The width of the distribution for each parameter is defined by the data pedigree of the Rpath.params object generated by either create.rpath.params() or read.rpath.params(). The returned Rsim parameter set is functionally equivalent to a params list object created by rsim.scenario().

Usage

rsim.sense(Rsim.scenario, Rpath.params, Vvary = c(0, 0), Dvary = c(0, 0))

Arguments

Rsim.scenario

The rsim.scenario() object containing the initial rsim parameters used as the center of distributions (base model) during random parameter generation.

Rpath.params

Rpath parameter object (unbalanced model) containing the data pedigree generated by either create.rpath.params() or read.rpath.params().

Vvary

length-2 vector with (lower,upper) bounds of vulnerability parameters generated in log-space - 1, Vvary = log(X-1). Thus, the Walters et al. 1997 vulnerability range of (1,+inf) centered on 2 now becomes (-inf,+inf) centered on 0.

Dvary

length-2 vector with (lower,upper) bounds of handling time generation in log-space - 1. Scaled as Vvary, above (-inf,+inf), centered on 0.

Value

Returns a params list object that can be substituted for the params list in an rsim.scenario object.

References

Walters C, Christensen V, Pauly D (1997) Structuring dynamic models of exploited ecosystems from trophic mass-balance assessments. Rev Fish Biol Fish 7:139-172. doi:10.1023/a:1018479526149

Whitehouse GA, Aydin KY (2020) Assessing the sensitivity of three Alaska marine food webs to perturbations: an example of Ecosim simulations using Rpath. Ecol Model 429:16. doi:10.1016/j.ecolmodel.2020.109074

See Also

vignette("ecosense", package = "Rpath") and Other Rpath functions: read.rpath.params(), create.rpath.params(), check.rpath.params(), rpath(), rsim.scenario(), rsim.run()

Examples

# Read in Rpath parameter file and balance model
EBS_bal <- rpath(Ecosense.EBS)
# Create a 100 yr Rsim scenario
EBS_scene <- rsim.scenario(EBS_bal, Ecosense.EBS, years = 1:100)
# Generate a new params list
new_EBS_params <- rsim.sense(EBS_scene, Ecosense.EBS, Vvary = c(-4.5, 4.5), Dvary = c(-4.5, 4.5))
# assign the generated params to the Rsim.scenario object
EBS_scene$params <- new_EBS_params

Initialize list of age structured group (stanza) parameters for dynamic simulation

Description

Creates a list of stanza indices and parameters to be used by rsim.run.

Usage

rsim.stanzas(Rpath.params, state, params)

Arguments

Rpath.params

R object containing the parameters needed to create a Rpath model. This is generated either by the create.rpath.params() or read.rpath.params() functions.

state

List object of state variables generated by rsim.state.

params

Rsim parameter object generated by rsim.params.

Value

a list of 21 objects:

  • Nsplit, number of model groups with stanzas

  • Nstanzas, numeric vector length Nsplit+1, leading 0 for indexing followed by the number of age groups for each model group with stanzas

  • EcopathCode, numeric matrix of Rpath group numbers with Nsplit+1 species rows and Nstanzas+1 age group columns, first column and row empty for indexing

  • Age1, numeric matrix of age in months of first age group with Nsplit+1 species rows, first column and row empty for indexing, second column earliest age in months (0), third column max age in months

  • Age2, numeric matrix of age in months of last age group with Nsplit+1 species rows, first column and row empty for indexing, second column earliest age in months, third column max age in months

  • baseWageS, numeric matrix with rows of monthly weight relative to weight at infinity (Winf) calculated in rpath.stanzas with Nsplit+1 species columns

  • baseNageS, numeric matrix with rows of monthly numbers surviving, calculated in rpath.stanzas with Nsplit+1 species columns

  • baseQageS, numeric matrix with rows of monthly consumption, calculated as WageS^VBGFd in rpath.stanzas with Nsplit+1 species columns

  • Wmat, numeric vector length Nsplit+1, leading 0 for indexing followed by weight at 50% maturity relative to Winf for each model group with stanzas

  • RecPower, numeric vector length Nsplit+1, leading 0 for indexing followed by recruitment power parameter for each model group with stanzas

  • recruits, numeric vector length Nsplit+1, leading 0 for indexing followed by recruits per spawner entered as input to rpath.stanzas

  • VBGFd, numeric vector length Nsplit+1, leading 0 for indexing followed by von Bertalanffy d (default = 2/3) for each model group with stanzas

  • RzeroS, numeric vector length Nsplit+1, leading 0 for indexing followed by recruits per spawner entered as input to rpath.stanzas

  • vBM, numeric vector length Nsplit+1, leading 0 for indexing followed by von Bertalanffy growth coefficient for each model group with stanzas

  • SplitAlpha, numeric matrix of initial monthly (rows) growth coefficients for each model group with stanzas (Nsplit+1 species columns)

  • SpawnX, numeric vector length Nsplit+1, leading 0 for indexing followed by relative strength of spawner-recruit relationship for each model group with stanzas, currently set to 10000, no relationship

  • SpawnEnergy, numeric vector length Nsplit+1, leading 0 for indexing followed by relative energy going to recruitment rather than growth for each model group with stanzas, currently set to 1

  • baseEggsStanza, numeric vector length Nsplit+1, leading 0 for indexing followed by initial estimate of egg output for each model group with stanzas

  • baseSpawnBio, numeric vector length Nsplit+1, leading 0 for indexing followed by initial estimate of spawning biomass (=egg output) for each model group with stanzas

  • RscaleSplit, numeric vector length Nsplit+1, leading 0 for indexing followed by adult to juvenile metric scaling parameter for each model group with stanzas, currently set to 1

  • baseStanzaPred, numeric vector length NUM_GROUPS+1, base consumption (sum of QageS*NageS) for each model group with stanzas in full model group order; 0s entered for non-stanza groups

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(REco.params)
# Create default dynamic parameters from Rpath model
Rsim.params <- rsim.params(Rpath)
# Create state vectors with default values
Rsim.state <- rsim.state(Rsim.params)
# Create stanza object
Rsim.stanzas <- rsim.stanzas(REco.params, Rsim.state, Rsim.params)

Initialize starting state matrix for Rsim scenario

Description

Creates a matrix of starting state variables used by Rsim, including initial biomass and numbers by group, as well as feeding time (Ftime). Default initial values: N = 0, Ftime = 1

Usage

rsim.state(params)

Arguments

params

Rsim parameter object generated by rsim.params.

Value

S3 object class Rsim.state, a list of 3 objects:

  • Biomass, numeric vector of initial biomass by biomass group

  • N, numeric vector of initial numbers by biomass group

  • Ftime, numeric vector of initial feeding time parameter by biomass group

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create dynamic parameters from Rpath model
Rsim.params <- rsim.params(Rpath)
# Create state vectors with default values
Rsim.state <- rsim.state(Rsim.params)

Function to add a time step to an Rsim run

Description

Runs rsim.run and appends the output to a previous Rsim.output. Currently only works with the Adams-Bashforth numerical integration method (AB).

Usage

rsim.step(Rsim.scenario, Rsim.output, method = "AB", year.end)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

Rsim.output

R object containing the output from rsim.run.

method

Numerical integration method. Either 'AB' for Adams-Bashforth or 'RK4' for 4th order Runge-Kutta.

year.end

The final year for the step interval

Value

Returns an Rsim.output object.

See Also

Other Rsim functions: extract.node(), rsim.params(), rsim.plot(), rsim.run(), rsim.scenario(), write.Rsim()


Set Rsim.scenario parameters

Description

Modifies the various parameters of the rsim.scenario() object. Parameters that can be adjusted using this function are: params,start_state, forcing,fishing,stanzas

Usage

set.rsim.scene(
  Rsim.scenario,
  params = NULL,
  start_state = NULL,
  forcing = NULL,
  fishing = NULL,
  stanzas = NULL
)

Arguments

Rsim.scenario

Scenario object that contains all of the rsim rates and forcing functions generated by rsim.scenario().

params

Rsim parameter object generated by rsim.params.

start_state

Rsim starting values object generated by rsim.state()

forcing

Rsim forcing matrix object generated by rsim.forcing()

fishing

Rsim fishing matrix object generated by rsim.fishing()

stanzas

Rsim stanza parameters object generated by rsim.stanzas()

Value

Returns an Rsim.scenario object with the new parameter.

See Also

Other Adjust functions: adjust.fishing(), adjust.forcing(), adjust.scenario()

Examples

# Read in Rpath parameter file and generate balanced model
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
stanzas <- rsim.stanzas(AB.params)
Rsim.scenario.new <- set.rsim.scene(Rsim.scenario,stanzas=stanzas)

Plot routine for Ecopath multistanzas

Description

Plots the biomass composition of multistanza groups from an Rpath.stanzas object.

Usage

stanzaplot(
  Rpath.params,
  StanzaGroup,
  line.cols = c("black", "green", "blue", "red")
)

Arguments

Rpath.params

R object containing the parameters needed to create a Rpath model. This is generated either by the create.rpath.params() or read.rpath.params() functions.

StanzaGroup

The Stanza group's name to be plotted.Valid values are found in the 'stanzas' field of the Rpath parameter file.

line.cols

A vector of four colors used to represent the population biomass, relative number, individual weights, and stanza separation lines.

Value

Creates a figure showing the break down of biomass and number per stanza.

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), webplot(), write.Rpath(), write.rpath.params()

Examples

# Choose group with multiple stanzas
params <- REco.params
stanzaplot(params, StanzaGroup = "Roundfish1")

Plot routine for Ecopath food web

Description

Plots the food web associated with an Rpath object.

Usage

webplot(
  Rpath.obj,
  eco.name = attr(Rpath.obj, "eco.name"),
  line.col = "grey",
  highlight = NULL,
  highlight.col = c("black", "red", "orange"),
  labels = FALSE,
  label.pos = NULL,
  label.num = FALSE,
  label.cex = 1,
  fleets = FALSE,
  type.col = "black",
  box.order = NULL
)

Arguments

Rpath.obj

Rpath model created by rpath().

eco.name

Optional name of the ecosystem. Default is the 'eco.name' attribute from the rpath object created from running rpath().

line.col

The color of the lines between nodes of the food web.

highlight

Group number or name to highlight the connections of that group. Valid values are found in the 'Group' field of the object created from running rpath().

highlight.col

Color of the connections to the highlighted group, vector of length 3. Defaults to black for prey, red for predator, orange for fleet.

labels

Logical whether or not to display group names. If TRUE and label.pos = NULL, no points will be plotted, just label names.

label.pos

A position specifier for the labels. Values of 1, 2, 3, 4 indicate positions below, to the left of, above, and to the right of the points, respectively. A null value will cause the labels to be plotted without the points, assuming that labels = TRUE.

label.num

Logical value indication whether group numbers should be used for labels instead of names.

label.cex

Numeric value of the relative size of the labels within the plot.

fleets

Logical value indicating whether or not to include fishing fleets in the food web plot.

type.col

The color of the points corresponding to the types of the group. Must be of length 1 or 4. Color order will be consumers, primary producers, detrital, and fleet groups.

box.order

Vector of box numbers to change the default plot order. Must include all box numbers

Value

Returns a plot visualization of the food web.

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), write.Rpath(), write.rpath.params()

Examples

# Read in Rpath parameter file, generate and name model object
Rpath.obj <- rpath(AB.params, eco.name = "Anchovy Bay")
# Plot food web diagram with all groups labeled, including fleets
webplot(Rpath.obj, labels = TRUE, fleets = TRUE)
# Plot food web diagram without labels, highlighting connections of cod group
webplot(Rpath.obj, highlight = "cod",fleets = TRUE)

Write function for Rpath food web object

Description

Outputs basic parameters or mortalities from a rpath() object to a .csv or .RData file.

Usage

write.Rpath(x, file = NA, morts = F)

Arguments

x

Rpath model object generated by rpath().

file

file name for resultant file. Need to specify ".csv" or ".RData".

morts

Logical value whether to output basic parameters or mortalities.

Value

Writes a list object or file with the basic parameters or mortalities from an Rpath object.

If morts = F, output reflects the basic parameters of the mass-balanced model, namely:

Group

Vector of group names

type

Vector of group types: 0 = consumer, 1 = producer, 2 = detritus, 3 = fishery

TL

Vector of trophic level for each group, calculated based on mass balance

Biomass

Vector of biomass values for each modeled group

PB

Vector of production:biomass ratios for each modeled group

QB

Vector of consumption:biomass ratios for each modeled group

EE

Vector of ecotrophic efficiency values for each modeled group

GE

Vector of gross efficiency values (production:comsumption ratios) for each modeled group

Removals

Vector of total fishery removals for each modeled group

If morts = T, output reflects calculated mortality values for each group. The number of columns will vary based on how many predators are in the model.

Group

Vector of group names

M0

Vector of natural mortality for each group. Natural mortality = PB * (1-EE)

Fmort

Vector of fishing mortality for each group

M2.XX

Vector of predation mortality, where XX is the name of a predator group

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.rpath.params()

Examples

## Not run: 
# Read in Rpath parameter file, generate model object
x <- rpath(AB.params)
# Saves basic model parameters for all groups to the root directory of users project
write.Rpath(x, file = "output.csv", morts = F)
# Calculates natural mortality (M0), fishing mortality by fleet, and predation mortality by predator (M2) on each group
# Writes output to an Rdata file in the root directory of users project
write.Rpath(x, file = here::here("output.RData"), morts = T)

## End(Not run)

Write Rpath parameters to .csv files

Description

Creates a series of .csv files from an Rpath.params object.

Usage

write.rpath.params(Rpath.params, eco.name, path = "")

Arguments

Rpath.params

R object containing the Rpath parameters. Most likely this was created using create.rpath.params() or read.rpath.params().

eco.name

ecosystem name that will be included in all the file names.

path

location for the output files.

Value

Outputs a series of .csv files named by the provided eco.name and the parameters they represent. For example the model parameters will be named "eco.name_model.csv".

See Also

Other Rpath functions: MTI(), check.rpath.params(), create.rpath.params(), frate.table(), read.rpath.params(), rpath(), rpath.consumers(), rpath.detrital(), rpath.gears(), rpath.groups(), rpath.living(), rpath.mixotrophs(), rpath.producers(), rpath.stanzas(), stanzaplot(), webplot(), write.Rpath()


Write function for Rsim run

Description

Outputs starting biomass, ending biomass, and catch to a .csv or .Rdata file.

Usage

write.Rsim(Rsim.output, file = NA)

Arguments

Rsim.output

object created by the rsim.run() function.

file

file name for resultant file. Need to specify ".csv" or ".RData".

Value

Writes a list object or file with the start and end biomass and catch per group from an Rpath.sim object.

Group

Vector of group names

StartBio

Vector of Biomass values at simulation start

EndBio

Vector of Biomass values at simulation end

BioES

Vector of ratio end:start Biomass values

StartCatch

Vector of Catch values at simulation start

EndCatch

Vector of Catch values at simulation end

CatchES

Vector of ratio end:start Catch values

See Also

Other Rsim functions: extract.node(), rsim.params(), rsim.plot(), rsim.run(), rsim.scenario(), rsim.step()

Examples

# Read in Rpath parameter file and generate model object
Rpath <- rpath(AB.params)
# Create a 50 yr Rsim scenario
Rsim.scenario <- rsim.scenario(Rpath, AB.params, years = 1:50)
# Run the Rsim simulation
Rsim.output <- rsim.run(Rsim.scenario, method = "RK4", years = 1:50)
# Save summary output to a .csv file
write.Rsim(Rsim.output, file = "output.csv")