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, units = c("metric", "English"), WsOpts = NULL, ...)
## S3 method for class 'formula'
wrAdd(wt, data, 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 |
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.
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
.
#===== Create random data for three species
#----- just to control the randomization
set.seed(345234534)
dbt <- data.frame(species=factor(rep(c("Bluefin Tuna"),30)),
tl=round(rnorm(30,1900,300),0))
dbt$wt <- round(4.5e-05*dbt$tl^2.8+rnorm(30,0,6000),1)
dbg <- data.frame(species=factor(rep(c("Bluegill"),30)),
tl=round(rnorm(30,130,50),0))
dbg$wt <- round(4.23e-06*dbg$tl^3.316+rnorm(30,0,10),1)
dlb <- data.frame(species=factor(rep(c("Largemouth Bass"),30)),
tl=round(rnorm(30,350,60),0))
dlb$wt <- round(2.96e-06*dlb$tl^3.273+rnorm(30,0,60),1)
df <- rbind(dbt,dbg,dlb)
str(df)
#===== Add Wr variable
#----- using formula interface
df$Wr1 <- wrAdd(wt~tl+species,data=df)
#----- same but with non-formula interface
df$Wr2 <- wrAdd(df$wt,df$tl,df$species)
#----- same but using dplyr
if (require(dplyr)) {
df <- df %>%
mutate(Wr3=wrAdd(wt,tl,species))
}
#----- examine results
peek(df,n=10)
#===== Example with only one species in the data.frame
bg <- droplevels(subset(df,species=="Bluegill"))
bg$Wr4 <- wrAdd(wt~tl+species,data=bg)
bg
#===== Example with a species that has Ws eqns for multiple groups and a
# group needs to be specified with WsOpts
wae <- data.frame(species=factor(rep(c("Walleye"),30)),
tl=round(rnorm(30,500,200),0))
wae$wt <- round(3.33e-06*wae$tl^3.16+rnorm(30,0,50),1)
# wae$Wr <- wrAdd(wt~tl+species,data=wae) # will err b/c multiple groups
wae$Wr <- wrAdd(wt~tl+species,data=wae,
WsOpts=list(Walleye=list(group="overall")))
peek(wae,n=10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.