Package 'a4adiags'

Title: Additional Diagnostics for FLa4a stock Assessment Models
Description: A series of extra diagnostics for the FLa4a model, including prediction skill through restrospective prediction of model inputs and runs tests. Contains ggplot-based plot funtions of diagnostics outputs.
Authors: Iago Mosqueira [aut, cre] , Henning Winker [aut], European Union [fnd, cph]
Maintainer: Iago Mosqueira <[email protected]>
License: EUPL
Version: 0.1.6
Built: 2024-11-20 05:37:31 UTC
Source: https://github.com/flr/a4adiags

Help Index


a4aBioidx Computes observed and expected FLIndexBiomass from a4a fits

Description

a4aBioidx Computes observed and expected FLIndexBiomass from a4a fits

Usage

a4aBioidx(stock, fit, indices)

Arguments

stock

Input FLStock object.

fit

object a4a fit .

indices

Input FLIndices object.

nyears

Number if years for retrospective, defaults to 5.

nsq

Number of years for average biology and selectivity, defaults to 3.

fixed.ks

Is the number of knots is splines with 'year' constant?

Value

FLIndexBiomass

Examples

data(sol274)
 # models
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))
qmod <- list(~s(age, k=3), ~s(age, k=3))
vmod <- list(~s(age, k=3), ~s(age, k=3), ~s(age, k=3))
srmod <- ~factor(year)
# RUN a4a
fit <- sca(stock, indices, fmodel=fmod, qmodel=qmod, vmodel=vmod,sr=srmod)
idxs = a4aBioidx(stock,fit,indices)
idxs$"BTS"@index # observed
idxs$"BTS"@index.q # fitted stored here

Compute a retrospective hindcast cross-validation of a4a stock and indices

Description

The output of a4ahcxval consist of a list with two elements, named 'stocks' and 'indices'. The first is an object of class FLStocks, each a peel from the restrospective run. The second element is a list of FLIndices object. The first FLIndices object, named 'data', is a copy of the input 'indices' argument, with the additoned catch.n slot, if originally missing. The next element, named as the final year of the data set, contains the naive prediction of the input FLIndices, while the remaining elements are the result of a hindcast prediction of the relevant indices, those within the year range of as set ny nyears.

Usage

a4ahcxval(stock, indices, nyears = 5, nsq = 3, check.ks = FALSE, ...)

Arguments

stock

Input FLStock object.

indices

Input FLIndices object.

nyears

Number if years for retrospective, defaults to 5.

nsq

Number of years for average biology and selectivity, defaults to 3.

...

Any submodels and other arguments for the call to sca.

fixed.ks

Is the number of knots is splines with 'year' constant?

Value

A list containing elements 'stocks', of class FLStocks, and 'indices', a list of FLIndices objects. See details for structure of this list.

Examples

data(sol274)
 # models
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))
qmod <- list(~s(age, k=3), ~s(age, k=3))
vmod <- list(~s(age, k=3), ~s(age, k=3), ~s(age, k=3))
srmod <- ~factor(year)
# RUN xval
xval <- a4ahcxval(stock, indices, fmodel=fmod, qmodel=qmod, vmodel=vmod,sr=srmod)
# PLOT result
plotXval(xval$indices)

Plot the runs test result for one or more time series

Description

Plot the runs test result for one or more time series

Usage

## S4 method for signature 'a4aFitSA,FLIndices'
plotRunstest(fit, obs, combine = TRUE)

Arguments

fit

The result of a model fit.

obs

The observations used in the fit.

combine

Should ages be combined by addition, defaults to TRUE.

...

Extra arguments.

Value

An object of class ggplot2::gg

Examples

data(sol274)
plotRunstest(fit, indices)

Plot of FLIndices cross-validation by retrospective hindcast

Description

Plot of FLIndices cross-validation by retrospective hindcast

Usage

plotXval2(x, y = "missing", order = "inverse")

Arguments

x

An FLIndices object of the original observations.

y

A list contaning FLIndices objects returned by a4ahcxval.

order

Order in which retrospective runs are stored, defaults to"inverse".

Value

A ggplot object

Examples

# SEE vignette

Computes Runs Test p-values

Description

Computes Runs Test p-values

Usage

## S4 method for signature 'a4aFitSA,FLIndices'
runstest(fit, obs, combine = TRUE)

Arguments

fit

The result of a model fit.

obs

The observations used in the fit.

combine

Should ages be combined by addition, defaults to TRUE.

...

Extra arguments.

Value

A list with elements 'p.values' and 'pass'.

Examples

data(sol274)
# Call on a a4aFitSA object
runstest(fit, indices)
#
runstest(index(fit), lapply(indices, index))

Data from the 2020 ICES stock assessment of North Sea sole (sol.27.4)

Description

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))

Format

Objects of class FLStock, FLIndices and a4aFitSA

Details

qmod <- list(~s(age, k=3), ~s(age, k=3))

vmod <- list( ~s(age, k=3), ~s(age, k=3), ~s(age, k=3))

srmod <- ~factor(year)