a4adiags.Rmd
a4adiags is an open-source R package that provides a number of extra diagnostics for a4a stock assessment models, complementary of those already availabel in FLa4a.
(Carvalho et al. 2020)
It makes use of the S4 classes and methods developed by the FLR project (http://flr-project.org/R, (Kell et al. 2007)), which simplify the development, testing and use of statistical and simulation models for fisheries management advice.
Diagnostics in FLa4a
library(FLa4a)
#> Loading required package: FLCore
#> Loading required package: lattice
#> Loading required package: iterators
#> FLCore (Version 2.6.15.9016, packaged: 2021-01-18 20:35:15 UTC)
#> Loading required package: triangle
#> Loading required package: copula
#> Loading required package: coda
#> Loading required package: grid
#> Loading required package: gridExtra
#>
#> Attaching package: 'gridExtra'
#> The following object is masked from 'package:FLCore':
#>
#> combine
#> Loading required package: latticeExtra
#> This is FLa4a 1.8.2. For overview type 'help(package="FLa4a")'
library(a4adiags)
#> Loading required package: ggplot2
#>
#> Attaching package: 'ggplot2'
#> The following object is masked from 'package:latticeExtra':
#>
#> layer
#> The following object is masked from 'package:FLCore':
#>
#> %+%
data("sol274")
# fmodel, mimics AAP
fmod <- ~te(replace(age, age > 8, 8), year, k = c(4, 22)) +
s(replace(age, age > 8, 8), k=4) +
s(year, k=22, by=as.numeric(age==1))
# qmodel (GAM, SNS)
qmod <- list(~s(age, k=3), ~s(age, k=3))
# vmodel (catch, GAM, SNS)
vmod <- list(
~s(age, k=3),
~s(age, k=3),
~s(age, k=3))
# srmodel
srmod <- ~factor(year)
# fit
fit <- sca(stock, indices[c("BTS", "SNS")],
srmodel=srmod, fmodel=fmod, qmodel=qmod, vmodel=vmod)
library(doParallel)
ncores <- floor(detectCores() * .75)
if(Sys.info()["sysname"] %in% c("Darwin", "Linux")) {
registerDoParallel(ncores)
} else if(Sys.info()["sysname"] %in% c("Windows")) {
cl <- makeCluster(ncores)
clusterEvalQ(cl = cl, expr = { library(FLa4a); library(FLasher) })
registerDoParallel(cl)
}
res <- a4ahcxval(stock, indices, nyears=5, nsq=3, srmodel=srmod, fmodel=fmod,
qmodel=qmod, vmodel=vmod)
#> Warning in a4ahcxval(stock, indices, nyears = 5, nsq = 3, srmodel = srmod, :
#> Submodels using s(year) or te(year) should have 'k' changed in retro
#> Warning: executing %dopar% sequentially: no parallel backend registered
mase(indices, res$indices[-1])
#> BTS SNS
#> 0.8342634 0.6195470
plotXval(indices, res$indices)
(???)
(???)
FLPKG
at the FLPKG
issue page.1
a4diags
can always be installed using the devtools
package, by calling
library(devtools)
install_github('flr/a4adiags')
Carvalho, Felipe, Henning Winker, Dean Courtney, Maia Kapur, Laurence Kell, Massimiliano Cardinale, Michael Schirripa, et al. 2020. “A Cookbook for Using Model Diagnostics in Integrated Stock Assessments.” Fisheries Research, Accepted manuscript under revision.
Kell, L. T., I. Mosqueira, P. Grosjean, J-M. Fromentin, D. Garcia, R. Hillary, E. Jardim, et al. 2007. “FLR: An Open-Source Framework for the Evaluation and Development of Management Strategies.” ICES Journal of Marine Science 64 (4): 640–46. https://doi.org/10.1093/icesjms/fsm012.