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(a4adiags)
#> Loading required package: ggplot2
#> Loading required package: FLCore
#> Loading required package: lattice
#> Loading required package: iterators
#> FLCore (Version 2.6.20.9308, packaged: 2024-11-14 23:24:18 UTC)
#> Loading required package: ggplotFL
#> Loading required package: FLa4a
#> Loading required package: triangle
#> This is FLa4a 1.9.0. For overview type 'help(package="FLa4a")'
library(FLa4a)
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)
}
xval <- a4ahcxval(stock, indices, nyears=5, nsq=3, srmodel=srmod, fmodel=fmod,
qmodel=qmod, vmodel=vmod)
#> Warning: executing %dopar% sequentially: no parallel backend registered
mohnMatrix(xval$stocks, ssb)
#> base -1 -2 -3 -4 -5
#> 2012 28461.57 29865.56 30195.50 29562.62 30032.85 29778.79
#> 2013 34081.72 35428.59 35130.41 34567.14 34485.31 31997.13
#> 2014 30423.14 31155.84 31681.66 31191.75 29685.55 26520.74
#> 2015 28567.41 29631.27 30793.79 30899.53 28432.62 NA
#> 2016 35520.25 36541.37 38345.49 39220.43 NA NA
#> 2017 33901.84 36332.29 38558.82 NA NA NA
#> 2018 30749.29 33455.18 NA NA NA NA
#> 2019 30888.28 NA NA NA NA NA
icesAdvice::mohn(mohnMatrix(xval$stocks, ssb))
#> [1] 0.03930931
icesAdvice::mohn(mohnMatrix(xval$stocks, fbar))
#> [1] 0.0005614943
(Kell_2016?)
(Hyndman_2006?)
FLPKG
at the FLPKG
issue page 1.a4diags
can always be installed
using the devtools
package, by calling