https://github.com/calbertsen/multi_sam
Connecting single-stock assessment models through correlated survival
https://github.com/calbertsen/multi_sam
fisheries fisheries-stock-assessment r-package stock-assessment stockassessment
Last synced: 7 months ago
JSON representation
Connecting single-stock assessment models through correlated survival
- Host: GitHub
- URL: https://github.com/calbertsen/multi_sam
- Owner: calbertsen
- Created: 2017-09-29T14:07:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-12-19T11:57:38.000Z (10 months ago)
- Last Synced: 2024-12-19T12:40:16.184Z (10 months ago)
- Topics: fisheries, fisheries-stock-assessment, r-package, stock-assessment, stockassessment
- Language: R
- Size: 1.95 MB
- Stars: 5
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
# multiStockassessment
The `multiStockassessment` package extends the [`stockassessment`](https://github.com/fishfollower/SAM) to allow linked stocks (See e.g. Albertsen, C. M., Nielsen, A., and Thygesen, U. H. (2018) Connecting single-stock assessment models through correlated survival. *ICES Journal of Marine Science*, 75(1), 235-244. doi: [10.1093/icesjms/fsx114](https://dx.doi.org/10.1093/icesjms/fsx114)). The package can be installed with `devtools`:
```r
devtools::install_github("calbertsen/multi_SAM", subdir = "multiStockassessment")
```## Short example
To use the `multiStockassessment` package, the individual stocks must first be fitted with the `stockassessment` package and combined to a `samset` using the `c(...)` function.
### Preparing data using stockassessment
The code below loads the North Sea cod data from the stockassessment package, fits it, simulates two new data sets and fit those individually.
```{r,results='hide',warning=FALSE}
library(stockassessment)
data(nscodData)
data(nscodConf)
data(nscodParameters)set.seed(9876)
fit <- sam.fit(nscodData, nscodConf, nscodParameters,sim.condRE = FALSE)datSim <- simulate(fit,nsim=2)
fitSim <- do.call("c",lapply(datSim,function(x)sam.fit(x,nscodConf, nscodParameters)))```
### Creating correlation structure
```{r}
library(multiStockassessment)
```After the simulated data have been fitted and combined by the `c` function, the `multiStockassessment` package can be used to fit a model with correlated survival.
The `suggestCorStructure` function can be used to set up the correlation matrix. The `nAgeClose` argument can be used to construct the banded structures used in the paper. The result is a logical symmetric matrix indicating whether a correlation should be fixed at zero.
The dimension of the matrix is the number of stocks times the number of ages in the data.For instance, `suggestCorStructure(fitSim,nAgeClose=1)` creates a matrix where ages less than 1 appart are correlated between the stocks:
```{r}
cs <- suggestCorStructure(fitSim,nAgeClose=1)
cs
```The `suggestCorStructure` function has several options to configure the correlation structure, and the result can be modified by hand for complete freedom.
### Fitting the model
The model is fitted by the `multisam.fit` function. The function requires a `samset` and a correlaiton structure. By default, the correlation structure given models the partial correlations between cohorts. This can be changed to regular correlations by setting `usePartialCors = FALSE`.
```{r,results="hide",warning=FALSE}
obj <- multisam.fit(fitSim,cs)
``````{r}
obj
```### Investigating the result
Most plotting and table functions from the `stockassessment` package have a corresponding version in `multiStockassessment`.
The fitted correlation structure can be plotted by
```{r}
corplot(obj)
```
Other plotting functions implemented from the `stockassessment` package are
```{r}
fbarplot(obj)
``````{r}
ssbplot(obj)
``````{r}
ssbplot(obj)
``````{r}
tsbplot(obj)
``````{r}
recplot(obj)
``````{r}
catchplot(obj)
``````{r}
srplot(obj)
``````{r}
fitplot(obj,1)
```Note that the `fitplot` function above requires the stock to be specified.
```{r}
fitplot(obj,2)
```### Comparing models
Models can be compared with the `modeltable` function. For instance, the model above can be compared to individual assessments by
```{r,results="hide",warning=FALSE}
cs2 <- suggestCorStructure(fitSim,nAgeClose=0)
obj2 <- multisam.fit(fitSim,cs2)```
```{r}
modeltable(obj,obj2)
```