change_em_binning() alters the bin structure for the population and length-composition data in a Stock Synthesis estimation model (EM). The original length-composition data from the EM .dat is changed according to the user's specification. If the data file also contains conditional age-at-length data, then these data will be re-binned as well.

change_em_binning(
  dat_list,
  outfile = NULL,
  bin_vector,
  lbin_method = NULL,
  pop_binwidth = NULL,
  pop_minimum_size = NULL,
  pop_maximum_size = 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.

bin_vector

A numeric vector of new length bins to substitute into the *.dat file.

lbin_method

A numeric value of either NULL, 1, 2, 3 to change the lbin_method for the population bin. NULL means to not re-bin.

pop_binwidth

Population length bin width. Only necessary for lbin_method = 2. Note that this value must be smaller than the bin width specified in length-composition data len_bins or Stock Synthesis will fail (see notes in the Stock Synthesis manual).

pop_minimum_size

Population minimum length bin value. Only necessary for lbin_method = 2.

pop_maximum_size

Population maximum length bin value. Only necessary for lbin_method = 2.

See also

Other change functions: change_data(), change_e(), change_f(), change_o(), change_retro(), change_tv()

Author

Kotaro Ono (length-composition rebinning), Sean Anderson (conditional age-at-length rebinning)

Examples

# Note that typically this function is used with estimation models in ss3sim,
# but it is used with an operating model data file in the following examples.
f <- system.file("extdata", "models", "cod-om", "codOM.dat", package = "ss3sim")
d <- r4ss::SS_readdat(f, verbose = FALSE)

# An example with lbin_method = 1
l1 <- change_em_binning(d,
  outfile = NULL, lbin_method = 1,
  bin_vector = seq(20, 152, by = 4)
)
l1$lbin_vector
#>  [1]  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80  84  88  92
#> [20]  96 100 104 108 112 116 120 124 128 132 136 140 144 148 152
head(l1$lencomp)
#>   Yr Seas FltSvy Gender Part Nsamp l20 l24 l28 l32 l36 l40 l44 l48 l52 l56 l60
#> 1 26    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 2 27    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 3 28    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 4 29    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 5 30    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 6 31    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#>   l64 l68 l72 l76 l80 l84 l88 l92 l96 l100 l104 l108 l112 l116 l120 l124 l128
#> 1   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 2   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 3   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 4   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 5   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 6   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#>   l132 l136 l140 l144 l148 l152
#> 1    1    1    2    1    1    1
#> 2    1    1    2    1    1    1
#> 3    1    1    2    1    1    1
#> 4    1    1    2    1    1    1
#> 5    1    1    2    1    1    1
#> 6    1    1    2    1    1    1

# An example with lbin_method = 2
new_bin_vec <- seq(min(d$lbin_vector), max(d$lbin_vector), by = 4)
# add the max value if necessary.
if (new_bin_vec[length(new_bin_vec)] != d$lbin_vector[length(d$lbin_vector)]) {
  new_bin_vec <- c(
    new_bin_vec,
    d$lbin_vector[length(d$lbin_vector)]
  )
}
pop_bin_input <- 5
pop_min_size_input <- min(d$lbin_vector_pop) - 1
pop_max_size_input <- max(d$lbin_vector_pop) + 5
lbin_vec_pop <- seq(pop_min_size_input,
  pop_max_size_input,
  length.out = (pop_max_size_input - pop_min_size_input) /
    pop_bin_input + 1
)
l2 <- change_em_binning(
  dat_list = d,
  bin_vector = new_bin_vec,
  lbin_method = 2,
  # Note: need more inputs with lbin_method = 2
  pop_binwidth = pop_bin_input,
  pop_minimum_size = pop_min_size_input,
  pop_maximum_size = pop_max_size_input
)
l2$lbin_method
#> [1] 2
# note bin width is now the same as the input
pop_bin_input
#> [1] 5
l2$binwidth
#> [1] 5
# note the minimum size has changed based on the input:
pop_min_size_input
#> [1] 9
l2$minimum_size
#> [1] 9
# so has max
l2$maximum_size
#> [1] 206
l2$lbin_vector
#>  [1]  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80  84  88  92
#> [20]  96 100 104 108 112 116 120 124 128 132 136 140 144 148 152
# other modified components:
l2$lbin_vector_pop
#>  [1]   9.000  13.925  18.850  23.775  28.700  33.625  38.550  43.475  48.400
#> [10]  53.325  58.250  63.175  68.100  73.025  77.950  82.875  87.800  92.725
#> [19]  97.650 102.575 107.500 112.425 117.350 122.275 127.200 132.125 137.050
#> [28] 141.975 146.900 151.825 156.750 161.675 166.600 171.525 176.450 181.375
#> [37] 186.300 191.225 196.150 201.075 206.000
head(l2$lencomp)
#>   Yr Seas FltSvy Gender Part Nsamp l20 l24 l28 l32 l36 l40 l44 l48 l52 l56 l60
#> 1 26    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 2 27    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 3 28    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 4 29    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 5 30    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#> 6 31    1      1      0    0   100   2   1   1   2   1   1   2   1   1   2   1
#>   l64 l68 l72 l76 l80 l84 l88 l92 l96 l100 l104 l108 l112 l116 l120 l124 l128
#> 1   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 2   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 3   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 4   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 5   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#> 6   1   2   1   1   2   1   1   2   1    1    2    1    1    2    1    1    2
#>   l132 l136 l140 l144 l148 l152
#> 1    1    1    2    1    1    1
#> 2    1    1    2    1    1    1
#> 3    1    1    2    1    1    1
#> 4    1    1    2    1    1    1
#> 5    1    1    2    1    1    1
#> 6    1    1    2    1    1    1