In general, you shouldn't have to use these functions directly. However, they are exposed to the user in case you need the flexibility of using them yourself and as a place to hold documentation about the weighting schemes. These functions weight age or length frequencies. tidy_comps_commercial() and tidy_comps_survey() join the necessary data for commercial or survey samples, respectively, and format it for weighting. weight_comps() does the actual weighting based on the output from the tidy_* functions.

tidy_comps_commercial(specimen_dat, catch_dat, value, bin_size = NULL)

tidy_comps_survey(specimen_dat, survey_tows, value, bin_size = NULL)

weight_comps(dat)

Arguments

specimen_dat

Specimen data. E.g. from get_commercial_samples() for commercial data or get_survey_samples() for survey data.

catch_dat

Catch data. E.g. from get_catch().

value

The unquoted column name with the values to re-weight (e.g. age or length).

bin_size

The binning size (likely only used for lengths).

survey_tows

Survey tow data. E.g. from get_survey_samples().

dat

A properly formatted data frame such the output from tidy_comps_survey() or tidy_comps_commercial(). See details.

Details

The input data frame to weight_comps() must have columns in the following order:

  1. year

  2. weighting unit ID (e.g. trip ID or sample ID)

  3. grouping variable for first weighting (e.g. quarter or stratum)

  4. value of weighting variable (e.g. age or length bin)

  5. frequency of that weighting variable (e.g. frequency of that age or length bin)

  6. numerator in first weighting (e.g. sample catch weight or density)

  7. denominator in first weighting (e.g. quarter catch weight or total stratum density)

  8. numerator in second weighting (e.g. catch that quarter or stratum area)

  9. denominator in second weighting (e.g. catch that year or total survey area)

tidy_comps_commercial() and tidy_comps_survey() both output data frames in this format and so you ordinarily would not have to worry about this. The names of the columns do not matter, only their contents. The data frame should contain these columns and only these columns.

References

Page 161 of Kendra R. Holt, Paul J. Starr, Rowan Haigh, and Brian Krishka. 2016. Stock Assessment and Harvest Advice for Rock Sole (Lepidopsetta spp.) in British Columbia. CSAS Res. Doc. 2016/009. Link PDF

Examples

# NOT RUN {
species <- "redstripe rockfish"

## Surveys:
## ssid = 1 is Queen Charlotte Sound Synoptic Survey:
# rs_survey_samples <- get_survey_samples(species, ssid = 1)
# rs_survey_sets <- get_survey_sets(species, ssid = 1)

surv_lengths <- tidy_comps_survey(rs_survey_samples, rs_survey_sets,
  value = length, bin_size = 2)
surv_lengths
weight_comps(surv_lengths)

surv_ages <- tidy_comps_survey(rs_survey_samples, rs_survey_sets, value = age)
surv_ages
weight_comps(surv_ages)

## Commercial:
# rs_comm_samples <- get_commercial_samples(species)
# rs_catch <- get_catch(species)

com_lengths <- tidy_comps_commercial(rs_comm_samples, rs_catch,
  value = length, bin_size = 2)
com_lengths
weight_comps(com_lengths)

com_ages <- tidy_comps_commercial(rs_comm_samples, rs_catch,
  value = age)
com_ages
weight_comps(com_ages)

## These functions are pipe (%>%) friendly. E.g.:
tidy_comps_survey(rs_survey_samples, rs_survey_sets, value = age) %>%
  weight_comps()
# }