| age.key {FSA} | R Documentation |
This function uses either the semi- or completely-random methods to assign ages to individual fish in a length-sample according to the information in a supplied age-length key.
age.key(key, dl, cl, ca="age", type = "SR")
key |
A numeric matrix containing the age-length key. |
dl |
A data frame containing the fish in the length-sample. |
cl |
A number or character indicating which column of dl contains the length measurements. |
ca |
A number or character indicating which column of dl should receive the age assignments. |
type |
A string indicating whether to use the semi-random (type="SR", default) or completely-random (type="CR") techniques for assigning ages to individual fish. |
The age-length key sent in key must contain the range of length intervals present in the length sample sent in dl. If it does not then the function will stop with an error message. The age-length key must be constructed with length intervals as rows and age categories as columns.
The width of the length interval categories is determined from the first two row names of the age-length key matrix.
Assigned ages will be stored in the column identified in ca. If this argument is omitted then a new column labeled as age will will be created.
The original data frame in dl is returned with assigned ages added to the ca column or in an additional column labeled as age.
Derek H. Ogle, dogle@northland.edu
Isermann, D.A. and C.T. Knight. 2005. A Computer Program for Age-Length Keys Incorporating Age Assignment to Individual Fish. North American Journal of Fisheries Management, 25:1153-1160.
data(WR79) # create the age and length samples from the data frame WR.age <- subset(WR79, !is.na(age)) WR.len <- subset(WR79, is.na(age)) # find smallest length in age sample -- create appropriate length categories summary(WR.age$len) WR.age.mod <- lencat(WR.age,"len",startcat=35,w=5,drop.levels=TRUE) # create age-length key raw <- table(WR.age.mod$LCat, WR.age.mod$age) WR.key <- prop.table(raw, margin=1) # apply age-length key to length sample WR.len.mod <- age.key(WR.key,WR.len,cl="len",ca="age") head(WR.len.mod) # combine original age sample with new length sample and summarize WR.comb <- rbind(WR.age, WR.len.mod) table(WR.comb$age) tapply(WR.comb$len, WR.comb$age, mean)