psdAdd | R Documentation |
Creates a vector of the Gabelhouse lengths specific to a species for all individuals in an entire data frame.
psdAdd(len, ...)
## Default S3 method:
psdAdd(
len,
species,
group = NULL,
units = c("mm", "cm", "in"),
use.names = TRUE,
as.fact = ifelse(is.null(addLens), use.names, FALSE),
addLens = NULL,
verbose = TRUE,
...
)
## S3 method for class 'formula'
psdAdd(
len,
data = NULL,
group = NULL,
units = c("mm", "cm", "in"),
use.names = TRUE,
as.fact = ifelse(is.null(addLens), use.names, FALSE),
addLens = NULL,
verbose = TRUE,
...
)
len |
A numeric vector that contains lengths measurements or a formula of the form |
... |
Not used. |
species |
A character or factor vector that contains the species names. Ignored if |
group |
A named list that provides specific choices for |
units |
A string that indicates the type of units used for the lengths. Choices are |
use.names |
A logical that indicates whether the vector returned is numeric ( |
as.fact |
A logical that indicates that the new variable should be returned as a factor ( |
addLens |
A named list with (possibly named) numeric vectors of lengths that should be used in addition to the Gabelhouse lengths for the species that form the names in the list. 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 |
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 Gabelhouse lengths for each individual. The Gabelhouse length value will be NA
for each individual for which Gabelhouse length definitions do not exist in PSDlit
. Species names in the data.frame must be the same as those used in PSDlit
(i.e., same spelling and capitalization; use psdVal()
to see the list of species).
Some species have Gabelhouse lengths for sub-groups (e.g., “lentic” vs “lotic”). For these species, choose which sub-group to use with group
.
Individuals shorter than “stock” length will be listed as substock
if use.names=TRUE
or 0
if use.names=FALSE
.
Additional lengths to be used for a species may be included by giving a named list with vectors of additional lengths in addLens
. Note, however, that as.fact
will be reset to FALSE
if addLens
are specified, as there is no way to order the names (i.e., factor levels) for all species when additional lengths are used.
See examples and this article for a demonstration.
A numeric or factor vector that contains the Gabelhouse length categories.
6-Size Structure.
Derek H. Ogle, DerekOgle51@gmail.com
Ogle, D.H. 2016. Introductory Fisheries Analyses with R. Chapman & Hall/CRC, Boca Raton, FL.
Guy, C.S., R.M. Neumann, and D.W. Willis. 2006. New terminology for proportional stock density (PSD) and relative stock density (RSD): proportional size structure (PSS). Fisheries 31:86-87. [Was (is?) from http://pubstorage.sdstate.edu/wfs/415-F.pdf.]
Guy, C.S., R.M. Neumann, D.W. Willis, and R.O. Anderson. 2006. Proportional size distribution (PSD): A further refinement of population size structure index terminology. Fisheries 32:348. [Was (is?) from http://pubstorage.sdstate.edu/wfs/450-F.pdf.]
Willis, D.W., B.R. Murphy, and C.S. Guy. 1993. Stock density indices: development, use, and limitations. Reviews in Fisheries Science 1:203-222. [Was (is?) from http://web1.cnre.vt.edu/murphybr/web/Readings/Willis%20et%20al.pdf.]
psdVal
, psdCalc
, psdPlot
, PSDlit
, and wrAdd
for related functions. See mapvalues
for help in changing species names to match those in PSDlit
.
#===== Create random data for three species
set.seed(345234534)
dbg <- data.frame(species=factor(rep(c("Bluegill"),30)),
tl=round(rnorm(30,130,50),0))
dlb <- data.frame(species=factor(rep(c("Largemouth Bass"),30)),
tl=round(rnorm(30,350,60),0))
dbt <- data.frame(species=factor(rep(c("Bluefin Tuna"),30)),
tl=round(rnorm(30,1900,300),0))
df <- rbind(dbg,dlb,dbt)
#===== Simple examples
#----- Add variable using category names -- non-formula notation
df$PSD <- psdAdd(df$tl,df$species)
peek(df,n=6)
#----- Add variable using category names -- formula notation
df$PSD1 <- psdAdd(tl~species,data=df)
peek(df,n=6)
#----- Add variable using length values as names
# Also turned off messaging of fish not in PSDlit
df$PSD2 <- psdAdd(tl~species,data=df,use.names=FALSE,verbose=FALSE)
peek(df,n=6)
#----- Same as above but using dplyr
if (require(dplyr)) {
df <- df %>%
mutate(PSD1A=psdAdd(tl,species,verbose=FALSE),
PSD2A=psdAdd(tl,species,use.names=FALSE,verbose=FALSE))
peek(df,n=6)
}
#===== Adding lengths besides the Gabelhouse lengths
#----- Add a "minimum length" for Bluegill
df$PSD3 <- psdAdd(tl~species,data=df,verbose=FALSE,
addLens=list("Bluegill"=c("minLen"=175)))
df$PSD3A <- psdAdd(tl~species,data=df,verbose=FALSE,
addLens=list("Bluegill"=175))
df$PSD3B <- psdAdd(tl~species,data=df,verbose=FALSE,
addLens=list("Bluegill"=c("minLen"=175)),use.names=FALSE)
head(df,n=6)
#----- Add add'l lengths and names for Bluegill and Largemouth Bass
df$psd4 <- psdAdd(tl~species,data=df,verbose=FALSE,
addLens=list("Bluegill"=175,
"Largemouth Bass"=c(254,356)))
peek(df,n=20)
#===== Example for a species with sub-groups
dbt <- data.frame(species=factor(rep(c("Brown Trout"),30)),
tl=round(rnorm(30,230,50),0))
dlt <- data.frame(species=factor(rep(c("Lake Trout"),30)),
tl=round(rnorm(30,550,60),0))
df2 <- rbind(dbt,dlt)
df2$psd <- psdAdd(tl~species,data=df2,group=list("Brown Trout"="lentic"))
peek(df2,n=6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.