Learn R Programming

ss3sim (version 0.9.0)

sample_lcomp: Sample length compositions from expected values

Description

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

Usage

sample_lcomp(dat_list, outfile, fleets = c(1, 2), Nsamp, years, cpar = 1,
  ESS = NULL, write_file = 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_agecomp, sample_calcomp, sample_index, 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)

## Generate with constant sample size across years
ex1 <- sample_lcomp(dat_list=dat_list, outfile="test1.dat", fleets=c(1,2),
                    Nsamp=list(100,50), years=list(seq(26, 100, by=2),
                                            80:100), write_file = FALSE)

## Generate with varying Nsamp by year for first fleet
ex2 <- sample_lcomp(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, by=2),
                        80:100), write_file = FALSE)

## Plot distributions for a particular year to compare multinomial
## vs. overdispersed Dirichlet
temp.list <- temp.list2 <- list()
for(i in 1:40){
    temp.list[[i]] <-
      sample_lcomp(dat_list=dat_list, outfile="test1.dat", fleets=c(2), cpar=c(3),
                     Nsamp=list(100), years=list(1995),
                     write_file=FALSE)
    temp.list2[[i]] <-
        sample_lcomp(dat_list=dat_list, outfile="test1.dat", fleets=c(2),
                     cpar=c(NA), Nsamp=list(100), years=list(1995),
                     write_file=FALSE)
}
## Organize the data for plotting
x1 <- reshape2::melt(do.call(rbind, temp.list)[,-(1:6)[-3]], id.vars="FltSvy")
x2 <- reshape2::melt(do.call(rbind, temp.list2)[,-(1:6)[-3]], id.vars="FltSvy")
op <- par(mfrow=c(2,1))
with(x1, boxplot(value~variable, las=2, ylim=c(0,.6), ylab="Proportion",
                 main="Overdispersed (cpar=3)",  xlab="length bin"))
temp <- as.numeric(subset(dat_list$lencomp, Yr==1995 & FltSvy == 2)[-(1:6)])
points(temp/sum(temp), pch="-", col="red")
with(x2, boxplot(value~variable, las=2, ylim=c(0,.6), ylab="Proportion",
                 main="Multinomial", xlab="length bin"))
temp <- as.numeric(subset(dat_list$lencomp, Yr==1995 & FltSvy == 2)[-(1:6)])
points(temp/sum(temp), pch="-", col="red")
par(op)

Run the code above in your browser using DataLab