run_retro: Simulate bam models for running retrospective analysis

View source: R/run_retro.R

run_retroR Documentation

Simulate bam models for running retrospective analysis

Description

Simulate bam models for running retrospective analysis

Usage

run_retro(
  CommonName = NULL,
  fileName = "bam",
  dir_bam_sim = "sim",
  dir_bam_base = "base",
  bam = NULL,
  dat_file = NULL,
  tpl_file = NULL,
  cxx_file = NULL,
  dat_obj = NULL,
  tpl_obj = NULL,
  cxx_obj = NULL,
  standardize = FALSE,
  nyr_remove = 1:5,
  ncores = NULL,
  ndigits = 4,
  unlink_dir_bam_base = FALSE,
  run_bam_base = TRUE,
  overwrite_bam_base = TRUE,
  admb_options_base = "-nox",
  run_sim = TRUE,
  admb_options_sim = "-est -nox -ind",
  prompt_me = FALSE,
  subset_rdat = list(eq.series = 101, pr.series = 101),
  random_seed = 12345,
  admb2r_obj = admb2r.cpp,
  cleanup = list(del = c("*.r0*", "*.p0*", "*.b0*", "*.log", "*.rpt", "*.obj", "*.htp",
    "*.eva", "*.bar", "*.tds", "*.o", "tmp_admb", "variance", "*.dep", "*.hes", "*.tmp"))
)

Arguments

CommonName

Common name of species associated with dat, tpl, and cxx files

fileName

Name given to BAM files, not including file extensions.

dir_bam_sim

Name of directory to write retrospective analysis files to, relative to the working directory.

dir_bam_base

Name of directory to write bam base model files to, relative to the working directory.

bam

Output of bam2r.

dat_file

dat file path

tpl_file

tpl file path

cxx_file

cxx file path

dat_obj

dat file read in as a character vector with readLines(con=dat_file)

tpl_obj

tpl file read in as a character vector with readLines(con=tpl_file)

cxx_obj

cxx file read in as a character vector with readLines(con=cxx_file)

standardize

Should standardize_bam be run by the function before running the BAM

nyr_remove

number of years to remove in the retrospective analysis

ncores

number of cores to use for parallel processing

ndigits

number of digits to round simulated values to

unlink_dir_bam_base

Should dir_bam_base be deleted after this function is run?

run_bam_base

If FALSE, the function will look for an executable named fileName.exe in dir_bam_base and use it as the base model.

overwrite_bam_base

If FALSE, the files in dir_bam_base will not be overwritten if run_bam_base=TRUE

admb_options_base

Character string pasted to fileName to build run_command for the base model when running BAM with shell(run_command) (i.e. run_command <- paste(fileName, admb_options))

run_sim

If FALSE, the simulated data will be generated but won't be used in new BAM runs

admb_options_sim

ADMB code snippet used in shell script when running bam

prompt_me

Turn on/off prompts that ask for user input before deleting files.

subset_rdat

list of rdat objects to subset to decrease rdat file size

random_seed

random seed value. If NULL, random seed is not set within the function.

admb2r_obj

Character string containing admb2r C++ code, which is written with base::writeLines to dir_bam

cleanup

List object written to cleanup.bat file in dir_bam.

Value

Invisibly returns a data frame, sim_out, containing basic results of sim runs, including total likelihood and maximum gradient values. This data frame is also written to a csv file in dir_bam_sim.

Examples

## Not run: 
Run retrospective analysis, writing files to dir_bam_sim
run_retro("AtlanticMenhaden", dir_bam_base="AtMe_base", dir_bam_sim="AtMe_sim")
run_retro("BlackSeaBass", dir_bam_base="BlSB_base", dir_bam_sim="BlSB_sim",nyr_remove=1:4) # removing 5 years results in an error likely due to closed season commercial pot discards running out of data
run_retro("BluelineTilefish", dir_bam_base="BlTi_base", dir_bam_sim="BlTi_sim")
run_retro("Cobia", dir_bam_base="Cobi_base", dir_bam_sim="Cobi_sim")
run_retro("GagGrouper", dir_bam_base="GaGr_base", dir_bam_sim="GaGr_sim")
run_retro("GrayTriggerfish", dir_bam_base="GrTr_base", dir_bam_sim="GrTr_sim")
run_retro("GreaterAmberjack", dir_bam_base="GrAm_base", dir_bam_sim="GrAm_sim",nyr_remove=1:4) # removing 5 years results in an error because you run out of rGN discard length comps which start in 2013
run_retro("RedGrouper", dir_bam_base="ReGr_base", dir_bam_sim="ReGr_sim")
run_retro("RedPorgy", dir_bam_base="RePo_base", dir_bam_sim="RePo_sim")
run_retro("RedSnapper", dir_bam_base="ReSn_base", dir_bam_sim="ReSn_sim")
run_retro("ScampGrouper", dir_bam_base="ScGr_base", dir_bam_sim="ScGr_sim")
run_retro("SnowyGrouper", dir_bam_base="SnGr_base", dir_bam_sim="SnGr_sim")
run_retro("Tilefish", dir_bam_base="Tile_base", dir_bam_sim="Tile_sim")
run_retro("VermilionSnapper", dir_bam_base="VeSn_base", dir_bam_sim="VeSn_sim")


## End(Not run)

nikolaifish/bamExtras documentation built on July 21, 2023, 8:26 a.m.