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)
yrs
are the years to be sampled default >= 2017samples
is the desired sample size by lengthstrata
is a switch to change the comps to year/strata instead of year change toTRUE
if desired
- get complete cases of lengths by species, year, and stratum =
lngs
a. there is astrata
switch to include or exclude - filter years from
lfreq
andcpue
data - calculate length comp
a. no sampling
1. comps are calculated by
year
,species
,stratum
,haul
,sex
, andlength
b. reduced sample sizes by sex 1. filterlfreq
for only males and females 2.uncount
the frequency 3. sample byyear
,species
,stratum
,haul
at the selected sample size, save as.new_sexed
4. filter out previously sexed fish that are now unsexed,.new_unsexed
5. Join the original unsexed fish fromlfreq
to the.new_sexed
a. 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 = TRUE
aggregate abundance by year abd strata, save the output asnew
and the individuals asremoved
in a list a. ifstrata = NULL
aggregate 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)
iters
is the number of iterationsstrata
is a switch to change the comps to year/strata instead of year change toTRUE
if desiredsamples
is the desired sample size by lengthyears
is the min year to sample aka>=
save
will save results in theoutput
folder, a single file is output if there are nosamples
, otherwise two files are output: acomps
file and aremoved
file (sexed individuals who are move dto the unsexed population)
- replicates the
pop_est
function the desired number of iterations
get_data(data = sim output, id, species = NULL, yrs = NULL)
id
is the name of the dataspecies
is a filteryrs
is 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