| wrAdd | R Documentation |
Returns a vector that contains the relative weight specific to each species for all individuals in an entire data frame.
wrAdd(wt, ...)
## Default S3 method:
wrAdd(
wt,
len,
spec,
thesaurus = NULL,
units = c("metric", "English"),
WsOpts = NULL,
...
)
## S3 method for class 'formula'
wrAdd(wt, data, thesaurus = NULL, units = c("metric", "English"), ...)
wt |
A numeric vector that contains weight measurements or a formula of the form |
... |
Not used. |
len |
A numeric vector that contains length measurements. Not used if |
spec |
A character or factor vector that contains the species names. Not used if |
thesaurus |
A named list for providing alternative species names (the values in the list) that correspond to specific names in |
units |
A string that indicates whether the weight and length data in |
WsOpts |
A named list that provides specific choices for |
data |
A data.frame that minimally contains variables of the the observed lengths, observed weights, and the species names given in the |
This computes a vector that contains the relative weight specific to each species for all individuals in an entire data frame. The vector can be appended to an existing data.frame to create a variable that contains the relative weights for each individual. The relative weight value will be NA for each individual for which a standard weight equation does not exist in WSlit, a standard weight equation for the units given in units= does not exist in WSlit, or if the individual is shorter or longer than the lengths for which the standard weight equation should be applied. Either the linear or quadratic equation has been listed as preferred for each species, so only that equation will be used.
The species names in species must match the spelling and capitalization of species in WSlit. Use wsVal() to see a list of all species for which standard weight equations exist in WSlit and, more importantly, how the species names are spelled and capitalized.
The thesaurus argument may be used to relate alternate species names to the species names used in WSlit. For example, you (or your data) may use “Bluegill Sunfish”, but “Bluegill” is used in WSlit. The alternate species name can be used here if it is defined in a named vector (or list) given to thesarus=. The alternate species name is the value and the species name in PSDlit is the name in this vector/list - e.g., c("Bluegill"="Bluegill Sunfish"). See the examples for a demonstration.
Some species have length categories separated by sub-group. For example, length categories exist for both lentic and lotic populations of Brown Trout. The length values for a sub-group may be obtained by either including the species name in species and the sub-group name in group in WsOpts or by using the combined species and sub-group name, with the sub-group name in parentheses, in species. Both methods are demonstrated in the examples. Note that an error is returned if a species has sub-groups but neither method is used to define the sub-group.
Some (few) species have more than one equation listed in WSlit (for the specified units). In these instances the user must select one of the equations to use with WsOpts. WsOpts is a list of lists where the inside list contains one or more of group, ref, or method (see WSlit) required to specify a single equation for a particular species, which is the name of the inner list. See the examples for an illustration of how to use WsOpts.
See examples and this article for a demonstration.
A numeric vector that contains the computed relative weights, in the same order as in data=.
8-Condition.
Derek H. Ogle, DerekOgle51@gmail.com
Ogle, D.H. 2016. Introductory Fisheries Analyses with R. Chapman & Hall/CRC, Boca Raton, FL.
See wsVal, WSlit, and psdAdd for related functionality. See mapvalues for help in changing species names to match those in WSlit.
#===== Simple example with 3 species, 2 in WSlit ... nothing unusual
tmp <- subset(PSDWRtest,
species %in% c("Yellow Perch","Iowa Darter","Largemouth Bass"),
select=c("species","len","wt"))
peek(tmp,n=10)
#----- Add Wr variable ... using formula interface
tmp$wr1 <- wrAdd(wt~len+species,data=tmp)
#----- same but with non-formula interface
tmp$wr2 <- wrAdd(tmp$wt,tmp$len,tmp$species)
#----- same but using dplyr
if (require(dplyr)) {
tmp <- tmp %>%
mutate(wr3=wrAdd(wt,len,species))
}
#----- examine results
peek(tmp,n=10)
#===== Simple example with only one species in the data.frame
tmp <- subset(PSDWRtest,species %in% c("Yellow Perch"),
select=c("species","len","wt"))
tmp$wr <- wrAdd(wt~len+species,data=tmp)
peek(tmp,n=6)
#===== Example of species with sub-groups but only 1 sub-group in data.frame
#----- Group not in species name so must specify group with WsOpts
tmp <- subset(PSDWRtest,species=="Brown Trout" & location=="Trout Lake",
select=c("species","len","wt"))
tmp$wr1 <- wrAdd(wt~len+species,data=tmp,
WsOpts=list("Brown Trout"=list("group"="lotic")))
#----- Group in species name so don't specify group with WsOpts
tmp$species2 <- "Brown Trout (lotic)"
tmp$wr2 <- wrAdd(wt~len+species2,data=tmp) # note use of species2
peek(tmp,n=6)
#===== Example of species with sub-groups and 2 sub-groups in data.frame
tmp <- subset(PSDWRtest,species=="Brown Trout",
select=c("species","location","len","wt"))
#----- Must create "species" with sub-groups in name
#----- Many ways to do this, this is just one example for this case
tmp$species2 <- ifelse(tmp$location=="Trout Lake",
"Brown Trout (lotic)","Brown Trout (lentic)")
tmp$wr <- wrAdd(wt~len+species2,data=tmp) # note use of species2
peek(tmp,n=6)
#===== Example of a species name that needs the thesaurus
tmp <- subset(PSDWRtest,species %in% c("Yellow Perch","Bluegill Sunfish"),
select=c("species","len","wt"))
#----- Below will not add wr for "Bluegill Sunfish" as not in WsLit ("Bluegill" is)
tmp$wr1 <- wrAdd(wt~len+species,data=tmp)
#----- Use thesaurus to identify "Bluegill Sunfish" as "Blueill
tmp$wr2 <- wrAdd(wt~len+species,data=tmp,thesaurus=c("Bluegill"="Bluegill Sunfish"))
peek(tmp,n=10)
#===== Example of species that has Ws eqns for multiple reference values
tmp <- subset(PSDWRtest,species=="Ruffe",select=c("species","len","wt"))
#----- Below will err as Ruffe has Ws eqns for multiple reference values
# tmp$wr <- wrAdd(wt~len+species,data=tmp)
#----- Must choose which eqn to use with WsOpts
tmp$wr <- wrAdd(wt~len+species,data=tmp,
WsOpts=list(Ruffe=list(ref=75)))
peek(tmp,n=6)
#===== Example with two uses of WsOpts (and one species without)
tmp <- subset(PSDWRtest,species %in% c("Ruffe","Muskellunge","Iowa Darter"),
select=c("species","len","wt"))
tmp$wr <- wrAdd(wt~len+species,data=tmp,
WsOpts=list(Muskellunge=list(group="overall"),
Ruffe=list(ref=75)))
peek(tmp,n=10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.