alkPrep: Prepares problematic age-length key matrices for use.

View source: R/alkPrep.R

ageKeyPrepR Documentation

Prepares problematic age-length key matrices for use.

Description

Used to prepare problematic age-length key matrices for use in alkIndivAge. Problems that can be fixed are the deletion of empty rows at the beginning or at the end of the age-length key matrix and the ‘interpolation’ of values in missing rows in the ‘middle’ of the age-length key.

Usage

ageKeyPrep(key, show.msgs = TRUE)

alkPrep(key, show.msgs = TRUE)

Arguments

key

A numeric matrix that contains the problematic age-length key. The rows must sum to 1, the rows must be labeled with the mininum (numeric) value of the length intervals, and the columns must be labeled with numeric ages.

show.msgs

A logical that indicates if process messages should be displayed (TRUE; default).

Details

This function can be used to prepare problematic age-length key matrices for use in alkIndivAge. Problems that can be fixed are the deletion of empty rows at the beginning or at the end of the age-length key matrix and the ‘interpolation’ of values in missing rows in the ‘middle’ of the age-length key. In the case of interpolation, a cell in the missing row is computed by assuming a linear trend between the rows immediately adjacent (both above and below) to the missing row. This results in simply averaging the values in the adjacent rows if only one row is missing in the age-length key matrix.

An alternative to the linear interpolation method is to predict missing values from the fits of general linear or additive models. See the methos in the references for details on using this method.

Value

A matrix that contains the original age-length key matrix sent in key with missing rows either deleted if they were at the beginning or end of the matrix or replaced with interpolated values (see details) if in the middle of the matrix.

IFAR Chapter

12-Age-Length Key.

Author(s)

Derek H. Ogle, dogle@northland.edu

References

Ogle, D.H. 2016. Introductory Fisheries Analyses with R. Chapman & Hall/CRC, Boca Raton, FL.

Berg, C.W. and K. Kristensen. 2012. Spatial age-length key modelling using continuation ratio logits. Fisheries Research 129-130:119-126.

Gerritsen, H.D., D. McGrath, and C. Lordan. 2006. A simple method for comparing age-length keys reveals significant regional differences within a single stock of haddock (Melanogrammus aeglefinus). ICSE Journal of Marine Science 63:1096-1100.

Stari, T., K.F. Preedy, E. McKenzie, W.S.C. Gurney, M.R. Heath, P.A. Kunzlik, D.C. Speirs. 2010. Smooth age length keys: Observations and implications for data collection on North Sea haddock. Fisheries Research 105:2-12.

See Also

See alkIndivAge for using an age-length key to assign ages to individual fish and alkPlot to visualize age-length keys.

Also see functions in the DATRAS package (avaiable at http://www.rforge.net/DATRAS/index.html).

Examples

# create a "good" small ALK matrix
alk <- matrix(c(0.4,0.3,0.3,0.0,
                0.2,0.4,0.3,0.1,
                0.1,0.2,0.4,0.3,
                0.0,0.1,0.4,0.5,
                0.0,0.0,0.2,0.8),
              nrow=5,byrow=TRUE)
rownames(alk) <- c(10,20,30,40,50)
colnames(alk) <- c(2,3,4,5)
addmargins(alk,margin=2)

# Create various "problematic" ALK matrics
alk1 <- alk2 <- alk5 <- alk24 <- alk23 <- alk12 <- alk45 <- alk135 <- alk
alk1[1,] <- NA
alk2[2,] <- NA
alk5[5,] <- NA
alk24[c(2,4),] <- NA
alk23[c(2,3),] <- NA
alk12[1:2,] <- NA
alk45[4:5,] <- NA
alk135[c(1,3,5),] <- NA

# Show how the "problematic" matrices are "fixed"
alk1
alkPrep(alk1)
alk5
alkPrep(alk5)
alk2
alkPrep(alk2)
alk24
alkPrep(alk24)
alk23
alkPrep(alk23)
alk12
alkPrep(alk12)
alk45
alkPrep(alk45)
alk135
alkPrep(alk135)


droglenc/FSAmisc documentation built on Jan. 8, 2023, 12:59 a.m.