Learn R Programming

ss3sim (version 1.0.3)

sample_index: Sample the biomass with observation error

Description

This function creates an index of abundance sampled from the expected available biomass for given fleets in given years. Let B_y be the biomass from the operating model for year y. Then the sampled value is calculated as: B_y*exp(rnorm(1, 0, sds_obs)-sds_obs^2/2). The second term adjusts the random samples so that their expected value is B_y (i.e. the log-normal bias correction). If used with run_ss3sim the case file should be named index. A suggested (default) case letter is D for data.

Usage

sample_index(dat_list, outfile = NULL, fleets, years, sds_obs,
  make_plot = FALSE)

Value

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

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.

See Also

Other sampling functions: clean_data, sample_agecomp, sample_calcomp, sample_lcomp, sample_mlacomp, sample_wtatage

Examples

Run this code
# NOT RUN {
# Find the example data location:
d <- system.file("extdata", package = "ss3sim")
f_in <- file.path(d, "example-om", "ss3_expected_values.dat")
dat_list <- r4ss::SS_readdat(f_in, version = NULL, verbose = FALSE)
# Note the initial expected values for the index data:
dat_list$CPUE # Only has expected values for fleet 2 in every other year from
# 76 to 100, so can only sample from fleet 2 during every other year between
# 76 and 100
sam_yrs <- seq(76, 100, by = 2)
ex1 <- sample_index(dat_list,
                   outfile = NULL,
                   fleets = 2,
                   years = list(sam_yrs),
                   sds_obs=list(seq(.001, .1,
                     length.out = length(sam_yrs))))
ex1$CPUE
# could sample from less years, but not more:
ex2 <- sample_index(dat_list,
                    outfile = NULL,
                    fleets = 2,
                    years = list(sam_yrs[c(-1, -2)]),
                    sds_obs=list(seq(.001, .1,
                      length.out = length(sam_yrs[c(-1, -2)]))))
ex2$CPUE
# Also, sd can be fixed across years:
ex3 <- sample_index(dat_list,
                    outfile = NULL,
                    fleets = 2,
                    years = list(sam_yrs),
                    sds_obs=list(0.01))
ex3$CPUE
# If fleet 1 also had expected values in the index that you wanted to sample:
# ex4 <- sample_index(dat_list,
#                     outfile = NULL,
#                     fleets = c(1,2),
#                     years = list(sam_yrs, sam_yrs),
#                     sds_obs=list(0.01, 0.01))
# }

Run the code above in your browser using DataLab