Write out composition data to a file, binning the data as specified.

Workflow

PacFIN data should first be stratified using getComps, before using writeComps.

writeComps(
  inComps,
  fname = NULL,
  abins = NULL,
  lbins = NULL,
  maxAge = Inf,
  month = 7,
  partition = 2,
  ageErr = 0,
  dummybins = FALSE,
  sum1 = FALSE,
  digits = 4,
  overwrite = TRUE,
  verbose = FALSE
)

Arguments

inComps

A dataframe generated as described in Workflow, above.

fname

A filename with the appropriate extension, used to save the function output to the disk. For example, LenComps.csv or file.path(getwd(), "SampleSize.csv"). Full, relative, or simple paths are allowed because the argument is used as is, i.e., not redirected to a directory different than getwd(). Note that various functions within PacFIN.Utilities have different default values for this input argument.

abins

Bins to use for ages. Default is the data bins.

lbins

Bins to use for lengths. Default is the data bins.

maxAge

A numeric value specifying the maximum age of fish that should be included in the composition data, unless dummybins = TRUE, then those fish will be included in a plus group which you can investigate later. Note that maxAge is only used if abins = NULL, otherwise fish are binned according to user specified bins irregardless of maxAge.

month

Month for all observations. Defaults to 7. If input has multiple seasons, this must be a vector of equal length to the maximum seasons where the order of months in the vector will be assigned to season in ascending order. For example, if there are two seasons and the month = c(1, 7) season 1 will be assigned to month 1 and season 2 to month 7.

partition

Used by Stock Synthesis for length- or age-composition data where 0 = retained + discarded, 1= discarded, and 2 = retained fish. The default is to assume that these fish are retained only. The default was changed in 2020 from a value of 0, and code should be updated accordingly if you really want 0.

ageErr

Defaults to 1.

dummybins

A logical value specifying whether data outside of the lower and upper abins or lbins should be added to dummy bins, or be placed in the specified bins. Default is TRUE. Dummy bins are useful for determining whether the current bin structure properly captures the data.

sum1

A logical value specifying whether to rescale the compositions to sum to 1 (they will also be rounded to 4 decimal places)

digits

Integer indicating the number of decimal places to round value to (value is passed to round()). NULL will skip rounding.

overwrite

A logical value specifying whether to overwrite an existing file if the file associated with the input fname already exists.

verbose

A logical specifying if output should be written to the screen or not. Good for testing and exploring your data but can be turned off when output indicates information that you already know. The printing of output to the screen does not affect any of the returned objects. The default is to always print to the screen, i.e., verbose = TRUE.

Value

Appends data to the file given in fname.

Conditionally returns a dataframe if the out argument specifies the type of composition to return.

Details

The structure of the input dataframe determines whether writeComps produces age-, length-, or conditional-age-at-length- composition data.

Four sets of composition data are written to a single file specified by fname. These are:

  • females followed by males

  • male data only

  • female data only

  • males and females recombined as unsexed fish

The output file is appended to, rather than overwritten, so you may want to specify a new filename each time you generate a different stratification or bin structure, e.g., "out.1.csv", "out.2.csv".

Composition data are raw weights rather than proportions. Stock Synthesis internally converts these to proportions. The raw weights should be examined for anomalies.

To create proportions use prop.table on the columns containing composition data.

The columns in the output preceeding 'lengthcm' or 'age' are those that were used in stratifying the data.

Reality Checks

  • Set verbose = TRUE to follow progress

  • Use dummybins to evaluate bin structure

  • Examine the raw-weight output for anomalies

See also

Author

Andi Stephens, Chantel R. Wetzel, Kelli F. Johnson, Ian G. Taylor