Skip to content

Commit 25a98ae

Browse files
Feat issue 71 add linebreaks (#75)
* feat: break lines in .Rmd files at 72 chars #71 - uses vscode Rewrap extension - required a little tinkering, but not much * fix: line break in developer heading Co-authored-by: Kathryn Doering <[email protected]>
1 parent 744dc2d commit 25a98ae

9 files changed

+838
-304
lines changed

01-code-of-conduct.Rmd

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,39 @@
22

33
## FIMS Contributor Conduct
44

5-
All contributors participating and contributing to the FIMS project are expected to adhere to the [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). Briefly, these standards are adopted to ensure a positive and harassment-free enviroment for all participants. Examples of behavior that contributes to a positive environment for our community include:
5+
All contributors participating and contributing to the FIMS project are
6+
expected to adhere to the [Contributor
7+
Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/).
8+
Briefly, these standards are adopted to ensure a positive and
9+
harassment-free enviroment for all participants. Examples of behavior
10+
that contributes to a positive environment for our community include:
611

712
* Demonstrating empathy and kindness toward other people
813
* Being respectful of differing opinions, viewpoints, and experiences
914
* Giving and gracefully accepting constructive feedback
10-
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
11-
* Focusing on what is best not just for us as individuals, but for the overall community
15+
* Accepting responsibility and apologizing to those affected by our
16+
mistakes, and learning from the experience
17+
* Focusing on what is best not just for us as individuals, but for the
18+
overall community
1219

1320
## Supporting Good Conduct
1421

15-
FIMS Community leaders will create default community health files (e.g. CONTRIBUTING, CODE_OF_CONDUCT) to be used in all repositories owned by FIMS.
22+
FIMS Community leaders will create default community health files (e.g.
23+
CONTRIBUTING, CODE_OF_CONDUCT) to be used in all repositories owned by
24+
FIMS.
1625

1726
### Reporting Unacceptable Behavior
1827

19-
Questions about the FIMS Code of Conduct or reports of unacceptable behavior should be sent to [email protected]. Reports will be reviewed by a member of the NOAA Fisheries Office of Science and Technology who is not participating in the FIMS Project [Jim Berkson], but has the full support of FIMS Community Leaders. All reports will be reviewed promptly and fairly.
28+
Questions about the FIMS Code of Conduct or reports of unacceptable
29+
behavior should be sent to [email protected]. Reports will be
30+
reviewed by a member of the NOAA Fisheries Office of Science and
31+
Technology who is not participating in the FIMS Project [Jim Berkson],
32+
but has the full support of FIMS Community Leaders. All reports will be
33+
reviewed promptly and fairly.
2034

2135
### Consequences of Violating Conduct
2236

23-
People who violate the FIMS Contribute Conduct will face meaningful consequences, up to and including explusion from the FIMS Community. The Code of Conduct, as well as consequences for violations, apply equally to all participants.
37+
People who violate the FIMS Contribute Conduct will face meaningful
38+
consequences, up to and including explusion from the FIMS Community. The
39+
Code of Conduct, as well as consequences for violations, apply equally
40+
to all participants.

02-FIMS-Project-Overview.Rmd

Lines changed: 167 additions & 51 deletions
Large diffs are not rendered by default.

03-M1-model-specification.Rmd

Lines changed: 106 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
# M1 Model specification
22

3-
This section describes the implementation of the modules in FIMS in milestone 1. For the first milestone, we must implement enough complexity to adequately test a very standard population model. For this reason, we implement the minimum structure that can run the model described in [Li et al. 2020](). The product will be an age-structured integrated assessment model with two fleets (one survey, one fishery) and two sexes.
3+
This section describes the implementation of the modules in FIMS in
4+
milestone 1. For the first milestone, we must implement enough
5+
complexity to adequately test a very standard population model. For this
6+
reason, we implement the minimum structure that can run the model
7+
described in [Li et al. 2020](). The product will be an age-structured
8+
integrated assessment model with two fleets (one survey, one fishery)
9+
and two sexes.
410

511
## Model variables and bounds
612

713
## Inherited functors from `TMB`
814

915
### Atomic functions
1016

11-
Wherever possible, `FIMS` should not reinvent atomic functions with extant definitions in `TMB`. If there is a need for a new atomic function the development team can add it to `TMB` using the `TMB_ATOMIC_VECTOR_FUNCTION()` macro following the instructions [here](https://kaskr.github.io/adcomp/_book/AtomicFunctions.html#example-adding-new-primitive-function-with-known-derivatives).
17+
Wherever possible, `FIMS` should not reinvent atomic functions with
18+
extant definitions in `TMB`. If there is a need for a new atomic
19+
function the development team can add it to `TMB` using the
20+
`TMB_ATOMIC_VECTOR_FUNCTION()` macro following the instructions
21+
[here](https://kaskr.github.io/adcomp/_book/AtomicFunctions.html#example-adding-new-primitive-function-with-known-derivatives).
1222

1323
### Statistical distributions
1424

15-
All of the statistical distributions needed for the first milestone of `FIMS` are implemented in `TMB` and need not be replicated.
25+
All of the statistical distributions needed for the first milestone of
26+
`FIMS` are implemented in `TMB` and need not be replicated.
1627
Code can be found [here](http://kaskr.github.io/adcomp/group__R__style__distribution.html).
1728

18-
|Distribution | Name|
29+
|Distribution | Name|
1930
| ------------|---------|
2031
|Normal | [dnorm](http://kaskr.github.io/adcomp/dnorm_8hpp.html)|
2132
|Multinomial | [dmultinom](http://kaskr.github.io/adcomp/group__R__style__distribution.html#gafd0ae6b53840267138bb9250115fbe8b)
@@ -28,77 +39,128 @@ where $\mu$ is the mean of the distribution and $\sigma^2$ is the variance.
2839

2940
#### Multinomial Distribution
3041

31-
For $k$ categories and sample size, $n$,
42+
For $k$ categories and sample size, $n$,
3243

3344
$$f(y) = \frac{n!}{y_{1}!... y_{k}!}p^{y_{1}}_{1}...p^{y_{k}}_{k},$$
3445

35-
where $\sum^{k}_{i=1}y_{i} = n$, $p_{i} > 0$, and $\sum^{k}_{i=1}p_{i} = 1$.
46+
where $\sum^{k}_{i=1}y_{i} = n$, $p_{i} > 0$, and $\sum^{k}_{i=1}p_{i} = 1$.
3647

3748
The mean and variance of $y_{i}$ are respectively:
3849

3950
$\mu_{i} = np_{i}$,
4051

4152
$\sigma^{2}_{i} = np_{i}(1-p_{i})$
4253

43-
## Beverton-Holt expected recruitment function
54+
## Beverton-Holt expected recruitment function
4455

45-
For parity with existing stock assessment models, the first recruitment option in FIMS is a Beverton-Holt [cite] parameterized with R0 and h.
56+
For parity with existing stock assessment models, the first recruitment
57+
option in FIMS is a Beverton-Holt [cite] parameterized with R0 and h.
4658

4759
$$R_t =\frac{0.8R_0hS_{t-1}}{0.2R_0\phi_0(1-h) + S_{t-1}(h-0.2)}$$
48-
Where $R_t$ and $S_t$ are mean recruitment and spawning biomass in time $t$, $h$ is Mace-Doonan steepness, and $\phi_0$ are the unfished spawning biomass per recruit. The initial FIMS model will implement a static spawning biomass-per-recruit function, with the ability to overload the method in the future to allow for time-variation in mortality, maturity, and weight-at-age over time to account for changes in spawning biomass per recruit. Deviations are assumed to be lognormally distributed such that realized recruitment is the product of mean recruitment and the exponentiated recruitment deviation.
60+
Where $R_t$ and $S_t$ are mean recruitment and spawning biomass in time
61+
$t$, $h$ is Mace-Doonan steepness, and $\phi_0$ are the unfished
62+
spawning biomass per recruit. The initial FIMS model will implement a
63+
static spawning biomass-per-recruit function, with the ability to
64+
overload the method in the future to allow for time-variation in
65+
mortality, maturity, and weight-at-age over time to account for changes
66+
in spawning biomass per recruit. Deviations are assumed to be
67+
lognormally distributed such that realized recruitment is the product of
68+
mean recruitment and the exponentiated recruitment deviation.
4969
$$R_t = R_t\mathrm{exp}(r_{dev,t}-R^2/2), r_{dev,t} \sim N(0,R^2)$$
5070

51-
However, true $r_{dev,t}$ values are not known, so when using estimated recruitment deviations $\hat{r_{dev,t}}$ the following equation is applied to calculate mean unbiased recruitment $R*_t$ using a bias adjustment factor $b_y=\frac{E[SD(ry)]^2}{\sigma_R^2}$ (Methot and Taylor, 2011).
71+
However, true $r_{dev,t}$ values are not known, so when using estimated
72+
recruitment deviations $\hat{r_{dev,t}}$ the following equation is
73+
applied to calculate mean unbiased recruitment $R*_t$ using a bias
74+
adjustment factor $b_y=\frac{E[SD(ry)]^2}{\sigma_R^2}$ (Methot and
75+
Taylor, 2011).
5276
$$R^*_t=R_t\mathrm{exp}(\hat{r_{dev,t}}-b_y\frac{\sigma_R^2}{2})$$
53-
The recruitment function should take as input the $R$ , $S$ values, the $h$, $ln(R_0)$, and R parameters and $\phi_0$ and return mean and realized recruitment.
54-
77+
The recruitment function should take as input the $R$ , $S$ values, the
78+
$h$, $ln(R_0)$, and R parameters and $\phi_0$ and return mean and
79+
realized recruitment.
80+
5581
## Logistic function with extensions
5682
$$x_i=\frac{1}{1+\mathrm{exp}(-ln(19)(i-\nu_1)/\nu_2)}$$
5783

58-
Where $x_i$ is the quantity of interest (proportion mature, selected, etc.), $i$ is the index (can be age or size or any other quantity),
59-
$\nu_1$ is the index of 50% mature and $\nu_2$ is the difference in the index at 50% and the index at 95% ($\nu_2 = \mathrm{ln}(19)/s$ where
60-
$s$ is the slope parameter from an alternative parameterization). Logistic functions for maturity and selectivity should inherit and extend
61-
upon the base logistic function implementation.
62-
84+
Where $x_i$ is the quantity of interest (proportion mature, selected,
85+
etc.), $i$ is the index (can be age or size or any other quantity),
86+
$\nu_1$ is the index of 50% mature and $\nu_2$ is the difference in the
87+
index at 50% and the index at 95% ($\nu_2 = \mathrm{ln}(19)/s$ where
88+
$s$ is the slope parameter from an alternative parameterization).
89+
Logistic functions for maturity and selectivity should inherit and
90+
extend upon the base logistic function implementation.
91+
6392
## Catch and fishing mortality
6493

65-
The Baranov catch equation relates catch to instantaneous fishing and natural mortality.
94+
The Baranov catch equation relates catch to instantaneous fishing and
95+
natural mortality.
6696

6797
$$ C_{f,a,t}=\frac{F_{f,a,t}}{F_{f,a,t}+M}(1-\mathrm{exp}(-(F_{f,a,t}+M)))N_{a,t}$$
6898

69-
Where $C_{f,a,t}$ is the catch at age $a$ at time $t$ for fleet $f$, $F$ is instantaneous fishing mortality,
70-
$M$ is assumed constant over ages and time in the minimum viable assessment model, $N_a,t$ is the number of
71-
age $a$ fish at time $t$.
99+
Where $C_{f,a,t}$ is the catch at age $a$ at time $t$ for fleet $f$, $F$
100+
is instantaneous fishing mortality, $M$ is assumed constant over ages
101+
and time in the minimum viable assessment model, $N_a,t$ is the number
102+
of age $a$ fish at time $t$.
72103

73104
$$F_{a,t}=\sum_{a=0}^A s_{a,f,t}F$$
74105

75-
$s_a,f$ is selectivity at age $a$ for fleet $f$. Selectivity-at-age is constant over time.
106+
$s_a,f$ is selectivity at age $a$ for fleet $f$. Selectivity-at-age is
107+
constant over time.
76108

77-
Catch is in metric tons and survey is in number, so calculating catch weight ($CW_t$) is done as follows:
109+
Catch is in metric tons and survey is in number, so calculating catch
110+
weight ($CW_t$) is done as follows:
78111
$$ CW_t=\sum_{a=0}^A C_{a,t}w_a $$
79112

80113
Survey numbers are calculated as follows
81114

82115
$$I_t=q\sum_{a=0}^AN_{a,t}$$
83-
Where $I_t$ is the survey index and $q_t$ is survey catchability at time $t$.
116+
Where $I_t$ is the survey index and $q_t$ is survey catchability at time
117+
$t$.
84118

85119

86120

87121
## Modeling loops
88122

89-
This tier associates the expected values for each population section associated with a data source to that data source using a likelihood function. These likelihood functions are then combined into an objective function that is passed to TMB.
90-
91-
The population loop will be initialized at a user-specified age, time increment, and seasonal structure, rather than assuming ages, years, or seasons follow any pre-defined structure. Population categories will be described flexibly, such that subpopulations such as unique sexes, stocks, species, or areas can be handled identically to reduce duplication. Each subpopulation will have a unique set of attributes assigned to it, such that each subpopulation can share or have a different functional process (e.g. recruitment function, size-at-age) than a different category.
92-
93-
Spawning time and recruitment time are user-specified and can occur more than once per year. For the purposes of replicating model comparison project outputs, in milestone 1, all processes including spawning and recruitment occur January 1, but these should be specified via the `spawn_time` and `recruit_time` inputs into FIMS to allow for future flexibility. Spawning and recruitment timing can be input as a scalar or vector to account for multiple options.
94-
95-
Within the population loop, matrices denoting population properties at different partitions (age, season, sex) are translated into a single, dimension-folded index. A lookup table is computed at model start so that the dimension-folded index can be mapped to its corresponding population partition or time partition (e.g. population(sex, area, age, species, time, ...)) so the programmer can understand what is happening. The model steps through each specified timestep to match the data to expected values, and population processes occur in the closest specified timestep to the user-input process timing (e.g. recruitment) across a small timestep that is a predefined constant.
123+
This tier associates the expected values for each population section
124+
associated with a data source to that data source using a likelihood
125+
function. These likelihood functions are then combined into an objective
126+
function that is passed to TMB.
127+
128+
The population loop will be initialized at a user-specified age, time
129+
increment, and seasonal structure, rather than assuming ages, years, or
130+
seasons follow any pre-defined structure. Population categories will be
131+
described flexibly, such that subpopulations such as unique sexes,
132+
stocks, species, or areas can be handled identically to reduce
133+
duplication. Each subpopulation will have a unique set of attributes
134+
assigned to it, such that each subpopulation can share or have a
135+
different functional process (e.g. recruitment function, size-at-age)
136+
than a different category.
137+
138+
Spawning time and recruitment time are user-specified and can occur more
139+
than once per year. For the purposes of replicating model comparison
140+
project outputs, in milestone 1, all processes including spawning and
141+
recruitment occur January 1, but these should be specified via the
142+
`spawn_time` and `recruit_time` inputs into FIMS to allow for future
143+
flexibility. Spawning and recruitment timing can be input as a scalar or
144+
vector to account for multiple options.
145+
146+
Within the population loop, matrices denoting population properties at
147+
different partitions (age, season, sex) are translated into a single,
148+
dimension-folded index. A lookup table is computed at model start so
149+
that the dimension-folded index can be mapped to its corresponding
150+
population partition or time partition (e.g. population(sex, area, age,
151+
species, time, ...)) so the programmer can understand what is happening.
152+
The model steps through each specified timestep to match the data to
153+
expected values, and population processes occur in the closest specified
154+
timestep to the user-input process timing (e.g. recruitment) across a
155+
small timestep that is a predefined constant.
96156

97157
## Expected numbers and quantities
98158

99-
The expected values are calculated as follows in the population.hpp file:
159+
The expected values are calculated as follows in the population.hpp
160+
file:
100161
$$ B_t=\sum_{a=0}^AN_{a,t}w_a$$
101-
where $B_t$ is total biomass in time $t$, $N$ is total numbers, $w_a$ is weight-at-age $a$ in kilograms.
162+
where $B_t$ is total biomass in time $t$, $N$ is total numbers, $w_a$ is
163+
weight-at-age $a$ in kilograms.
102164

103165
$$N_t=\sum_{a=0}^AN_{a,t}$$
104166
where $N_t$ is the total number of fish in time $t$.
@@ -109,17 +171,23 @@ where $N_t$ is the total number of fish in time $t$.
109171
The initial equilibrium recruitment ($R_{eq}$) is calculated as follows:
110172

111173
$$R_{eq} = \frac{R_{0}(4h\phi_{F} - (1-h)\phi_{0})}{(5h-1)\phi_{F}} $$
112-
where $\phi_{F}$ is the initial spawning biomass per recruitment given fishing mortality.
174+
where $\phi_{F}$ is the initial spawning biomass per recruitment given
175+
fishing mortality.
113176

114177
## Likelihood calculations
115178

116-
Age composition likelihood links proportions at age from data to model using a multinomial likelihood function. The multinomial and lognormal distributions, including atomic functions are provided within `TMB`.
179+
Age composition likelihood links proportions at age from data to model
180+
using a multinomial likelihood function. The multinomial and lognormal
181+
distributions, including atomic functions are provided within `TMB`.
117182

118-
Survey index likelihood links estimated CPUE to input data CPUE in biomass using a lognormal distribution. (model.hpp)
183+
Survey index likelihood links estimated CPUE to input data CPUE in
184+
biomass using a lognormal distribution. (model.hpp)
119185

120-
Catch index likelihood links estimated catch to input data catch in biomass using a lognormal distribution. (model.hpp)
186+
Catch index likelihood links estimated catch to input data catch in
187+
biomass using a lognormal distribution. (model.hpp)
121188

122-
Age composition likelihoods link catch-at-age to expected catch-at-age using a multinomial distribution.
189+
Age composition likelihoods link catch-at-age to expected catch-at-age
190+
using a multinomial distribution.
123191

124192
## Statistical Inference:
125193

04-user-guide.Rmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# User guide
22

3-
This section details installation guides for [users](#user-installation-guide). See the [developer installation guide](#developer-installation-guide).
3+
This section details installation guides for
4+
[users](#user-installation-guide). See the [developer installation
5+
guide](#developer-installation-guide).
46

57
## User Installation Guide
68
This section describes how to install the FIMS R package and dependencies.

0 commit comments

Comments
 (0)