Description Usage Arguments Value Examples
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.
1 2 3 4 5 6 7 8 9 10 |
formula |
A formula of the form |
data |
A data.frame that minimally contains the observed age and length
measurements in the |
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 |
n.random |
A single numeric that indicates the total number of fish to sample
when |
w |
A single numeric that indicates the width of length categories to create
when |
startcat |
A single numeric that indicates the beginning of the first
length category when |
breaks |
A numeric vector of lower values for the break points of the
length categories when |
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.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.