You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: R/20_dynamics.R
+24-14
Original file line number
Diff line number
Diff line change
@@ -5,31 +5,41 @@
5
5
#' @details
6
6
#' The population model is a single-sex age-structured model in which the number of calves or pups born each year is density dependent, with the extent of density dependence a function of the number of mature adults \eqn{\tildeN}, the fecundity (pregnancy rate) at pre-exploitation equilibrium \eqn{f_0}, the maximum theoretical fecundity rate fmax, the degree of compensation \eqn{z}, and the abundance of individuals aged 1+ \eqn{N_{y+1}^{1+}} relative to carrying capacity \eqn{K^{1+}}. This function can be used alone but is intended to be used with \code{Projections()} to generate multiple simulations. NOTE: Either \code{ConstantCatch} or \code{ConstantF} can be specified, but not both.
7
7
#'
8
-
#' @param S0 Calf/pup survival, a numeric value between 0 and 1
9
-
#' @param S1plus Survival for animals age 1 year and older, a numeric value between 0 and 1
10
-
#' @param K1plus The pre-exploitation population size of individuals aged 1 and older. If this value is unavailable, it can be approximated by using the initial depletion and the estimate of current abundance
11
-
#' @param AgeMat Age at maturity in years (assumed to be age at first parturition - 1).
8
+
#' @param lh.params A list containing life history parameters: \cr\cr
9
+
#' \code{S0} Calf/pup survival, a numeric value between 0 and 1 \cr\cr
10
+
#' \code{S1plus} Survival for animals age 1 year and older, a numeric value between 0 and 1 \cr\cr
11
+
#' \code{K1plus} The pre-exploitation population size of individuals aged 1 and older. If this value is unavailable, it can be approximated by using the initial depletion and the estimate of current abundance \cr\cr
12
+
#' \code{AgeMat} Age at maturity in years (assumed to be age at first parturition - 1) \cr\cr
13
+
#' \code{nages} "Maximum" age, treated as the plus group age. The plus group age can be set equal to the age at maturity +2 years without losing accuracy. Must be greater than \code{AgeMat}.\cr\cr
14
+
#' \code{z} The degree of compensation. The default value is \code{z = 2.39}.\cr\cr
15
+
#' \code{lambdaMax} Maximum steady rate of increase (population growth rate)
12
16
#' @param InitDepl Starting depletion level
13
17
#' @param ConstantCatch Total bycatch each year, expressed as a vector of length \code{nyears}
14
18
#' @param ConstantF vector (length = \code{nyears}) rate of bycatch each year
15
-
#' @param z The degree of compensation. The default value is \code{z = 2.39}.
16
19
#' @param nyears Number of years to project
17
-
#' @param nages "Maximum" age, treated as the plus group age. The plus group age can be set equal to the age at maturity +2 years without losing accuracy. Must be greater than AgeMat.
18
-
#' @param lambdaMax Maximum steady rate of increase (population growth rate)
19
20
#'
20
21
#' @return A list containing a matrix \code{N} of numbers at age (dimensions \code{nyears} (rows) x \code{nages} (columns)) and one vector \code{TotalPop} (a vector of length \code{nyears}), containing the number of age 1+ individuals in the population.
21
-
22
-
# Note, nages = Plus Group Age, and Plus Group Age can = AgeMat+2 without losing accuracy (per AEP 11/30/18)
23
22
#'
24
23
#' @examples
25
24
#' # Generate a time series of abundance for a bowhead whale
Copy file name to clipboardexpand all lines: R/21_projections.R
+25-19
Original file line number
Diff line number
Diff line change
@@ -2,14 +2,20 @@
2
2
#'
3
3
#' @description Generates several projections, stochasticity is in the number of catches from year to year
4
4
#' @importFrom stats rlnorm
5
-
#' @param NOut number of simulations
5
+
#' @param NOut Number of simulations
6
6
#' @param ConstantBycatch Mean and CV of number of animals killed as bycatch per year (assumed lognormal)
7
7
#' @param ConstantRateBycatch Mean and CV of bycatch rate (assumed normal)
8
-
#' @param InitDepl initial depletion. If obs_CV>0, this is the mean depletion.
9
-
#' @param lh.params - life history parameters as a list. The list must include S0, S1plus, K1plus, AgeMat, nages, z, and lambdaMax
10
-
#' @param nyears number of years to do projections
11
-
#' @param obs_CV observation CV. Default to 1 for simple projections
12
-
#' @return list of outputs from simulations: \code{params} contains parameter values for each trajectory as a matrix; \code{trajectories} contains simulation outputs as a matrix; \code{fishing.rates} contain the bycatch rates for each year in each simulation as a matrix; \code{InitDepl} returns the initial depletion for the projections; \code{ConstantBycatch} provides Catch (total individuals killed in bycatch events per year) and CV of Catch (if the user has specified bycatch as a constant number); \code{ConstantRateBycatch} contains Bycatch Rate (additional mortality from bycatch each year) and CV of ByCatch rate. Other parameters are the same as in the \code{dynamics()} function.
8
+
#' @param InitDepl Initial depletion. If obs_CV>0, this is the mean depletion.
9
+
#' @param lh.params Life history parameters as a list. The list must include S0, S1plus, K1plus, AgeMat, nages, z, and lambdaMax.
10
+
#' @param nyears Number of years to do projections
11
+
#' @param obs_CV Observation CV. Default to 1 for simple projections
12
+
#' @return A list of outputs from simulations: \cr\cr
13
+
#' * \code{params} contains parameter values for each trajectory as a matrix; \cr
14
+
#' * \code{trajectories} contains simulation outputs as a matrix; \cr
15
+
#' * \code{fishing.rates} contain the bycatch rates for each year in each simulation as a matrix; \cr
16
+
#' * \code{InitDepl} returns the initial depletion for the projections; \cr
17
+
#' * \code{ConstantBycatch} provides Catch (total individuals killed in bycatch events per year) and CV of Catch (if the user has specified bycatch as a constant number); \cr
18
+
#' * \code{ConstantRateBycatch} contains Bycatch Rate (additional mortality from bycatch each year) and CV of ByCatch rate. Other parameters are the same as in the \code{dynamics()} function.
13
19
#'
14
20
#' @examples
15
21
#' projections(
@@ -33,7 +39,7 @@ projections <- function(NOut,
33
39
obs_CV=0) {
34
40
trajectories<- rep(0, times=nyears)
35
41
fishing.rates<- rep(0, times=nyears)
36
-
params<-0# S0, S1plus, fmax, K1plus, z # also need: nyears = 50, nages = 15
42
+
params<-0
37
43
38
44
# Life history params
39
45
S0<-lh.params$S0
@@ -45,23 +51,23 @@ projections <- function(NOut,
45
51
lambdaMax<-lh.params$lambdaMax
46
52
47
53
# Checks for parameter values
48
-
if (S0>=1) {
54
+
if (lh.params$S0>=1) {
49
55
warning("Calf/pup survival must be between 0 and 1")
50
56
}
51
-
if (S1plus>=1) {
57
+
if (lh.params$S1plus>=1) {
52
58
warning("Adult survival must be between 0 and 1")
53
59
}
54
-
if (AgeMat>nages) {
60
+
if (lh.params$AgeMat>nages) {
55
61
warning("Age at maturity must be less than plus group age")
56
62
}
63
+
if (lh.params$lambdaMax<1) {
64
+
warning("LambdaMax should be greater than 1.
65
+
Typical values are lambdaMax = 1.04 for cetaceans and lambdaMax = 1.12 for pinnipeds.")
66
+
}
57
67
if (!is.na(ConstantBycatch$Catch) &!is.na(ConstantRateBycatch$Rate)) {
58
68
warning("You cannot provide both bycatch as a whole number and as a rate.
59
69
Please specify either ConstantBycatch or ConstantRateBycatch.")
60
70
}
61
-
if (lambdaMax<1) {
62
-
warning("LambdaMax should be greater than 1.
63
-
Typical values are lambdaMax = 1.04 for cetaceans and lambdaMax = 1.12 for pinnipeds.")
64
-
}
65
71
66
72
set.seed(123)
67
73
@@ -79,9 +85,9 @@ projections <- function(NOut,
79
85
sdlog.catches<- sqrt(log(ConstantBycatch$CV^2+1)) # should be ~cv when sd is low (<0.5)
0 commit comments