User guide: the app's bigeye run in a script
Source:vignettes/jabba3app-02-user-guide.Rmd
jabba3app-02-user-guide.RmdEach step of the app calls a JABBA3 function. This guide runs the app’s example (Atlantic bigeye tuna, Use example data in step 1) with all other settings at the app’s defaults, and repeats it step by step in a script with the same calls. The results are those the app shows for Run 1.
1. Data
Data
The app’s example data are the bigeye catch and two longline CPUE
indices with their log-scale standard errors, from the
iccat dataset in JABBA3.
data(iccat)
bet <- iccat$bet
d <- jb3_data(bet$catch, bet$cpue, bet$se, stock = "Atlantic bigeye tuna")Data in the app’s csv format (one row per record: year,
type, series, value,
se) become the catch, index and standard-error tables of
jb3_data() by reshaping to one column per series:
f <- jabba3app_templates(tempdir(), "data", overwrite = TRUE)
long <- read.csv(file.path(tempdir(), "JABBA3_example_data_bigeye.csv"))
wide <- function(x, col = "value") {
w <- reshape(x[, c("year", "series", col)], idvar = "year", timevar = "series",
direction = "wide")
names(w) <- sub(paste0("^", col, "\\."), "", names(w))
w[order(w$year), ]
}
catch <- wide(long[long$type == "Catch", ])
catch <- data.frame(year = catch$year, catch = rowSums(catch[-1], na.rm = TRUE))
idx <- long[long$type == "Index", ]
d.csv <- jb3_data(catch, wide(idx), wide(idx, "se"), stock = "Atlantic bigeye tuna")
all.equal(d.csv$catch, d$catch, check.attributes = FALSE)
#> [1] TRUE2. Explore data
jbplot_data(d)

The common trend and joint index of the Index agreement and Joint index tabs:
tr <- jb3_trend(bet$cpue, bet$se, type = "relative", state = "rw", variance.weighting = "model",
run = "common trend")
jbplot_trend(tr)
jb3_qtable(tr, digits = 3)
#> index q lci uci log.se n years reference
#> 1 JR2_early 1.00 1.00 1.00 NA 20 1959-1978 TRUE
#> 2 JR2_late 2.36 1.55 3.59 0.215 39 1979-2017 FALSE3. Model setup
Priors: life history
Use example data fills in approximate bigeye biology from the JABBA3 user guide (illustrative only). Calculate gives Leslie r, the generation time, the age at maturity (the lag) and the suggested persistence:
lh <- c(linf = 217.3, k = 0.18, t0 = -0.709, M = 0.35, L50 = 94.8, L95 = 105.8,
a = 2.396e-5, b = 2.9774, s = 0.8, amax = 15)
les <- jb3_leslie(lh)
amat <- lh[["t0"]] - log(1 - lh[["L50"]] / lh[["linf"]]) / lh[["k"]] # age at 50% maturity
lag <- max(0, round(amat)) # production lag
rho <- jb3_rho_gt(les[["gt"]]) # persistence from generation time
c(Leslie.r = les[["r"]], GT = les[["gt"]], amat = amat, lag = lag, rho = rho)
#> Leslie.r GT amat lag rho
#> 0.4267873 7.0529824 2.4752659 2.0000000 0.7300000Priors: shape, r, Hmsy and process error
The app’s defaults: Bmsy/K = 0.4 (Pella-Tomlinson, fixed), r = m × Leslie r / 2 with a CV of 0.5, so that Hmsy = r / m = Leslie r / 2; the process error prior from Hmsy with σR = 0.5 (computed by JABBA3 when the model is built); K from r, one-sided with a CV of 1; and B1/K = 0.9 (CV 0.25). CVs become log-scale SDs, sqrt(log(1 + CV^2)).
cv2ls <- function(cv) sqrt(log(1 + cv^2))
BmsyK <- 0.4
r.med <- jb3_fmsy2r(les[["r"]] / 2, BmsyK = BmsyK, shape = "pella") # r = m x Hmsy
r.prior <- c(r.med, cv2ls(0.5))
pr <- jb3_priors(d, r = r.prior, K = "half+r", K.cv = 1, sigR = 0.5)
m <- uniroot(function(m) m^(1 / (1 - m)) - BmsyK, c(1.0001, 10))$root # shape m for Bmsy/K
c(r = r.med, m = m, Hmsy = r.med / m)
#> r m Hmsy
#> 0.2535362 1.1881129 0.2133940
0.5 * min(0.9 * r.med / m, 1.15) * exp(1.96 * 0.3) # process error prior median
#> [1] 0.172886With a CV on the shape (Uncertainty: With CV), the shape is estimated with a lognormal prior on m, here for Schaefer:
pr.m <- jb3_priors(d, r = c(jb3_fmsy2r(les[["r"]] / 2, BmsyK = 0.5, shape = "pella"), cv2ls(0.5)),
K = "half+r", m = c(2, cv2ls(0.3), 1))
fit.m <- jabba3(d, pr.m, jb3_model(shape = "pella", BmsyK = 0.5))A status prior (Add prior), for example B/Bmsy = 1 in 2010 with a CV of 0.2:
pr.st <- jb3_priors(d, r = r.prior, K = "half+r", sigR = 0.5,
status = jb3_bprior(1, cv = 0.2, year = 2010, type = "bbmsy"))Settings
Standard JABBA (the app’s default): no lag, independent process error, catch error on (SD 0.1), additive observation error with an extra SD estimated for each index:
mo <- jb3_model(shape = "pella", BmsyK = BmsyK, lag = 0, rho = 0,
catch.error = TRUE, sdc = 0.1, obs.error = "additive", sdi.est = TRUE)The other observation-error options: input SEs only
(sdi.est = FALSE), a minimum observation SD
(se.min = 0.2), and the SPiCT form with a prior on sdi
(obs.error = "spict" with
jb3_priors(sdi = c(0.2, cv2ls(0.5), 1))).
A random walk on F (Fishing mortality: random walk, all years) and a lognormal q prior (Catchability, q: lognormal prior, median in index units per unit of biomass) are set like this:
Run model
fit <- jabba3(d, pr, mo, ndraws = 1000, run = "Run 1")
fit$convergence$tier
#> [1] "ok"4. Model results
The summary plot of the Summary tab, then the Fit and production and Tables tabs:
jabbaplot3(fit)
jbplot_fits(fit, years = "all")
jbplot_spphase(fit)
jb3_partable(fit)
#> run par est lci uci cv
#> 1 Run 1 K 1.075711e+06 6.445323e+05 1.795338e+06 0.26133256
#> 2 Run 1 r 2.354694e-01 1.337116e-01 4.146675e-01 0.28872247
#> 3 Run 1 m 1.188115e+00 NA NA NA
#> 4 Run 1 Bmsy/K 4.000000e-01 NA NA NA
#> 5 Run 1 Bmsy 4.302842e+05 2.578129e+05 7.181352e+05 0.26133256
#> 6 Run 1 Fmsy 1.981874e-01 1.125409e-01 3.490130e-01 0.28872247
#> 7 Run 1 MSY 8.527692e+04 7.274138e+04 9.997272e+04 0.08111913
#> 8 Run 1 B1/K 8.899187e-01 5.498706e-01 1.440257e+00 0.24563624
#> 9 Run 1 sigma.proc 9.059814e-02 6.020499e-02 1.363346e-01 0.20850940
#> 10 Run 1 rho 0.000000e+00 NA NA NA
#> 11 Run 1 q1 9.978857e-07 5.556106e-07 1.792219e-06 0.29876079
#> 12 Run 1 q2 1.827073e-06 1.024416e-06 3.258632e-06 0.29520007
#> 13 Run 1 sdi1 5.008976e-02 1.645768e-02 1.524507e-01 0.56786971
#> 14 Run 1 sdi2 4.406166e-02 1.665215e-02 1.165873e-01 0.49645438
#> 15 Run 1 B/Bmsy (2017) 7.491770e-01 5.200232e-01 1.079310e+00 0.18627648
#> 16 Run 1 F/Fmsy (2017) 1.204962e+00 7.688561e-01 1.888434e+00 0.22923450
#> 17 Run 1 B/K (2017) 2.996708e-01 2.080093e-01 4.317240e-01 0.186276485. Check the fit
jb3_convergence(fit)
#> check value pass
#> 1 optimiser code 0.00e+00 TRUE
#> 2 max gradient 2.00e-11 TRUE
#> 3 Hessian positive definite 1.00e+00 TRUE
#> 4 standard errors 1.00e+00 TRUE
#> 5 Newton decrement 6.33e-23 TRUE
#> meaning
#> 1 nlminb reported convergence (0)
#> 2 largest absolute gradient at the optimum (< 0.001)
#> 3 the mode is a proper minimum (curvature in every direction)
#> 4 all delta-method SEs finite
#> 5 expected further decrease of the objective by a Newton step (< 0.001 ok, <= 0.1 warning)
jbplot_runs(fit)
jb3_diags(fit)
#> index n RMSE SDNR runs.p out.3sig bias.p LjungBox.p
#> 1 JR2_early 20 0.09635549 0.5584203 0.106 0 0.7234448 0.662329372
#> 2 JR2_late 39 0.09390813 0.5717921 0.003 0 0.8406524 0.001676375
#> Shapiro.p flag
#> 1 0.1105697 FALSE
#> 2 0.7170649 TRUE
jbplot_priorpost(fit)
Retrospective analysis and hindcast cross-validation. The app runs
one set of peels and derives the hindcast from them;
jb3_hindcast() refits with only the index removed and gives
nearly the same MASE:
rt <- jb3_retro(fit, n = 5)
jbplot_retro(rt)
rt$rho
#> quant rho
#> B B -0.02980447
#> B/Bmsy B/Bmsy -0.03568972
#> F F 0.03735214
#> F/Fmsy F/Fmsy 0.05896584
hc <- jb3_hindcast(fit, n = 5)
jbplot_hcxval(hc, nyears = hc$n)
hc$mase
#> index MASE MASE.adj MAE.PR MAE.base n.eval
#> JR2_early JR2_early NA NA NA NA 0
#> JR2_late JR2_late 1.200827 1.200827 0.1649849 0.1373927 56. Compare runs
Run 2 with the Recommended starting point (the lag at the age at maturity and persistent process error), the other settings unchanged:
mo2 <- jb3_model(shape = "pella", BmsyK = BmsyK, lag = lag, rho = rho,
catch.error = TRUE, sdc = 0.1, obs.error = "additive")
fit2 <- jabba3(d, pr, mo2, ndraws = 1000, run = "Run 2")
fits <- list(`Run 1` = fit, `Run 2` = fit2)
jbplot_trj(fits, type = c("B/Bmsy", "F/Fmsy"))
An ensemble with equal weights:
w <- jb3_weights(fits, weight = "equal")
ens <- jb3_ensemble(fits, weights = w$weight)
jbplot_ensemble(ens)
7. Stock status
The advice trajectories with the threshold and limit, and the Kobe plot in the final year:
jbplot_advice(fit, bthr = 0.5, blim = 0.3)
jbplot_kobe(fit)
8. Forecast
Projections at 0 to 1.25 × Fmsy for ten years, the Kobe II matrix (ICCAT style), and catch advice from a harvest control rule with the target at Fmsy, the trigger at 0.5 Bmsy and the limit at 0.3 Bmsy:
pj <- jb3_project(fit, fmsy = c(0, 0.5, 0.75, 1, 1.25), nyears = 10, imp.years = 1)
jbplot_projection(pj, bthr = 0.5, blim = 0.3)
jb3_kobematrix(pj, what = "all", percent = TRUE)
#> a) Probability that F < Fmsy (%)
#> F/Fmsy 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
#> 0.00 22 100 100 100 100 100 100 100 100 100
#> 0.50 22 100 100 100 100 100 100 100 100 100
#> 0.75 22 100 100 100 100 100 100 100 100 100
#> 1.00 22 100 100 100 100 100 100 100 100 100
#> 1.25 22 0 0 0 0 0 0 0 0 0
#>
#> b) Probability that B > Bmsy (%)
#> F/Fmsy 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
#> 0.00 13 18 46 73 89 95 98 99 100 100
#> 0.50 13 18 33 51 67 78 87 92 93 95
#> 0.75 13 18 26 37 47 58 63 71 78 79
#> 1.00 13 18 19 22 23 27 30 33 35 38
#> 1.25 13 18 13 10 8 8 7 6 6 6
#>
#> c) Probability that F < Fmsy and B > Bmsy (%)
#> F/Fmsy 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
#> 0.00 12 18 46 73 89 95 98 99 100 100
#> 0.50 12 18 33 51 67 78 87 92 93 95
#> 0.75 12 18 26 37 47 58 63 71 78 79
#> 1.00 12 18 19 22 23 27 30 33 35 38
#> 1.25 12 0 0 0 0 0 0 0 0 0
adv <- jb3_advice(fit, imp.years = 1, imp = "Fsq", ftgt = 1, btrigger = 0.5, blim = 0.3)
jbplot_advicecatch(adv)