Learn R Programming

ss3sim (version 0.9.0)

change_data: Change the data that is available as output from an SS operating model.

Description

change_data alters the data structure for a data list as read in by SS_readdat, for use in preparing the data file for an SS operating model. Original data is removed and dummy data is added, as specified, to the SS .dat file. This causes SS to produce expected values (OM "truth") when the operating model is run, from which data can be sampled. For each data type altered, change_data will add data for the fleets and years given; potentially adding many rows of redundant data. Currently, .dat files with multiple genders cannot be manipulated with change_data. calculate_data_units is used internally in ss3sim_base to create a superset of fleets and years from sample arguments, and clean_data to strip out unused data after change_data is called (see examples below). change_data is called internally automatically, but can also be used by an ss3sim user to manipulate data as a case, or to prepare a new OM for use in a simulation. See the vignette for more details.

Usage

change_data(dat_list, outfile, fleets, years, types, age_bins = NULL,
  len_bins = NULL, pop_binwidth = NULL, pop_minimum_size = NULL,
  pop_maximum_size = NULL, lcomp_constant = NULL, tail_compression = NULL,
  write_file = TRUE)

Value

  • An invisible data list, and a file is written if write_file = TRUE.

Which arguments to specifiy in case files

All function argument descriptions that start with an asterisk (*) will be passed through the case files to run_ss3sim. If one of these arguments is not specified in a case file, then a value of NULL will be passed, which may or may not be an appropriate value. Other arguments will be ignored if specified.

Details

The robustification constant is added to both the observed and expected proportions of length composition data, before being normalized internally. It is designed to help stabilize the model, but is unclear how and when to use it for optimal effect. The same value is used for all length data.

See Also

sample_lcomp, sample_agecomp

Other change functions: change_em_binning, change_e, change_f, change_maturity, change_retro, change_tv

Examples

Run this code
d <- system.file("extdata", package = "ss3sim")
fleets <- 1:2
years <- c(5, 10, 15)
types <- c("len", "age")
file_in <- r4ss::SS_readdat(paste0(d, "/models/cod-om/codOM.dat"))
file_in <- change_fltname(file_in)

# Basic test with just length data, default bins:
out <- change_data(file_in, outfile = "ignore.dat", types = "len",
  years = years, fleets = fleets, write_file = FALSE)
print(out$lbin_vector)
print(out$lencomp)

# Change the length bins:
out <- change_data(file_in, "ignore.dat", types = "len",
  years = years, fleets = fleets, len_bins = 3:6, write_file = FALSE)
out$lbin_vector
out$lencomp

# Change the population length bins:
out <- change_data(file_in, "ignore.dat", types = "len",
  years = years, fleets = fleets, pop_binwidth = 1, pop_minimum_size = 5,
  pop_maximum_size = 210, write_file = FALSE)
out$binwidth
out$maximum_size
out$minimum_size

# Sample from index, length composition, age composition, catch at length,
# mean length at age data: (normally this is all done from within run_ss3sim).

index_params = list(fleets = c(1, 2), years = list(c(1, 2),
  c(10, 11)), sds_obs = c(0.1, 0.2))
lcomp_params = list(Nsamp = list(12345), fleets = 1, years = list(c(1, 5)))
agecomp_params = list(Nsamp = list(12345), fleets = c(1, 2),
  years = list(2, c(15, 16)))
calcomp_params = list(Nsamp = list(1), fleets = c(1), years = 98)
mlacomp_params = list(fleets = c(2), Nsamp = 54, years = list(c(1, 15)))
d <- system.file("extdata", package = "ss3sim")
f_in <- paste0(d, "/models/cod-om/codOM.dat")
dat_list <- r4ss::SS_readdat(f_in, verbose = FALSE)
dat_list <- change_fltname(dat_list)
data_units <- calculate_data_units(index_params = index_params,
  lcomp_params = lcomp_params, agecomp_params = agecomp_params,
  calcomp_params = calcomp_params, mlacomp_params = mlacomp_params)
data_units
dat2 <- with(data_units, change_data(dat_list = dat_list, fleets = fleets,
  years = years, types = types, write_file = FALSE))
dat3 <- clean_data(dat_list = dat2, lcomp_params = lcomp_params,
  index_params = index_params, agecomp_params = agecomp_params,
  calcomp_params = calcomp_params, mlacomp_params = mlacomp_params,
  verbose = TRUE)

Run the code above in your browser using DataLab