Description Usage Arguments Details Value Author(s) References See Also Examples
Randomly creates length-at-age data according to a typical von Bertalanffy growth function (VBGF).
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
)
|
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 |
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 ( |
seed |
An integer that can be used to control the seed for the random number generator used in the function. See 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:
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).
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
.
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
.
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.
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).
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.
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.
Repeat the previous all but the first step for all fish to be simulated.
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 dataType
s to return the same data in different formats. See examples.
A data frame in one of four formats as determined by dataType
. The variables that may occur in each data.frame are:
id
: a unique identification for individual fish.
lenCap
: the observed length at the time of capture (corresponds to ageCap
).
ageCap
: the number of completed growing seasons at the time of capture.
ageFracG
: the fractional age of the fish – i.e., number of completed growing seasons plus a decimal representation of the fraction of the current growing seasons completed at the time of capture.
ageFracY
: the fractional age of the fish as a proportion of the sampling year – i.e., number of completed growing seasons plus the Julian sampling date divided by 365 (assumes all years are 365 days).
agePrev
: an age in the fish's growth history. Will be a whole number if backcalc=TRUE
(i.e., length was back-calculated to an age that represents the beginning of a growing season) or a decimal if backcalc=FALSE
(i.e., repeated observations of length may not be at the beginning of a growing season).
len
: the observed length that corresponds to agePrev
.
Which of these variables is returned depends on the dataTYpe
as follows:
‘atCapture’ format: Returns id
, ageCap
, ageFracG
, and lenCap
. Each row corresponds to the observations for an individual fish at the time of capture.
‘long’ format: Returns id
, ageCap
, agePrev
, ageFracG
, len
, and lenCap
. Each row corresponds to one age observation and individual fish are spread across as many rows as ageCap
. If backcalc=TRUE
then there will be one ageFracG
greater than ageCap
(represents “plus” or current season's growth) and all other ageFracG
s will be whole numbers.
‘groupedData’ format: Returns same as ‘long’ format but as a groupedData
object (from the nlme package).
‘wide’ format: returns id
, ageCap
, lenCap
, and lengths-at-age (ageX
; both previous ages and age-at-capture). In ‘wide’ format each row corresponds to a fish and may include several lengths (at previous ages and at-capture).
Derek H. Ogle, dogle@northland.edu. This function was motivated by the simulation methodology shown in Box 2 of Vigliola and Meekan (2009).
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 groupedData
from nlme for how to analyze data in ‘groupedData’ format.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.