vbDataGen: Randomly create length-at-age data according to a von...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/vbDataGen.R

Description

Randomly creates length-at-age data according to a typical von Bertalanffy growth function (VBGF).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
vbDataGen(
  n,
  Linf,
  K,
  t0,
  paramCV = 0.1,
  SE = NULL,
  SECV = NULL,
  SD = NULL,
  SDCV = NULL,
  minAge = 1,
  maxAge = 9,
  agedist = rep(1, maxAge - minAge + 1),
  growth.per = c(1, 365),
  sample.per = 1,
  dataType = c("atCapture", "long", "groupedData", "wide", "tagrecap"),
  lendigs = getOption("digits"),
  agedigs = 2,
  backcalc = FALSE,
  seed = NULL
)

Arguments

n

Number of individuals to simulate data for.

Linf

The ‘true’ value of the Linf parameter.

K

The ‘true’ value of the K parameter.

t0

The ‘true’ value of the t0 parameter.

paramCV

The coefficient of variation for the parameters for individual fish. See details.

SE

The constant standard error for the mean lengths-at-age within a fish. See details.

SECV

The coefficient of variation for the mean lengths-at-age within a fish. See details.

SD

The constant standard deviation of individuals for the mean lengths-at-age within a fish. See details.

SDCV

The coefficient of variation for individuals for the mean lengths-at-age within a fish. See details.

minAge

The minimum possible age-at-capture for an individual.

maxAge

The maximum possible age-at-capture for an individual.

agedist

A vector of values that are proportional to the percentage of fish expected for each age. This vector must have a length equal to maxAge-minAge+1. See examples.

growth.per

A numeric vector of length 2 that contains the Julian dates for the beginning and ending dates for the period when the fish grows. See details and examples.

sample.per

A numeric vector of length 1 or 2 that contains the Julian beginning and ending date(s) for sampling the fish. If only one value is given, then it is assumed that sampling occurred only on that date. See details and examples.

dataType

The type of data frame that should be returned. See details.

lendigs

A single numeric that controls the number of digits for the length variable.

agedigs

A single numeric that controls the number of digits for the fractional age variable.

backcalc

A logical that indicates whether the lengths at previous ages should be considered to be from back-calculation (TRUE) or repeated observations (e.g., of tagged fish; FALSE, DEFAULT).

seed

An integer that can be used to control the seed for the random number generator used in the function. See details.

Details

This function can be used to generate random growth data, in one of four formats (see ‘return’ section and examples below) controlled by dataType.

The essential steps for constructing the simulated data are as follows:

  1. Use Linf, K, and t0 to set ‘true’ values for the three parameters in a typical VBGF (see growthFunShow described in growthModels in FSA for the equation of this parameterization).

  2. For each fish, generate a random age-at-capture (i.e., number of completed growing seasons) between minage and maxage from the probability distribution for each age in probdist.

  3. Add a fractional age to the ages from the previous step and store in ageFracG. By defaut, the sample.per is the first day of the growth.per, so ageCap and ageFracG will be the same. However, if sample.per is not a single day equal to the first day of the growth.per, then ageFracG will be greater than ageCap.

  4. For each fish, generate random values for Linf, K, and t0 from a normal distribution with a mean of Linf, K, and t0 and a standard deviation derived from each of Linf, K, and t0, respectively, times paramCV. This step is used to model different parameter values for each fish.

  5. For each fish, generate the mean length at each ageFracG in the fish's life (i.e., if the fish is five years old, then a random length for ages one through five) according to the typical VBGF and the random parameters determined in the previous step for that fish. These means are deterministic within a fish, but not among fish (because of the previous step).

  6. For each fish, add a random error to the mean lengths-at-age from the previous step. These random errors are from a normal distribution with a mean of 0 and a standard error given by SE or SECV times the mean length-at-age. This step is used to model random error in the mean lengths-at-age within an individual fish.

  7. For each fish, add a random error to the mean lengths-at-age from the previous step. These random errors are from a normal distribution with a mean of 0 and a standard deviation given by SD or SDCV times the mean length-at-age. This step is used to model random error of individual lengths around the mean lengths-at-age within an individual fish.

  8. Repeat the previous all but the first step for all fish to be simulated.

  9. Store the data for all fish in a data.frame, modify that data.frame to match the format required by dataType, and return the data.frame.

Note that seed can be used to control the random seed used by the function. Use the same seed with different dataTypes to return the same data in different formats. See examples.

Value

A data frame in one of four formats as determined by dataType. The variables that may occur in each data.frame are:

Which of these variables is returned depends on the dataTYpe as follows:

Author(s)

Derek H. Ogle, dogle@northland.edu. This function was motivated by the simulation methodology shown in Box 2 of Vigliola and Meekan (2009).

References

Vigliola, L. and M.G. Meekan. 2009. The back-calculation of fish growth from otoliths. Chapter 6 (pp. 174-211) in B.S. Green et al. (eds.), Tropical Fish Otoliths: Information for Assessment, Management and Ecology, Reviews: Methods and Technologies in Fish Biology and Fisheries 11.

See Also

See groupedData from nlme for how to analyze data in ‘groupedData’ format.

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
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
###########################################################
## At-capture (observation) format examples
# Use CV as errors for means and individuals, sample at
#   beginning of growth season, uniform age distribution
vbcap1 <- vbDataGen(100,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,lendigs=1)
head(vbcap1)
plot(lenCap~ageCap,data=vbcap1,pch=19,col=rgb(0,0,0,1/5))

# Use constant errors for means and individuals, sample at
#   beginning of growth season, uniform age distribution
vbcap2 <- vbDataGen(100,Linf=30,K=0.2,t0=-0.2,SE=2,SD=0.5,lendigs=1)
head(vbcap2)
plot(lenCap~ageCap,data=vbcap2,pch=19,col=rgb(0,0,0,1/5))
xtabs(~ageCap,data=vbcap2)

# Use constant errors for means and individuals, sample at
#   beginning of growth season, non-uniform age distribution
#   (i.e., relatively few young and old fish)
ad <- c(1,1,2,4,4,4,2,1,1)
vbcap3 <- vbDataGen(100,Linf=30,K=0.2,t0=-0.2,agedist=ad,SECV=0.02,SDCV=0.04,lendigs=1)
head(vbcap3)
plot(lenCap~ageCap,data=vbcap3,pch=19,col=rgb(0,0,0,1/5))
xtabs(~ageCap,data=vbcap3)

# Use CV as errors for means and individuals, uniform age
#   distribution, sample throughout the growth season,
#   leads to fractional ages
# Assumed fish growth period (make a Julian date)
growth.per.date <- c("1-Apr-2010","21-Oct-2010")
( growth.per <- strptime(growth.per.date,"%d-%b-%Y")$yday+1 )
# Assumed sampling period (make a Julian date)
sample.per.date <- c("15-Apr-2010","1-Jun-2010")
( sample.per <- strptime(sample.per.date,"%d-%b-%Y")$yday+1 )
vbcap4 <- vbDataGen(100,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,lendigs=1,
                    growth.per=growth.per,sample.per=sample.per)
head(vbcap4)
plot(lenCap~ageCap,data=vbcap4,pch=19,col=rgb(0,0,0,1/5))
points(lenCap~ageFracG,data=vbcap4,pch=19,col=rgb(1,0,0,1/5))
points(lenCap~ageFracY,data=vbcap4,pch=19,col=rgb(0,1,0,1/5))

# Use CV as errors for means and individuals, sample at
#   beginning of growth season, uniform age distribution
#   but set a non-default minimum age
vbcap5 <- vbDataGen(100,Linf=30,K=0.2,t0=-0.2,minAge=3,SECV=0.02,SDCV=0.04,lendigs=1)
head(vbcap5)
plot(lenCap~ageCap,data=vbcap5,pch=19,col=rgb(0,0,0,1/5))

###########################################################
## Long (ungrouped format) ... repeated measures
# Use CV as errors for means and individuals, sample at
#   beginning of growth season, uniform age distribution
vblong1 <- vbDataGen(10,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,
                     dataType="long",lendigs=1)
head(vblong1,n=15)

# Use CV as errors for means and individuals, uniform age
#   distribution, sample throughout the growth season
#   (seasons set above), leads to fractional ages
vblong <- vbDataGen(10,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,lendigs=1,
                    growth.per=growth.per,sample.per=sample.per,dataType="long")
head(vblong,n=15)

###########################################################
## long (grouped format) ... repeated measures
# Use CV as errors for means and individuals, sample at
#   beginning of growth season, uniform age distribution
vbgrp1 <- vbDataGen(10,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,
                    dataType="groupedData",lendigs=1)
head(vbgrp1)
if (require(lattice)) plot(vbgrp1)

# Just errors in parameters (i.e., models unique parameters
# for each fish but no variability around the VBGF for an
# individual fish).
vbgrp2 <- vbDataGen(10,Linf=30,K=0.2,t0=-0.2,SE=0,SD=0,dataType="groupedData",lendigs=1)
head(vbgrp2)
if (require(lattice)) plot(vbgrp2)

###########################################################
## wide format ... repeated measures
# Use CV as errors for means and individuals, sample at
#   beginning of growth season, uniform age distribution
vbwide1 <- vbDataGen(10,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,
                     dataType="wide",lendigs=1)
head(vbwide1)

###########################################################
## Tag-recapture format data
# Use CV as errors for means and individuals, sample at
#   beginning of growth season, uniform age distribution
vbtag1 <- vbDataGen(100,Linf=30,K=0.2,t0=-0.2,minAge=3,SECV=0.02,SDCV=0.04,
                    lendigs=1,dataType="tagrecap")
head(vbtag1)

# Use CV as errors for means and individuals, uniform age
#   distribution, sample throughout the growth season,
#   leads to fractional ages ... more interesting
vbtag2 <- vbDataGen(100,Linf=30,K=0.2,t0=-0.2,minAge=3,SECV=0.02,SDCV=0.04,lendigs=1,
                    growth.per=growth.per,sample.per=sample.per,dataType="tagrecap")
head(vbtag2)

###########################################################
# Back-calculated-like format
# Use CV as errors for means and individuals, uniform age
#   distribution, sample throughout the growth season,
#   leads to fractional ages
vbBClong1 <- vbDataGen(10,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,lendigs=1,
                       growth.per=growth.per,sample.per=sample.per,
                       dataType="long",backcalc=TRUE)
head(vbBClong1,n=15)

###########################################################
## Use seed to get same "fish" in different formats
sd <- 1534756   # set seed
# generate three types of data using same seed
( vbcapA <- vbDataGen(3,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,lendigs=1,
                      growth.per=growth.per,sample.per=sample.per,seed=sd) )
( vblongA <- vbDataGen(3,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,dataType="long",
                       growth.per=growth.per,sample.per=sample.per,lendigs=1,seed=sd) )
( vbwideA <- vbDataGen(3,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,dataType="wide",
                       growth.per=growth.per,sample.per=sample.per,lendigs=1,seed=sd) )
( vbBCA <- vbDataGen(3,Linf=30,K=0.2,t0=-0.2,SECV=0.02,SDCV=0.04,dataType="long",
                     growth.per=growth.per,sample.per=sample.per,lendigs=1,
                     seed=sd,backcalc=TRUE) )
# Note that back-calculated results do not maintain same fish measurements

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