wrAdd: Computes a vector of relative weights specific to a species...

wrAddR Documentation

Computes a vector of relative weights specific to a species in an entire data frame.

Description

This computes a vector that contains the relative weight specific to each species for all individuals in an entire data frame.

Usage

wrAdd(wt, ...)

## Default S3 method:
wrAdd(wt, len, spec, units = c("metric", "English"), ...)

## S3 method for class 'formula'
wrAdd(wt, data, units = c("metric", "English"), ...)

Arguments

wt

A numeric vector that contains weight measurements or a formula of the form wt~len+spec where “wt” generically represents the weight variable, “len” generically represents the length variable, and “spec” generically represents the species variable. Note that this formula can only contain three variables and they must be in the order of weight first, length second, species third.

...

Not used.

len

A numeric vector that contains length measurements. Not used if wt is a formula.

spec

A character or factor vector that contains the species names. Not used if wt is a formula.

units

A string that indicates whether the weight and length data in formula are in ("metric" (DEFAULT; mm and g) or "English" (in and lbs) units.

data

A data.frame that minimally contains variables of the the observed lengths, observed weights, and the species names given in the formula=.

Details

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, a standard weight equation for the 75th percentile 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 use of the 75th percentile is by far the most common and, because this function is designed for use on entire data frames, it will be the only percentile allowed. Thus, to use equations for other percentiles, one will have to use “manual” methods. See WSlit and wsVal for more details about types of equations, percentiles, finding which species have published standard weight equations, etc. See the examples for one method for changing species names to something that this function will recognize.

Value

Returns A numeric vector that contains the computed relative weights, in the same order as in data=.

IFAR Chapter

8-Condition.

Author(s)

Derek H. Ogle, DerekOgle51@gmail.com

References

Ogle, D.H. 2016. Introductory Fisheries Analyses with R. Chapman & Hall/CRC, Boca Raton, FL.

See Also

See wsVal, WSlit, and psdAdd for related functionality. See mapvalues for help in changing species names to match those in WSlit.

Examples

## 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)

df$Wr1 <- wrAdd(wt~tl+species,data=df)
## same but with non-formula interface
df$Wr2 <- wrAdd(df$wt,df$tl,df$species)

## Same as above but using dplyr
if (require(dplyr)) {
  df <- mutate(df,Wr3a=wrAdd(wt,tl,species))
}

df
 
## Example with only one species in the data.frame
bg <- droplevels(subset(df,species=="Bluegill"))
bg$Wr4 <- wrAdd(wt~tl+species,data=bg)


droglenc/FSA documentation built on Aug. 30, 2023, 12:51 a.m.