View source: R/assignLifeStage.R
assignLifeStage | R Documentation |
This function will be called within F.get.catch.data The purpose is to replace the life stage column with an updated assignment based on a clustering routine.
assignLifeStage( DATA, groupN = 1, USEWeight = NULL, output.file = output.file, ... )
DATA |
A data frame of the catch data with the weight measurement, as
returned from |
groupN |
The number of life stage groups to be estimated, see details. |
USEWeight |
Indicate whether weight should not (FALSE) be used in the analytical assignment or allow (NULL) weight to be used, see details. |
output.file |
A text string indicating a prefix to append to all output. |
... |
Arguments passed to |
The function expects the data frame DATA to have column names:
lifeStage
, SampleDate
, FinalRun
, forkLength
, weight
, Unmarked
. The
lifeStage
column is overwritten with the new analytical life stage
assignment.
The life stage assignment is done by each unique value in the FinalRun
column. If the final run is unassigned, no estimation is done and the life
stage is set to Unassigned.
This function relies on several global variables as set by
GlobalVars
: sample.size.forkLength
,
sample.size.forkLengthAndWeight
, weight.prop.forkLength
,
forkLength.mean.diff
, see GlobalVars
for default values.
If the number of fish with a fork length value is less than
sample.size.forkLength
the life stage is set to Unassigned, else the
life stage assignment will continue.
If USEWeight=FALSE
the life stage is analytically assigned using fork
length and date only. If USEWeight=NULL
the weight variable is also
used to assign life stage if the number of fish with a weight measurement
divided by the number of fish with a fork length measurement is greater than
weight.prop.forkLength
AND the number of fish with a weight and fork
length measurements is greater than sample.size.forkLengthAndWeight
.
It is not recommend for the user to specify USEWeight=TRUE
, if done,
weight is only used if the number of fish with a weight measurement is
greater than sample.size.forkLengthAndWeight
else weight is not used.
In all cases fork length and date are used in the life stage assignment and
based on user input and these conditions weight might also be used to assign
life stage.
groupN
may take the values 2, 3, or NULL. If 2 or 3 the analytical
life stage is done with that number of groups. If 2, the group names are
Small and Large, if 3 the group names are Small, Medium, and Large. These
names are chosen to distinguish from the morphometric life stage names. If
groupN=NULL
the analytical life stage begins with 3 groups. If the
minimum pairwise fork length mean difference is less than
forkLength.mean.diff
the number of groups fit is reduced by one. In
this protocol the number of groups can be one, in which case the group name
is All.
The analytical assignment is done through a call to the
Mclust
function in the mclust
package. The
Mclust
function is fitting a mixture of multivariate normal
distributions. The number of distribution fit corresponds to the number of
life stage groups. The Mclust
function returns mean vectors and
variance covariance matrices for each group and the group member ship for
each fish used in the mixture distribution estimation. The group names are
assigned based on the means of the fork length, smallest mean is label as
Small, etc.
In some cases not all of the fish are used in the mixture distribution
estimation. For example if weight is to be used, there could be some fish
without a weight measurement and complete observations are needed for the
Mclust
function. For these fish a minimum Mahalanobis distance is used
for the life stage assignment. For each fish not used in the mixture
distribution estimation, but have at least a fork length or weight, the
Mahalanobis distance from the fish to each of the group means is calculated.
The minimum distance indicates which group that fish will be assigned too.
The concept is that all fish with a recorded fork length will have a group
assignment.
The analytical and morphometric life stage assignments are compared with a
call to assignLSCompare
.
The data frame DATA is returned with the lifeStage
column
being updated by the analytical assignment.
Jared Studyvin, WEST Inc.
assignLSCompare
, GlobalVars
## Not run: assignLifeStage(DATA,groupN,USEWeight) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.