Learn R Programming

SlotLim (version 0.0.2)

rb: rb

Description

Calculates the proportional rate of change in an abundance or biomass index (rb) between consecutive data points using one of three methods:

"annual"

Change between the two most recent data points: \((x_1 - x_2)/x_2\). Requires at least 2 values.

"1over2"

Change between the most recent value and the mean of the two values prior: \((x_1 - \bar{x}_{2:3})/\bar{x}_{2:3}\). Requires at least 3 values.

"2over3"

Change between the mean of the two most recent values and the mean of the three values prior: \((\bar{x}_{1:2} - \bar{x}_{3:5})/\bar{x}_{3:5}\). Requires at least 5 values.

Usage

rb(
  b_index = NULL,
  method = c("annual", "1over2", "2over3"),
  na.rm = FALSE,
  digits = NULL
)

Value

A numeric scalar: the proportional rate of change rb. Positive values indicate an increase; negative values indicate a decrease.

Arguments

b_index

Numeric vector of abundance or biomass indices in descending time order (most recent first).

method

Character string; one of "annual" (default), "1over2", or "2over3".

na.rm

Logical; if TRUE, NAs are removed before computing. If FALSE (default) and NAs are present in the needed positions, the result may be NA.

digits

Optional integer. If supplied, the result is rounded using round(x, digits). If NULL (default), full precision is returned.

Details

Validates that sufficient data are available for the chosen method and guards against (near-)zero denominators. If a needed denominator is NA (after na.rm) or numerically zero, an error is thrown.

See Also

TBA

Examples

Run this code
cpue <- c(0.75, 0.70, 1.49, 1.20, 1.10)  # most recent first
rb(b_index = cpue) # annual method by default
rb(b_index = cpue, method = "1over2")
rb(b_index = cpue, method = "2over3")

cpue2 <- c(0.75, NA, 1.49, 1.20, 1.10)
rb(cpue2, method = "1over2", na.rm = TRUE, digits = 2)

Run the code above in your browser using DataLab