Learn R Programming

FSA (version 0.8.1)

psdAdd: Create vector of Gabelhouse lengths for each species from an entire data frame.

Description

Creates a vector of the Gabelhouse lengths specific to a species for all individuals in an entire data frame.

Usage

psdAdd(len, ...)

## S3 method for class 'default':
psdAdd(len, spec, units = c("mm", "cm", "in"),
  use.names = TRUE, addSpec = NULL, addLens = NULL, verbose = TRUE, ...)

## S3 method for class 'formula':
psdAdd(len, data = NULL, units = c("mm", "cm", "in"),
  use.names = TRUE, addSpec = NULL, addLens = NULL, verbose = TRUE, ...)

Arguments

len
A numeric vector that contains lengths measurements or a formula of the form len~spec where len generically represents the length variable and spec generically represents the species variable. Note that this
spec
A character or factor vector that contains the specicas names. Not used if len is a formula.
units
A string that indicates the type of units used for the lengths. Choices are mm for millimeters (DEFAULT), cm for centimeters, and in for inches.
use.names
A logical that indicates whether the vector returned is numeric (=FALSE) or word (=TRUE; default) representations of the Gabelhouse lengths. See details.
addSpec
A character vector of species names for whiach addLens will be provided.
addLens
A numeric vector of lengths that should be used for the species in addSpec in addition to the Gabelhouse lengths. See examples.
verbose
A logical that indicates whether detailed messages about species without Gabelhouse lengths or with no recorded values should be printed or not.
data
A data.frame that minimally contains the length measurements and species names if len is a formula.
...
Not used.

Value

  • A numeric or factor vector that contains the Gabelhouse length categories.

IFAR Chapter

6-Size Structure.

Details

This computes a vector that contains the Gabelhouse lengths 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 Gabelhous lengths for each individual. The Gabelhouse length value will be NA for each individual for which a Gabelhouse length definitision do not exist in PSDlit. Individuals shorter than stock length will be listed as zero if use.names=TRUE or 0 if use.names=FALSE. See the examples for one method for changing species names to something that this function will recognize. Additional lengths to be use for each species can be included by giving a vector of species names in addSpec and a corresponding vector of additional lengths in addLens. Note, however, that use.names will be reset to FALSE if addSpec and addLens are specified as there is no way to order the names when additional lengths are used.

References

Ogle, D.H. 2015. http://derekogle.com/IFAR{Introductory Fisheries Analyses with R}. Chapman & Hall/CRC, Boca Raton, FL. Guy, C.S., R.M. Neumann, and D.W. Willis. 2006. http://pubstorage.sdstate.edu/wfs/415-F.pdf{New terminology for proportional stock density (PSD) and relative stock density (RSD): proportional size structure (PSS).} Fisheries 31:86-87. Guy, C.S., R.M. Neumann, D.W. Willis, and R.O. Anderson. 2006. http://pubstorage.sdstate.edu/wfs/450-F.pdf{Proportional size distribution (PSD): A further refinement of population size structure index terminology.} Fisheries 32:348. Willis, D.W., B.R. Murphy, and C.S. Guy. 1993. http://web1.cnre.vt.edu/murphybr/web/Readings/Willis%20et%20al.pdf{Stock density indices: development, use, and limitations.} Reviews in Fisheries Science 1:203-222.

See Also

psdVal, psdCalc, psdPlot, PSDlit, and wrAdd for related functions. See mapvalues for help in changing species names to match those in PSDlit.

Examples

Run this code
## Create random data for three species
# only for repeatability
set.seed(345234534)
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)
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)
df <- rbind(dbg,dlb,dbt)
str(df)

## Examples (non-dplyr)
# Add variable using category names -- formula notation
df$PSD <- psdAdd(tl~species,data=df)
head(df)
# Add variable using category names -- non-formula notation
df$PSD1 <- psdAdd(df$tl,df$species)
head(df)
# Add variable using length values as names
df$PSD2 <- psdAdd(tl~species,data=df,use.names=FALSE)
head(df)
# Add additional length and name for Bluegill
df$PSD3 <- psdAdd(tl~species,data=df,addSpec="Bluegill",addLens=175)
head(df)
# Add additional lengths and names for Bluegill and Largemouth Bass from a data.frame
addls <- data.frame(species=c("Bluegill","Largemouth Bass","Largemouth Bass"),
                    lens=c(175,254,356))
df$psd4 <- psdAdd(tl~species,data=df,addSpec=addls$species,addLens=addls$lens)
head(df)

## All of the above but using dplyr
if (require(dplyr)) {
  df <- df %>%
    mutate(PSD1A=psdAdd(tl,species)) %>%
    mutate(PSD2A=psdAdd(tl,species,use.names=FALSE)) %>%
    mutate(psd3a=psdAdd(tl,species,addSpec="Bluegill",addLens=175)) %>%
    mutate(psd4a=psdAdd(tl,species,addSpec=addls$species,addLens=addls$lens))
}
df

Run the code above in your browser using DataLab