Learn R Programming

ss3sim (version 0.9.0)

sample_agecomp: Sample age compositions from expected values

Description

Take a data.SS_new file containing expected values and sample to create observed age compositions which are then written to file for use by the estimation model. If used with run_ss3sim the case file should be named agecomp. A suggested (default) case letter is D for data.

Usage

sample_agecomp(dat_list, outfile, fleets = c(1, 2), Nsamp, years, cpar = 1,
  ESS = NULL, write_file = TRUE, keep_conditional = TRUE)

Value

  • A modified .dat file if write_file=TRUE. 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_calcomp, sample_index, sample_lcomp, sample_mlacomp, sample_wtatage

Examples

Run this code
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)

## Turn off age comps by specifying fleets=NULL
sample_agecomp(dat_list=dat_list, outfile="test1.dat",
               fleets=NULL, cpar=c(5,NA), Nsamp=list(100,100),
               years=list(1995, 1995), write_file=FALSE)

## Generate with a smaller number of fleet taking samples
ex1 <- sample_agecomp(dat_list=dat_list, outfile="test1.dat", fleets=c(2),
                      Nsamp=list(c(10,50)), years=list(c(26,27)),
                      write_file=FALSE)

## Generate with varying Nsamp by year for first fleet
ex2 <- sample_agecomp(dat_list=dat_list, outfile="test2.dat", fleets=c(1,2),
                      Nsamp=list(c(rep(50, 5), rep(100, 5)), 50),
                      years=list(seq(26, 44, 2),
                          c(26:100)), write_file=FALSE)

## Run three  cases showing Multinomial, Dirichlet(1) and over-dispersed
## Dirichlet for different levels of sample sizes
op <- par(mfrow = c(1,3))
for(samplesize in c(30, 100, 1000)){
    ex4 <- sample_agecomp(dat_list=dat_list, outfile="test4.dat", fleets=c(1,2),
                          Nsamp=list(samplesize, samplesize),
                          write_file = FALSE,
                          years=list(2000,2000), cpar=c(NA, 1))
    ex5 <- sample_agecomp(dat_list=dat_list, outfile="test5.dat", fleets=c(1,2),
                          Nsamp=list(samplesize, samplesize),
                          write_file = FALSE,
                          years=list(2000,2000), cpar=c(1, 1))
    ex6 <- sample_agecomp(dat_list=dat_list, outfile="test6.dat", fleets=c(1,2),
                          Nsamp=list(samplesize, samplesize),
                          write_file = FALSE,
                          years=list(2000,2000), cpar=c(5, 1))
    true <- subset(dat_list$agecomp, FltSvy==1 & Yr == 2000)[-(1:9)]
    true <- true/sum(true)
    plot(0:15, subset(ex4, FltSvy==1)[1,-(1:9)], type="b", ylim=c(0,1),
         col=1, xlab="Age", ylab="Proportion", main=paste("Sample size=",
         samplesize))
    legend("topright", legend=c("Multinomial", "Dirichlet(1)",
                                "Dirichlet(5)", "Truth"),
           lty=1, col=1:4)
    lines((0:15), subset(ex5, FltSvy==1)[1,-(1:9)], type="b", col=2)
    lines((0:15), subset(ex6, FltSvy==1)[1,-(1:9)], type="b", col=3)
    lines((0:15), true, col=4, lwd=2)
}
par(op)

Run the code above in your browser using DataLab