Extract length-composition data from a .ss_new data file and sample the data. It is assumed that the composition data will be expected values as written by Stock Synthesis in the second section of the data file, but one can also sample input data. The resulting length-composition data are assumed to represent observed length composition and will overwrite the length data in dat_list, which is returned invisibly. The data file can also be written to the disk, if a file path is provided to outfile, and used as simulated data by an estimation model.

sample_lcomp(
  dat_list,
  outfile = NULL,
  fleets,
  Nsamp,
  years,
  cpar = 1,
  ESS = NULL,
  ...
)

Arguments

dat_list

A Stock Synthesis data list object as read in from SS_readdat. Be sure to correctly specify which section of the data file you want to work with when reading it in using the section argument. Where, section = 1 reads in the input values used to run the model and section = 2 reads in the expected values generated given all the input to the OM. section = 3 is not used within ss3sim, but this section provides bootstrapped data sets that have been sampled internally within SS.

outfile

A character string specifying the file name to use when writing the information to the disk. The string must include the proper file extension. No file is written using the default value of NULL, which leads to increased speed because writing the file takes time and computing resources.

fleets

*A vector of integers specifying which fleets to include. The order of the fleets pertains to the input order of other arguments. An entry of fleets=NULL leads to zero samples for any fleet.

Nsamp

*A numeric list of the same length as fleets. Either single values or vectors of the same length as the number of years can be passed through. Single values are repeated for all years. If no fleet collected samples, keep the value to Nsamp=NULL.

years

*A list the same length as fleets giving the years as numeric vectors. If no fleet collected samples, keep the value to years=NULL.

cpar

A numeric value or vector the same length as fleets controlling the variance of the Dirichlet distribution used for sampling. A value of 1 leads to the same standard deviation as a multinomial of the given Nsamp, 2 indicates twice, etc. Values greater than one indicate overdispersion, and less underdispersion. NULL or NA for a given fleet will lead to no dispersion.

ESS

The final effective sample size (ESS) associated with the simulated data. The ESS is not used to generate the simulated data but can be used as an input sample size in subsequent models that estimate population parameters or status. The default, NULL, leads to the true (internally calculated) #' ESS being used, which is Nsamp for the multinomial case or given by the formula under cpar for the Dirichlet case. At least one value must be provided for each fleet or a vector of year-specific values can be used for any given fleet. The argument accepts a list with entries, either a single integer or a vector of integers, for each fleet.

...

Any argument you want to be a column in the new data frame of composition data. All extra arguments should be named columns in data. Each argument needs to be a list of length length(fleets). Or, you can use a single value that will be repeated for each combination of fleet, year, ... in your data.

Value

A modified .dat file if !is.null(outfile). A list object containing the modified .dat file is returned invisibly.

See also

Author

Cole Monnahan and Kotaro Ono

Examples

dat_list <- r4ss::SS_readdat(
  verbose = FALSE,
  file = system.file(file.path("extdata", "models", "cod-om", "codOM.dat"),
    package = "ss3sim"
  )
)
## Generate with constant sample size across years
ex1 <- sample_lcomp(
  dat_list = dat_list, outfile = NULL,
  fleets = 1:2, Nsamp = list(100, 50),
  years = list(seq(26, 100, by = 2), 80:100)
)
#> Error: dim(ex1[["lencomp"]]) not equal to c(59, 51).
#> 1/2 mismatches
#> [1] 8850 - 59 == 8791