prepRECA: Prepare data for R-ECA

Description Usage Arguments Details Value

View source: R/prepRECA.R

Description

Checks and reformats data as required by eca.estimate and eca.predict

Usage

1
2
3
4
5
prepRECA(samples, landings, fixedEffects, randomEffects,
  carEffect = NULL, neighbours = NULL, nFish = NULL,
  ageError = NULL, minAge = NULL, maxAge = NULL, maxLength = NULL,
  lengthResolution = NULL, testMax = 1000, date = NULL,
  month = NULL, quarter = NULL)

Arguments

samples

data.table() with samples, each row corresponding to one sampled fish. Contains columns:

catchId

Column identifying the catch that the sample was taken from. Typically a haul or a landing.

sampleId

Column identifying the sample. If only one sample is taken for each catch. This can be set equal to catchId

date

POSIXct() Date of catch

Age

integer() Age of fish

Length

numeric() Length of fish in cm. Must be complete (no NAs)

Weight

numeric() Weight of fish in kg. Fish with missing values will not be included in Weight-given-length model.

...

Additional columns which may be used as covariates as covariates. Type of covariate must be sepcified in 'fixedEffects', 'randomEffects' or 'carEffect'

landings

data.table() with total landings, each row corresponding to one cell. Contains columns:

LiveWeightKG

numeric(). Total landings (Live/Round weight in Kg) for the cell

...

Additional columns which may be used as covariates. Covariates in landings define each cell. Type of covariate must be sepcified in 'fixedEffects', 'randomEffects' or 'carEffect'

fixedEffects

character() vector specifying fixed effects. Corresponding columns must exists in samples and landings.

randomEffects

character() vector specifying random effects. Corresponding columns must exists samples (may also exist in landings).

carEffect

character() specifying a random effect with conditional autoregressive coefficient. Corresponding columns must exists samples (may also exist in landings).

neighbours

list() specifying the neighbourhood-structure for the carEffect. neighbours[a] should provide a vector of neighbours to a. May be NULL of no carEffect is used.

nFish

data.table() specifying the number of fish in the part of the catch that each sample was taken from. Not alwaus needed. See details. Columns:

ageError

matrix() specifying the probability of read age (rows), given true age (columns). Row and column names specify the ages. If NULL, a unit matrix is assumed (No error in age reading).

minAge

lowest age to include in model. If NULL, minimal age in samples is used. Age range must match any age error matrix provided (ageError)

maxAge

highest age to include in model. If NULL, maximal age in samples is used. Age range must match any age error matrix provided (ageError)

maxLength

longest length to include in model. If NULL, maximal length in samples is used.

lengthResolution

desired resolution for length groups. If NULL minimal difference in first testMax records are used.

testMax

The largest number of record to inspect for deriving lengthResolution.

date

POSIXct() vector, matching the number of rows in 'landings', date of catch, see details.

month

integer() vector, matching the number of rows in 'landings', month of catch (1 for January, etc.), see details.

quarter

integer() vector, vector, matching the number of rows in 'landings', quarter of catch (1 for Q1, etc.), see details.

sampleID

Column idenitfying the sample, defined as for 'samples'

count

Estimated number of fish in the part of the catch the sample was taken from

Details

The cell definition is specified by 'landings'. The type of covariates are specified in fixedEffects, randomEffects and carEffect. All fixed effects, as well as any car-effect, must be included in the cell definition. All covariates must occur in samples.

The parameters 'date', 'month', and 'quarter' are used to set the temporal resolution for catch at age prediction. Provide exactly one of these, and set the other ones to NULL. Temporal resolution need not match any temporal covariate used. One can for example run with month, even if Quarter is a covariate in the model. Note that resolution is sensitive to data volume. If you get errors in prediction with E_p(a) = nan, consider trying with quarter.

neighbours must be symetric, so that b %in% neighbours[a], implies a %in% neighbours[b]

nfish is only needed when several samples may be taken from the same catch. If these are stratified in any way (e.g. pre-sorting by size or sex), an estimate of strata sizes must be given (count). If these are replicate samples from the same selection frame, an estimate of the total catch may be given.

output GlobalParameters: While outputs AgeLength, WeightLength and Landings are complete and ready for R-ECA runs. This function populates the list of GlobalParameters only partially. Run parameters have to be added afterwards.

Value

list() with elements:

AgeLength

input needed for eca.estimate and eca.predict

WeightLength

input needed for eca.estimate and eca.predict

Landings

input needed for eca.estimate and eca.predict

GlobalParameters

input needed for eca.estimate and eca.predict. see details

CovariateMaps

Mapping of values for each covariate in landings and samples (including catchId) to integer value used in R-ECA.


edvinf/prepRECA documentation built on Nov. 11, 2019, 6:30 a.m.