sample4ALK: Sample fish for construction of an age-length key.

Description Usage Arguments Value Examples

View source: R/sample4ALK.R

Description

Samples fish from a data frame of lengths and ages to simulate selecton of fish to be used to construct an age-length key. Fish can either be selected as a fixed number per length category (e.g., 5 fish per 10-mm length category) or as a random sample from the population.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sample4ALK(
  formula,
  data,
  type = c("fixed", "random"),
  n.fixed = 10,
  n.random = 100,
  w = 1,
  startcat = NULL,
  breaks = NULL
)

Arguments

formula

A formula of the form age~length where “age” generically represents a variable in data that contain the observed ages and “length” generically represents a variable in data that contains the observed length measurements.

data

A data.frame that minimally contains the observed age and length measurements in the formula.

type

A string indicating the type of sampling to conduct. See details.

n.fixed

A single numeric that indicates the number of fish to sample per length category when type="fixed".

n.random

A single numeric that indicates the total number of fish to sample when type="random".

w

A single numeric that indicates the width of length categories to create when type="fixed".

startcat

A single numeric that indicates the beginning of the first length category when type="fixed".

breaks

A numeric vector of lower values for the break points of the length categories when type="fixed".

Value

A data.frame similar to data but where some of the ages have been replaced with NA to simulate fish that have NOT been sampled for ages.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## get FSA library for lencat
require(FSA)

## set seed for repeatability
set.seed(5234734)

## Simulated individual ages (random) -- see simAges functions
bg.ages <- simAges(N0=500,A=0.35)

## Simulated lengths, given the above ages
bg.lens <- simLenFromAge(bg.ages,228,0.206,0,8)

## Combine lengths and ages into one data.frame
df <- data.frame(age=bg.ages,len=bg.lens)
# length frequency (10-mm) of the "population"
df$LCat <- lencat(df$len,w=10)
( popLF <- xtabs(~LCat,df) )
round(prop.table(popLF),2)

## Simulate some fish having ages -- random selection of 200 individuals
dfage1 <- sample4ALK(age~len,data=df,type="random",n.random=200)
# length frequency (10-mm) of the "aged" fish
( smpl1LF <- xtabs(~LCat,Subset(dfage1,!is.na(age))) )
round(prop.table(smpl1LF),2)

## Simulate some fish having ages -- 10 fish per 10-mm length category
dfage2 <- sample4ALK(age~len,data=df,type="fixed",w=10,n.fixed=10)
# length frequency (10-mm) of the "aged" fish
( smpl2LF <- xtabs(~LCat,Subset(dfage2,!is.na(age))) )
round(prop.table(smpl2LF),2)

## Example age-length key from the last sample
# get age-sample
df.age <- Subset(dfage2,!is.na(age))
al.raw <- xtabs(~LCat+age,data=df.age)
al.key <- prop.table(al.raw,margin=1)
round(al.key,2)

droglenc/FSAsim documentation built on Feb. 15, 2020, 11:20 p.m.