I'm archiving this repo - functions have been repackaged and moved to https://github.com/BenWilliams-NOAA/swo
The sims function is the primary driver, it calls the pop_est function and replicates it a user defined number of iterations, it then processes the results out of list form and can save the results as a .csv.
pop_est(lfreq = length freq file, cpue = cpue file, samples = NULL, yrs = 2017, strata = NULL)
yrsare the years to be sampled default >= 2017samplesis the desired sample size by lengthstratais a switch to change the comps to year/strata instead of year change toTRUEif desired
- get complete cases of lengths by species, year, and stratum =
lngsa. there is astrataswitch to include or exclude - filter years from
lfreqandcpuedata - calculate length comp
a. no sampling
1. comps are calculated by
year,species,stratum,haul,sex, andlengthb. reduced sample sizes by sex 1. filterlfreqfor only males and females 2.uncountthe frequency 3. sample byyear,species,stratum,haulat the selected sample size, save as.new_sexed4. filter out previously sexed fish that are now unsexed,.new_unsexed5. Join the original unsexed fish fromlfreqto the.new_sexeda. note: this means the overall sample size is reduced, could be computed in another fashion 6. comps are calculated byyear,species,stratum,haul,sex, andlength - calculate comp for hauls w/o length samples,
.unk - id hauls w/o lengths, name
.no_length - calculate the population estimate by stratum,
.pop - if there are any hauls w/o lengths joins them to the length comp and compute population size by haul,
.temp - if
strata = TRUEaggregate abundance by year abd strata, save the output asnewand the individuals asremovedin a list a. ifstrata = NULLaggregate abundance by year and output directly to global environment
sims(iters = 1, lfreq = length freq file, cpue = cpue file, strata = NULL, samples = NULL, yrs = 2017, save = NULL)
itersis the number of iterationsstratais a switch to change the comps to year/strata instead of year change toTRUEif desiredsamplesis the desired sample size by lengthyearsis the min year to sample aka>=savewill save results in theoutputfolder, a single file is output if there are nosamples, otherwise two files are output: acompsfile and aremovedfile (sexed individuals who are move dto the unsexed population)
- replicates the
pop_estfunction the desired number of iterations
get_data(data = sim output, id, species = NULL, yrs = NULL)
idis the name of the dataspeciesis a filteryrsis a filter
- helper function pulls the simulations, splits the results out calculates confidence intervals
plot_comp(base_data = og data, sim_data = reduced sample data, species = NULL, yrs = NULL)
- species is a filer
- yrs is a filter
- line plot with 95% ci comparing original population-based comps to reduced sample size comps
table_comp(base_data = og data, sim_data = reduced sample data, species = NULL, yrs = NULL)
- species is a filer
- yrs is a filter
- creates a table of output values, also output the difference and percent difference by year, or by year & stratum
plot_comp2(base_data, sim_data, species = NULL, yrs = NULL)
- species is a filer
- yrs is a filter
- density plot to plot the output of
table_comp